libcommonc++  0.7
FileName.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_FileName_hxx
24 #define __ccxx_FileName_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/String.h++>
28 
29 namespace ccxx {
30 
56 {
57  public:
58 
60  FileName();
61 
63  FileName(const String& path);
64 
66  FileName(const String& dir, const String& filename);
67 
69  FileName(const FileName& other);
70 
72  FileName(const char* path);
73 
75  FileName& operator=(const FileName& other);
76 
78  FileName& operator=(const String& path);
79 
81  FileName& operator=(const char* path);
82 
84  ~FileName();
85 
90  inline String toString() const
91  { return(getPathName()); }
92 
94  String getPathName() const;
95 
97  void setPathName(const String& path);
98 
103  inline String getVolume() const
104  { return(_volume); }
105 
110  void setVolume(const String& volume);
111 
113  inline String getDirectory() const
114  { return(_dir); }
115 
117  void setDirectory(const String& dir);
118 
125  FileName& pushDirectory(const String& dir);
126 
131  FileName& popDirectory();
132 
134  inline String getBaseName() const
135  { return(_basename); }
136 
138  void setBaseName(const String& name);
139 
141  inline String getExtension() const
142  { return(_ext); }
143 
145  void setExtension(const String& ext);
146 
148  String getFileName() const;
149 
159  void setFileName(const String& name);
160 
166  bool isAbsolute() const;
167 
173  FileName& canonicalize();
174 
175  private:
176 
177  void _rebuildPathName() const;
178  void _rebuildFileName() const;
179 
180  String _volume;
181  String _dir;
182  String _basename;
183  String _ext;
184  mutable String _filename;
185  mutable String _pathname;
186  mutable bool _filenameDirty;
187  mutable bool _pathnameDirty;
188 };
189 
190 } // namespace ccxx
191 
192 #endif // __ccxx_FileName_hxx
String getDirectory() const
Get the directory for this FileName.
Definition: FileName.h++:113
String getExtension() const
Get the extension for the FileName.
Definition: FileName.h++:141
String getVolume() const
Get the volume for this FileName.
Definition: FileName.h++:103
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
A class representing a filename.
Definition: FileName.h++:55
String toString() const
Get a String representation of the FileName.
Definition: FileName.h++:90
String getBaseName() const
Get the base name from the FileName.
Definition: FileName.h++:134
Definition: AllocationMap.c++:25