xref: /trunk/main/autodoc/inc/cosv/ploc.hxx (revision 11c03c6d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef CSV_PLOC_HXX
25 #define CSV_PLOC_HXX
26 
27 // USED SERVICES
28 #include <cosv/string.hxx>
29 #include <cosv/plocroot.hxx>
30 #include <cosv/dirchain.hxx>
31 #include <cosv/tpl/dyn.hxx>
32 #include <cosv/csv_ostream.hxx>
33 
34 
35 
36 
37 namespace csv
38 {
39     class bostream;
40 
41 namespace ploc
42 {
43     class Root;
44 
45 
46 /** Represents a path in the file system.
47 
48     The path can be relative or absolute and in Unix- or Windows-syntax.
49 */
50 class Path
51 {
52   public:
53 
54     // LIFECYCLE
55     explicit            Path(
56                             const char *        i_sPath = ".",                  /// Dirs have to be ended with a '\\ or '/'.
57                             bool                i_bPathIsAlwaysDir = false,     /// This overrides a missing Delimiter at the end of the i_sPath, if true.
58                             const char *        i_sDelimiter = Delimiter() );
59                         Path(
60                             const Path &        i_rPath );
61                         ~Path();
62     // OPERATORS
63     Path &              operator=(
64                             const Path &        i_rPath );
65     // OPERATIONS
66     void                Set(
67                             const char *        i_sPath,
68                             bool                i_bPathIsAlwaysDir = false,
69                             const char *        i_sDelimiter = Delimiter() );
70     void                SetFile(                // If there is already a file, that is exchanged.
71                             const String &      i_sName );
72     // INQUIRY
RootDir() const73     const Root &        RootDir() const         { return *pRoot; }
74     const DirectoryChain &
DirChain() const75                         DirChain() const        { return aPath; }
File() const76     const String  &     File() const            { return sFile; }
77     const char *        FileExtension() const;
78     bool                IsValid() const;
IsDirectory() const79     bool                IsDirectory() const     { return sFile.length() == 0; }
IsFile() const80     bool                IsFile() const          { return sFile.length() > 0; }
81 
82     /// Directories have a delimiter at the end, files not.
83     void                Get(
84                             ostream &           o_rPath ) const;
85     /// Directories have a delimiter at the end, files not.
86     void                Get(
87                             bostream &          o_rPath ) const;
88     // ACCESS
DirChain()89     DirectoryChain &    DirChain()              { return aPath; }
90 
91   private:
92     Dyn<Root>           pRoot;
93     DirectoryChain      aPath;
94     String              sFile;
95 };
96 
97 
98 
99 
100 }   // namespace ploc
101 }   // namespace csv
102 
103 
104 
105 /// Directories produce a delimiter at the end, files not.
106 inline csv::ostream &
operator <<(csv::ostream & o_rOut,const csv::ploc::Path & i_rPath)107 operator<<( csv::ostream &           o_rOut,
108             const csv::ploc::Path &  i_rPath )
109 {
110  	i_rPath.Get(o_rOut);
111     return o_rOut;
112 }
113 
114 /// Directories produce a delimiter at the end, files not.
115 inline csv::bostream &
operator <<(csv::bostream & o_rOut,const csv::ploc::Path & i_rPath)116 operator<<( csv::bostream &         o_rOut,
117             const csv::ploc::Path & i_rPath )
118 {
119  	i_rPath.Get(o_rOut);
120     return o_rOut;
121 }
122 
123 
124 
125 #endif
126