xref: /aoo42x/main/autodoc/inc/cosv/dirchain.hxx (revision 8a106958)
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_DIRCHAIN_HXX
25 #define CSV_DIRCHAIN_HXX
26 
27 
28 // USED SERVICES
29 	// BASE CLASSES
30 	// COMPONENTS
31 #include <cosv/string.hxx>
32 	// PARAMETERS
33 #include <cosv/csv_ostream.hxx>
34 
35 #include <cosv/persist.hxx>
36 #include <cosv/tpl/tpltools.hxx>
37 
38 
39 
40 namespace csv
41 {
42     class bostream;
43 
44 namespace ploc
45 {
46 
47 
48 class DirectoryChain
49 {
50   public:
51                         DirectoryChain();
52                         DirectoryChain(
53                             const char *        i_sPath,
54                             bool                i_bPathIsAlwaysDir = false,
55                             const char *        i_sDelimiter = Delimiter() );
56                         DirectoryChain(
57                             const DirectoryChain &
58                                                 i_rDC );
59                         ~DirectoryChain();
60 
61     // OPERATORS
62     DirectoryChain &    operator=(
63                             const DirectoryChain &
64                                                 i_rDC );
65     DirectoryChain &    operator+=(
66                             const String &      i_sName );
67     DirectoryChain &    operator+=(
68                             const DirectoryChain &
69                                                 i_rDC );
70     DirectoryChain &    operator-=(
71                             uintt               i_nLevelsUp );
72 
73     // OPERATIONS
74     void                Set(
75                             const char *        i_sPath,
76                             bool                i_bPathIsAlwaysDir = false,
77                             const char *        i_sDelimiter = Delimiter() );
78     void                PushFront(
79                             const String &      i_sName );
80     void                PushFront(
81                             const DirectoryChain &
82                                                 i_sPath );
83     void                PushBack(
84                             const String &      i_sName );
85     void                PushBack(
86                             const DirectoryChain &
87                                                 i_sPath );
88     void                PopFront(
89                             uintt               i_nCount = 1 );
90     void                PopBack(
91                             uintt               i_nCount = 1 );
92 
93     // INQUIRY
94     uintt               Size() const;
95 
96     StringVector::const_iterator
97                         Begin() const;
98     StringVector::const_iterator
99                         End() const;
100 
101     const String &      Front() const;
102     const String &      Back() const;
103 
104     void                Get(
105                             ostream &           o_rPath,
106                             const char *        i_sDelimiter ) const;
107     void                Get(
108                             bostream &          o_rPath,
109                             const char *        i_sDelimiter ) const;
110   private:
111     StringVector        aPath;
112 };
113 
114 
115 // IMPLEMENTATION
116 inline
DirectoryChain(const DirectoryChain & i_rDC)117 DirectoryChain::DirectoryChain( const DirectoryChain & i_rDC )
118     { PushBack(i_rDC); }
119 
120     // OPERATORS
121 inline DirectoryChain &
operator =(const DirectoryChain & i_rDC)122 DirectoryChain::operator=( const DirectoryChain & i_rDC )
123     { csv::erase_container(aPath); PushBack(i_rDC); return *this; }
124 inline DirectoryChain &
operator +=(const String & i_sName)125 DirectoryChain::operator+=( const String & i_sName )
126     { PushBack(i_sName); return *this;  }
127 inline DirectoryChain &
operator +=(const DirectoryChain & i_rDC)128 DirectoryChain::operator+=( const DirectoryChain & i_rDC )
129     { PushBack(i_rDC); return *this;  }
130 inline DirectoryChain &
operator -=(uintt i_nLevelsUp)131 DirectoryChain::operator-=( uintt i_nLevelsUp )
132     { PopBack(i_nLevelsUp); return *this;  }
133 inline uintt
Size() const134 DirectoryChain::Size() const
135     { return aPath.size(); }
136 
137 inline StringVector::const_iterator
Begin() const138 DirectoryChain::Begin() const
139     { return aPath.begin(); }
140 inline StringVector::const_iterator
End() const141 DirectoryChain::End() const
142     { return aPath.end(); }
143 inline const String &
Front() const144 DirectoryChain::Front() const
145     { return aPath.empty() ? String::Null_() : aPath.front(); }
146 inline const String &
Back() const147 DirectoryChain::Back() const
148     { return aPath.empty() ? String::Null_() : aPath.back(); }
149 
150 
151 }   // namespace ploc
152 }   // namespace csv
153 
154 
155 inline csv::ostream &
operator <<(csv::ostream & o_rOut,const csv::ploc::DirectoryChain & i_rSubPath)156 operator<<( csv::ostream &                     o_rOut,
157             const csv::ploc::DirectoryChain &  i_rSubPath )
158 {
159  	i_rSubPath.Get(o_rOut, csv::ploc::Delimiter());
160     return o_rOut;
161 }
162 
163 inline csv::bostream &
operator <<(csv::bostream & o_rOut,const csv::ploc::DirectoryChain & i_rSubPath)164 operator<<( csv::bostream &                     o_rOut,
165             const csv::ploc::DirectoryChain &   i_rSubPath )
166 {
167  	i_rSubPath.Get(o_rOut, csv::ploc::Delimiter());
168     return o_rOut;
169 }
170 
171 
172 
173 #endif
174 
175 
176 
177