xref: /aoo42x/main/autodoc/source/cosv/storage/ploc.cxx (revision 8a106958)
159617ebcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
359617ebcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
459617ebcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
559617ebcSAndrew Rist  * distributed with this work for additional information
659617ebcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
759617ebcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
859617ebcSAndrew Rist  * "License"); you may not use this file except in compliance
959617ebcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1059617ebcSAndrew Rist  *
1159617ebcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1259617ebcSAndrew Rist  *
1359617ebcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1459617ebcSAndrew Rist  * software distributed under the License is distributed on an
1559617ebcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1659617ebcSAndrew Rist  * KIND, either express or implied.  See the License for the
1759617ebcSAndrew Rist  * specific language governing permissions and limitations
1859617ebcSAndrew Rist  * under the License.
1959617ebcSAndrew Rist  *
2059617ebcSAndrew Rist  *************************************************************/
2159617ebcSAndrew Rist 
2259617ebcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <precomp.h>
25cdf0e10cSrcweir #include <cosv/ploc.hxx>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES
28cdf0e10cSrcweir #include <cosv/bstream.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace csv
34cdf0e10cSrcweir {
35cdf0e10cSrcweir namespace ploc
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
Path(const char * i_sPath,bool i_bPathIsAlwaysDir,const char * i_sDelimiter)39cdf0e10cSrcweir Path::Path( const char *        i_sPath,
40cdf0e10cSrcweir             bool                i_bPathIsAlwaysDir,
41cdf0e10cSrcweir             const char *        i_sDelimiter        )
42cdf0e10cSrcweir     :   pRoot(0)
43cdf0e10cSrcweir         // aPath,
44cdf0e10cSrcweir         // sFile
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     Set(i_sPath, i_bPathIsAlwaysDir, i_sDelimiter );
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
Path(const Path & i_rPath)49cdf0e10cSrcweir Path::Path( const Path & i_rPath )
50cdf0e10cSrcweir     :   pRoot(i_rPath.pRoot->CreateCopy()),
51cdf0e10cSrcweir         aPath(i_rPath.aPath),
52cdf0e10cSrcweir         sFile(i_rPath.sFile)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
~Path()56cdf0e10cSrcweir Path::~Path()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir Path &
operator =(const Path & i_rPath)61cdf0e10cSrcweir Path::operator=( const Path & i_rPath )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     pRoot = i_rPath.pRoot->CreateCopy();
64cdf0e10cSrcweir     aPath = i_rPath.aPath;
65cdf0e10cSrcweir     sFile = i_rPath.sFile;
66cdf0e10cSrcweir     return *this;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir void
Set(const char * i_sPath,bool i_bPathIsAlwaysDir,const char * i_sDelimiter)71cdf0e10cSrcweir Path::Set( const char *        i_sPath,
72cdf0e10cSrcweir            bool                i_bPathIsAlwaysDir,
73cdf0e10cSrcweir            const char *        i_sDelimiter        )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     if ( *i_sDelimiter != '\\' AND *i_sDelimiter != '/' )
76cdf0e10cSrcweir         return;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     const char *
79cdf0e10cSrcweir         restPath = 0;
80cdf0e10cSrcweir     pRoot = Root::Create_( restPath, i_sPath, i_sDelimiter );
81cdf0e10cSrcweir     if (restPath == 0)
82cdf0e10cSrcweir         return;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     aPath.Set(restPath, i_bPathIsAlwaysDir, i_sDelimiter);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     if (NOT i_bPathIsAlwaysDir)
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir 		const char *
89cdf0e10cSrcweir 		    file = strrchr( restPath, *i_sDelimiter );
90cdf0e10cSrcweir         if (file == 0)
91cdf0e10cSrcweir 			file = restPath;
92cdf0e10cSrcweir 		else
93cdf0e10cSrcweir 			file++;
94cdf0e10cSrcweir         sFile = file;
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir void
SetFile(const String & i_sName)99cdf0e10cSrcweir Path::SetFile( const String & i_sName )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     sFile = i_sName;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir const char *
FileExtension() const105cdf0e10cSrcweir Path::FileExtension() const
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     const char *
108cdf0e10cSrcweir         ext = strrchr(sFile, '.');
109cdf0e10cSrcweir     if (ext != 0)
110cdf0e10cSrcweir         ++ext;
111cdf0e10cSrcweir     else
112cdf0e10cSrcweir         ext = "";
113cdf0e10cSrcweir     return ext;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir bool
IsValid() const117cdf0e10cSrcweir Path::IsValid() const
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     return RootDir().OwnDelimiter() != 0;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir void
Get(ostream & o_rPath) const123cdf0e10cSrcweir Path::Get( ostream & o_rPath ) const
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     if (NOT IsValid())
126cdf0e10cSrcweir         return;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     pRoot->Get( o_rPath );
129cdf0e10cSrcweir     aPath.Get( o_rPath, pRoot->OwnDelimiter() );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     if ( sFile.length() > 0 )
132cdf0e10cSrcweir         o_rPath << sFile;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir void
Get(bostream & o_rPath) const137cdf0e10cSrcweir Path::Get( bostream & o_rPath ) const
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     if (NOT IsValid())
140cdf0e10cSrcweir         return;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     pRoot->Get( o_rPath );
143cdf0e10cSrcweir     aPath.Get( o_rPath, pRoot->OwnDelimiter() );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     if ( sFile.length() > 0 )
146cdf0e10cSrcweir         o_rPath.write( sFile );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir } // namespace ploc
153cdf0e10cSrcweir } // namespace csv
154