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 #include <precomp.h> 25 #include <cosv/dirchain.hxx> 26 27 // NOT FULLY DECLARED SERVICES 28 #include <cosv/bstream.hxx> 29 30 31 32 33 namespace csv 34 { 35 namespace ploc 36 { 37 38 39 DirectoryChain::DirectoryChain() 40 { 41 } 42 43 DirectoryChain::DirectoryChain( const char * i_sSubPath, 44 bool i_bPathIsAlwaysDir, 45 const char * i_sDelimiter ) 46 { 47 Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter ); 48 } 49 50 DirectoryChain::~DirectoryChain() 51 { 52 } 53 54 void 55 DirectoryChain::Set( const char * i_sSubPath, 56 bool i_bPathIsAlwaysDir, 57 const char * i_sDelimiter ) 58 { 59 csv_assert(i_sDelimiter != 0); 60 if (i_sSubPath == 0) 61 return; 62 63 const char * pRestPath = i_sSubPath; 64 if (*pRestPath == *i_sDelimiter) 65 ++pRestPath; 66 67 for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter); 68 pDirEnd != 0; 69 pDirEnd = strchr(pRestPath,*i_sDelimiter) ) 70 { 71 aPath.push_back( String(pRestPath, pDirEnd) ); 72 pRestPath = pDirEnd + 1; 73 } 74 if (*pRestPath != 0 AND i_bPathIsAlwaysDir) 75 aPath.push_back( String(pRestPath) ); 76 } 77 78 void 79 DirectoryChain::PushFront( const String & i_sName ) 80 { 81 aPath.insert( aPath.begin(), i_sName ); 82 } 83 84 void 85 DirectoryChain::PushFront( const DirectoryChain & i_sPath ) 86 { 87 aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() ); 88 } 89 90 void 91 DirectoryChain::PushBack( const String & i_sName ) 92 { 93 aPath.push_back(i_sName); 94 } 95 96 void 97 DirectoryChain::PushBack( const DirectoryChain & i_sPath ) 98 { 99 aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() ); 100 } 101 102 void 103 DirectoryChain::PopFront( uintt i_nCount ) 104 { 105 if (i_nCount <= aPath.size()) 106 aPath.erase( aPath.begin(), aPath.begin() + i_nCount ); 107 else 108 aPath.erase( aPath.begin(), aPath.end() ); 109 } 110 111 void 112 DirectoryChain::PopBack( uintt i_nCount ) 113 { 114 if (i_nCount <= aPath.size()) 115 aPath.erase( aPath.end() - i_nCount, aPath.end() ); 116 else 117 aPath.erase( aPath.begin(), aPath.end() ); 118 } 119 120 void 121 DirectoryChain::Get( ostream & o_rPath, 122 const char * i_sDelimiter ) const 123 { 124 for ( std::vector<String>::const_iterator it = aPath.begin(); 125 it != aPath.end(); 126 ++it ) 127 { 128 o_rPath << (*it).c_str() << i_sDelimiter; 129 } 130 } 131 132 void 133 DirectoryChain::Get( bostream & o_rPath, 134 const char * i_sDelimiter ) const 135 { 136 uintt deliLen = strlen(i_sDelimiter); 137 138 for ( std::vector<String>::const_iterator it = aPath.begin(); 139 it != aPath.end(); 140 ++it ) 141 { 142 o_rPath.write( (*it).c_str() ); 143 o_rPath.write( i_sDelimiter, deliLen); 144 } 145 } 146 147 148 149 150 } // namespace ploc 151 } // namespace csv 152