xref: /aoo42x/main/autodoc/inc/cosv/ploc.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef CSV_PLOC_HXX
29 #define CSV_PLOC_HXX
30 
31 // USED SERVICES
32 #include <cosv/string.hxx>
33 #include <cosv/plocroot.hxx>
34 #include <cosv/dirchain.hxx>
35 #include <cosv/tpl/dyn.hxx>
36 #include <cosv/csv_ostream.hxx>
37 
38 
39 
40 
41 namespace csv
42 {
43     class bostream;
44 
45 namespace ploc
46 {
47     class Root;
48 
49 
50 /** Represents a path in the file system.
51 
52     The path can be relative or absolute and in Unix- or Windows-syntax.
53 */
54 class Path
55 {
56   public:
57 
58     // LIFECYCLE
59     explicit            Path(
60                             const char *        i_sPath = ".",                  /// Dirs have to be ended with a '\\ or '/'.
61                             bool                i_bPathIsAlwaysDir = false,     /// This overrides a missing Delimiter at the end of the i_sPath, if true.
62                             const char *        i_sDelimiter = Delimiter() );
63                         Path(
64                             const Path &        i_rPath );
65                         ~Path();
66     // OPERATORS
67     Path &              operator=(
68                             const Path &        i_rPath );
69     // OPERATIONS
70     void                Set(
71                             const char *        i_sPath,
72                             bool                i_bPathIsAlwaysDir = false,
73                             const char *        i_sDelimiter = Delimiter() );
74     void                SetFile(                // If there is already a file, that is exchanged.
75                             const String &      i_sName );
76     // INQUIRY
77     const Root &        RootDir() const         { return *pRoot; }
78     const DirectoryChain &
79                         DirChain() const        { return aPath; }
80     const String  &     File() const            { return sFile; }
81     const char *        FileExtension() const;
82     bool                IsValid() const;
83     bool                IsDirectory() const     { return sFile.length() == 0; }
84     bool                IsFile() const          { return sFile.length() > 0; }
85 
86     /// Directories have a delimiter at the end, files not.
87     void                Get(
88                             ostream &           o_rPath ) const;
89     /// Directories have a delimiter at the end, files not.
90     void                Get(
91                             bostream &          o_rPath ) const;
92     // ACCESS
93     DirectoryChain &    DirChain()              { return aPath; }
94 
95   private:
96     Dyn<Root>           pRoot;
97     DirectoryChain      aPath;
98     String              sFile;
99 };
100 
101 
102 
103 
104 }   // namespace ploc
105 }   // namespace csv
106 
107 
108 
109 /// Directories produce a delimiter at the end, files not.
110 inline csv::ostream &
111 operator<<( csv::ostream &           o_rOut,
112             const csv::ploc::Path &  i_rPath )
113 {
114  	i_rPath.Get(o_rOut);
115     return o_rOut;
116 }
117 
118 /// Directories produce a delimiter at the end, files not.
119 inline csv::bostream &
120 operator<<( csv::bostream &         o_rOut,
121             const csv::ploc::Path & i_rPath )
122 {
123  	i_rPath.Get(o_rOut);
124     return o_rOut;
125 }
126 
127 
128 
129 #endif
130