1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dirchain.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <cosv/dirchain.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <cosv/bstream.hxx>
46 DirectoryChain::DirectoryChain()
50 DirectoryChain::DirectoryChain( const char * i_sSubPath
,
51 bool i_bPathIsAlwaysDir
,
52 const char * i_sDelimiter
)
54 Set( i_sSubPath
, i_bPathIsAlwaysDir
, i_sDelimiter
);
57 DirectoryChain::~DirectoryChain()
62 DirectoryChain::Set( const char * i_sSubPath
,
63 bool i_bPathIsAlwaysDir
,
64 const char * i_sDelimiter
)
66 csv_assert(i_sDelimiter
!= 0);
70 const char * pRestPath
= i_sSubPath
;
71 if (*pRestPath
== *i_sDelimiter
)
74 for ( const char * pDirEnd
= strchr(pRestPath
,*i_sDelimiter
);
76 pDirEnd
= strchr(pRestPath
,*i_sDelimiter
) )
78 aPath
.push_back( String(pRestPath
, pDirEnd
) );
79 pRestPath
= pDirEnd
+ 1;
81 if (*pRestPath
!= 0 AND i_bPathIsAlwaysDir
)
82 aPath
.push_back( String(pRestPath
) );
86 DirectoryChain::PushFront( const String
& i_sName
)
88 aPath
.insert( aPath
.begin(), i_sName
);
92 DirectoryChain::PushFront( const DirectoryChain
& i_sPath
)
94 aPath
.insert( aPath
.begin(), i_sPath
.Begin(), i_sPath
.End() );
98 DirectoryChain::PushBack( const String
& i_sName
)
100 aPath
.push_back(i_sName
);
104 DirectoryChain::PushBack( const DirectoryChain
& i_sPath
)
106 aPath
.insert( aPath
.end(), i_sPath
.Begin(), i_sPath
.End() );
110 DirectoryChain::PopFront( uintt i_nCount
)
112 if (i_nCount
<= aPath
.size())
113 aPath
.erase( aPath
.begin(), aPath
.begin() + i_nCount
);
115 aPath
.erase( aPath
.begin(), aPath
.end() );
119 DirectoryChain::PopBack( uintt i_nCount
)
121 if (i_nCount
<= aPath
.size())
122 aPath
.erase( aPath
.end() - i_nCount
, aPath
.end() );
124 aPath
.erase( aPath
.begin(), aPath
.end() );
128 DirectoryChain::Get( ostream
& o_rPath
,
129 const char * i_sDelimiter
) const
131 for ( std::vector
<String
>::const_iterator it
= aPath
.begin();
135 o_rPath
<< (*it
).c_str() << i_sDelimiter
;
140 DirectoryChain::Get( bostream
& o_rPath
,
141 const char * i_sDelimiter
) const
143 uintt deliLen
= strlen(i_sDelimiter
);
145 for ( std::vector
<String
>::const_iterator it
= aPath
.begin();
149 o_rPath
.write( (*it
).c_str() );
150 o_rPath
.write( i_sDelimiter
, deliLen
);