1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <precomp.h> 29*cdf0e10cSrcweir #include <cosv/dirchain.hxx> 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES 32*cdf0e10cSrcweir #include <cosv/bstream.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir namespace csv 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir namespace ploc 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir DirectoryChain::DirectoryChain() 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir DirectoryChain::DirectoryChain( const char * i_sSubPath, 48*cdf0e10cSrcweir bool i_bPathIsAlwaysDir, 49*cdf0e10cSrcweir const char * i_sDelimiter ) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter ); 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir DirectoryChain::~DirectoryChain() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir void 59*cdf0e10cSrcweir DirectoryChain::Set( const char * i_sSubPath, 60*cdf0e10cSrcweir bool i_bPathIsAlwaysDir, 61*cdf0e10cSrcweir const char * i_sDelimiter ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir csv_assert(i_sDelimiter != 0); 64*cdf0e10cSrcweir if (i_sSubPath == 0) 65*cdf0e10cSrcweir return; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir const char * pRestPath = i_sSubPath; 68*cdf0e10cSrcweir if (*pRestPath == *i_sDelimiter) 69*cdf0e10cSrcweir ++pRestPath; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter); 72*cdf0e10cSrcweir pDirEnd != 0; 73*cdf0e10cSrcweir pDirEnd = strchr(pRestPath,*i_sDelimiter) ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir aPath.push_back( String(pRestPath, pDirEnd) ); 76*cdf0e10cSrcweir pRestPath = pDirEnd + 1; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir if (*pRestPath != 0 AND i_bPathIsAlwaysDir) 79*cdf0e10cSrcweir aPath.push_back( String(pRestPath) ); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir void 83*cdf0e10cSrcweir DirectoryChain::PushFront( const String & i_sName ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir aPath.insert( aPath.begin(), i_sName ); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void 89*cdf0e10cSrcweir DirectoryChain::PushFront( const DirectoryChain & i_sPath ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir void 95*cdf0e10cSrcweir DirectoryChain::PushBack( const String & i_sName ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir aPath.push_back(i_sName); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void 101*cdf0e10cSrcweir DirectoryChain::PushBack( const DirectoryChain & i_sPath ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir void 107*cdf0e10cSrcweir DirectoryChain::PopFront( uintt i_nCount ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir if (i_nCount <= aPath.size()) 110*cdf0e10cSrcweir aPath.erase( aPath.begin(), aPath.begin() + i_nCount ); 111*cdf0e10cSrcweir else 112*cdf0e10cSrcweir aPath.erase( aPath.begin(), aPath.end() ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void 116*cdf0e10cSrcweir DirectoryChain::PopBack( uintt i_nCount ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if (i_nCount <= aPath.size()) 119*cdf0e10cSrcweir aPath.erase( aPath.end() - i_nCount, aPath.end() ); 120*cdf0e10cSrcweir else 121*cdf0e10cSrcweir aPath.erase( aPath.begin(), aPath.end() ); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir void 125*cdf0e10cSrcweir DirectoryChain::Get( ostream & o_rPath, 126*cdf0e10cSrcweir const char * i_sDelimiter ) const 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir for ( std::vector<String>::const_iterator it = aPath.begin(); 129*cdf0e10cSrcweir it != aPath.end(); 130*cdf0e10cSrcweir ++it ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir o_rPath << (*it).c_str() << i_sDelimiter; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir void 137*cdf0e10cSrcweir DirectoryChain::Get( bostream & o_rPath, 138*cdf0e10cSrcweir const char * i_sDelimiter ) const 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir uintt deliLen = strlen(i_sDelimiter); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir for ( std::vector<String>::const_iterator it = aPath.begin(); 143*cdf0e10cSrcweir it != aPath.end(); 144*cdf0e10cSrcweir ++it ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir o_rPath.write( (*it).c_str() ); 147*cdf0e10cSrcweir o_rPath.write( i_sDelimiter, deliLen); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir } // namespace ploc 155*cdf0e10cSrcweir } // namespace csv 156