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