1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include <cosv/dirchain.hxx>
31 // NOT FULLY DECLARED SERVICES
32 #include <cosv/bstream.hxx>
43 DirectoryChain::DirectoryChain()
47 DirectoryChain::DirectoryChain( const char * i_sSubPath
,
48 bool i_bPathIsAlwaysDir
,
49 const char * i_sDelimiter
)
51 Set( i_sSubPath
, i_bPathIsAlwaysDir
, i_sDelimiter
);
54 DirectoryChain::~DirectoryChain()
59 DirectoryChain::Set( const char * i_sSubPath
,
60 bool i_bPathIsAlwaysDir
,
61 const char * i_sDelimiter
)
63 csv_assert(i_sDelimiter
!= 0);
67 const char * pRestPath
= i_sSubPath
;
68 if (*pRestPath
== *i_sDelimiter
)
71 for ( const char * pDirEnd
= strchr(pRestPath
,*i_sDelimiter
);
73 pDirEnd
= strchr(pRestPath
,*i_sDelimiter
) )
75 aPath
.push_back( String(pRestPath
, pDirEnd
) );
76 pRestPath
= pDirEnd
+ 1;
78 if (*pRestPath
!= 0 AND i_bPathIsAlwaysDir
)
79 aPath
.push_back( String(pRestPath
) );
83 DirectoryChain::PushFront( const String
& i_sName
)
85 aPath
.insert( aPath
.begin(), i_sName
);
89 DirectoryChain::PushFront( const DirectoryChain
& i_sPath
)
91 aPath
.insert( aPath
.begin(), i_sPath
.Begin(), i_sPath
.End() );
95 DirectoryChain::PushBack( const String
& i_sName
)
97 aPath
.push_back(i_sName
);
101 DirectoryChain::PushBack( const DirectoryChain
& i_sPath
)
103 aPath
.insert( aPath
.end(), i_sPath
.Begin(), i_sPath
.End() );
107 DirectoryChain::PopFront( uintt i_nCount
)
109 if (i_nCount
<= aPath
.size())
110 aPath
.erase( aPath
.begin(), aPath
.begin() + i_nCount
);
112 aPath
.erase( aPath
.begin(), aPath
.end() );
116 DirectoryChain::PopBack( uintt i_nCount
)
118 if (i_nCount
<= aPath
.size())
119 aPath
.erase( aPath
.end() - i_nCount
, aPath
.end() );
121 aPath
.erase( aPath
.begin(), aPath
.end() );
125 DirectoryChain::Get( ostream
& o_rPath
,
126 const char * i_sDelimiter
) const
128 for ( std::vector
<String
>::const_iterator it
= aPath
.begin();
132 o_rPath
<< (*it
).c_str() << i_sDelimiter
;
137 DirectoryChain::Get( bostream
& o_rPath
,
138 const char * i_sDelimiter
) const
140 uintt deliLen
= strlen(i_sDelimiter
);
142 for ( std::vector
<String
>::const_iterator it
= aPath
.begin();
146 o_rPath
.write( (*it
).c_str() );
147 o_rPath
.write( i_sDelimiter
, deliLen
);