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