159617ebcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
359617ebcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
459617ebcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
559617ebcSAndrew Rist  * distributed with this work for additional information
659617ebcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
759617ebcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
859617ebcSAndrew Rist  * "License"); you may not use this file except in compliance
959617ebcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1059617ebcSAndrew Rist  *
1159617ebcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1259617ebcSAndrew Rist  *
1359617ebcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1459617ebcSAndrew Rist  * software distributed under the License is distributed on an
1559617ebcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1659617ebcSAndrew Rist  * KIND, either express or implied.  See the License for the
1759617ebcSAndrew Rist  * specific language governing permissions and limitations
1859617ebcSAndrew Rist  * under the License.
1959617ebcSAndrew Rist  *
2059617ebcSAndrew Rist  *************************************************************/
2159617ebcSAndrew Rist 
2259617ebcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <precomp.h>
25cdf0e10cSrcweir #include <cosv/dirchain.hxx>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
28cdf0e10cSrcweir #include <cosv/bstream.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace csv
34cdf0e10cSrcweir {
35cdf0e10cSrcweir namespace ploc
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
DirectoryChain()39cdf0e10cSrcweir DirectoryChain::DirectoryChain()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
DirectoryChain(const char * i_sSubPath,bool i_bPathIsAlwaysDir,const char * i_sDelimiter)43cdf0e10cSrcweir DirectoryChain::DirectoryChain( const char *        i_sSubPath,
44cdf0e10cSrcweir                                 bool                i_bPathIsAlwaysDir,
45cdf0e10cSrcweir                                 const char *        i_sDelimiter        )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter );
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
~DirectoryChain()50cdf0e10cSrcweir DirectoryChain::~DirectoryChain()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir void
Set(const char * i_sSubPath,bool i_bPathIsAlwaysDir,const char * i_sDelimiter)55cdf0e10cSrcweir DirectoryChain::Set( const char *        i_sSubPath,
56cdf0e10cSrcweir                      bool                i_bPathIsAlwaysDir,
57cdf0e10cSrcweir                      const char *        i_sDelimiter        )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     csv_assert(i_sDelimiter != 0);
60cdf0e10cSrcweir     if (i_sSubPath == 0)
61cdf0e10cSrcweir         return;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     const char * pRestPath = i_sSubPath;
64cdf0e10cSrcweir     if (*pRestPath == *i_sDelimiter)
65cdf0e10cSrcweir         ++pRestPath;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter);
68cdf0e10cSrcweir           pDirEnd != 0;
69cdf0e10cSrcweir           pDirEnd = strchr(pRestPath,*i_sDelimiter) )
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         aPath.push_back( String(pRestPath, pDirEnd) );
72cdf0e10cSrcweir         pRestPath = pDirEnd + 1;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir     if (*pRestPath != 0 AND i_bPathIsAlwaysDir)
75cdf0e10cSrcweir         aPath.push_back( String(pRestPath) );
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir void
PushFront(const String & i_sName)79cdf0e10cSrcweir DirectoryChain::PushFront( const String & i_sName )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     aPath.insert( aPath.begin(), i_sName );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir void
PushFront(const DirectoryChain & i_sPath)85cdf0e10cSrcweir DirectoryChain::PushFront( const DirectoryChain & i_sPath )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir void
PushBack(const String & i_sName)91cdf0e10cSrcweir DirectoryChain::PushBack( const String & i_sName )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     aPath.push_back(i_sName);
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir void
PushBack(const DirectoryChain & i_sPath)97cdf0e10cSrcweir DirectoryChain::PushBack( const DirectoryChain & i_sPath )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir void
PopFront(uintt i_nCount)103cdf0e10cSrcweir DirectoryChain::PopFront( uintt i_nCount )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     if (i_nCount <= aPath.size())
106cdf0e10cSrcweir         aPath.erase( aPath.begin(), aPath.begin() + i_nCount );
107cdf0e10cSrcweir     else
108cdf0e10cSrcweir         aPath.erase( aPath.begin(), aPath.end() );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir void
PopBack(uintt i_nCount)112cdf0e10cSrcweir DirectoryChain::PopBack( uintt i_nCount )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     if (i_nCount <= aPath.size())
115cdf0e10cSrcweir         aPath.erase( aPath.end() - i_nCount, aPath.end() );
116cdf0e10cSrcweir     else
117cdf0e10cSrcweir         aPath.erase( aPath.begin(), aPath.end() );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir void
Get(ostream & o_rPath,const char * i_sDelimiter) const121cdf0e10cSrcweir DirectoryChain::Get( ostream &      o_rPath,
122cdf0e10cSrcweir                      const char *   i_sDelimiter ) const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     for ( std::vector<String>::const_iterator it = aPath.begin();
125cdf0e10cSrcweir           it != aPath.end();
126cdf0e10cSrcweir           ++it )
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         o_rPath << (*it).c_str() << i_sDelimiter;
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir void
Get(bostream & o_rPath,const char * i_sDelimiter) const133cdf0e10cSrcweir DirectoryChain::Get( bostream &      o_rPath,
134cdf0e10cSrcweir                      const char *    i_sDelimiter ) const
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     uintt deliLen = strlen(i_sDelimiter);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     for ( std::vector<String>::const_iterator it = aPath.begin();
139cdf0e10cSrcweir           it != aPath.end();
140cdf0e10cSrcweir           ++it )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         o_rPath.write( (*it).c_str() );
143cdf0e10cSrcweir         o_rPath.write( i_sDelimiter,  deliLen);
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir } // namespace ploc
151cdf0e10cSrcweir } // namespace csv
152