Path.h
1/*
2 * Copyright (C) 2006-2014 Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_System_Path_h
30#define Pt_System_Path_h
31
32#include <Pt/System/Api.h>
33#include <Pt/String.h>
34#include <Pt/Types.h>
35#include <string>
36
37namespace Pt {
38
39namespace System {
40
41class PathImpl;
42
47class PT_SYSTEM_API Path
48{
49 public:
53
56 Path(const Path& p);
57
60 Path(const Pt::String& s);
61
64 Path(const char* s);
65
68 Path(const char* s, std::size_t n);
69
73
74 // Assignments
75
78 Path& assign(const Path& p);
79
83
86 Path& assign(const char* s);
87
90 Path& assign(const char* s, std::size_t n);
91
94 Path& operator=(const Path& p)
95 { return assign(p); }
96
100 { return assign(s); }
101
104 Path& operator=(const char* s)
105 { return assign(s); }
106
107 // Appends
108
113 Path& append(const Path& p);
114
120
125 Path& append(const char* s);
126
131 Path& append(const char* s, std::size_t n);
132
138 { return append(p); }
139
145 { return append(s); }
146
151 Path& operator/=(const char* s)
152 { return append(s); }
153
154 // Concatenation
155
160 Path& concat(const Path& p);
161
167
172 Path& concat(const char* s);
173
178 Path& concat(const char* s, std::size_t n);
179
183 { return concat(p); }
184
190 { return concat(s); }
191
196 Path& operator+=(const char* s)
197 { return concat(s); }
198
199 // Modifiers
200
203 void clear();
204
205 // Query
206
209 bool empty() const;
210
211 // TODO: return Path objects
212
216
220
224
228
229 // Comparison
230
233 int compare(const Path& p) const;
234
235 // Conversion
236
240
243 std::string toLocal() const;
244
251
252 // Others
253
257
261
265
266 // Implementation
267
268 const PathImpl* impl() const
269 { return _impl; }
270
271 PathImpl* impl()
272 { return _impl; }
273
274 private:
275 PathImpl* _impl;
276 std::string _pathData;
277};
278
283inline Path operator/(const Path& a, const Path& b)
284{
285 return Path(a) /= b;
286}
287
292inline Path operator/(const Path& a, const Pt::String& b)
293{
294 return Path(a) /= b;
295}
296
301inline Path operator/(const Path& a, const char* b)
302{
303 return Path(a) /= b;
304}
305
310inline bool operator==(const Path& a, const Path& b)
311{
312 return a.compare(b) == 0;
313}
314
319inline bool operator!=(const Path& a, const Path& b)
320{
321 return a.compare(b) != 0;
322}
323
328inline bool operator<(const Path& a, const Path& b)
329{
330 return a.compare(b) < 0;
331}
332
333} // namespace System
334
335} // namespace Pt
336
337#endif // Pt_System_Path_h
Unicode capable basic_string.
Definition Api-String.h:67
Path & assign(const Path &p)
Assigns a path name.
Path & append(const char *s, std::size_t n)
Appends an UTF-8 encoded path name.
Path & concat(const char *s, std::size_t n)
Appends an UTF-8 encoded path name.
Path operator/(const Path &a, const Pt::String &b)
Appends a paths to another.
Definition Path.h:292
Path & operator+=(const Path &p)
Concatenates a path name.
Definition Path.h:182
Path & operator+=(const Pt::String &s)
Concatenates a path name.
Definition Path.h:189
Path & operator=(const char *s)
Assigns an UTF-8 encoded path name.
Definition Path.h:104
bool operator==(const Path &a, const Path &b)
Compares two paths.
Definition Path.h:310
Path & operator=(const Path &p)
Assignment operator.
Definition Path.h:94
std::string toLocal() const
Returns the path name in local encoding.
Pt::String toGeneric() const
Returns the path name with generic separators.
static Pt::String dirsep()
Returns the directory separator string.
Path & assign(const char *s, std::size_t n)
Assigns an UTF-8 encoded path name.
Pt::String extension() const
Returns the file name extension.
Path & operator/=(const Path &p)
Appends a path name.
Definition Path.h:137
Path & operator=(const Pt::String &s)
Assigns a path name.
Definition Path.h:99
bool empty() const
Returns true if path is empty.
Path & assign(const char *s)
Assigns an UTF-8 encoded path name.
Path & append(const char *s)
Appends an UTF-8 encoded path name.
Path & operator/=(const Pt::String &s)
Appends a path name.
Definition Path.h:144
Path operator/(const Path &a, const Path &b)
Appends a paths to another.
Definition Path.h:283
Path & concat(const Path &p)
Concatenates a path name.
static Pt::String curdir()
Returns the current directory string.
Pt::String baseName() const
Returns the file name without directory and extension.
Path & append(const Path &p)
Appends a path name.
bool operator!=(const Path &a, const Path &b)
Compares two paths.
Definition Path.h:319
Path()
Default constructor.
Path(const Path &p)
Copy constructor.
Path & append(const Pt::String &s)
Appends a path name.
int compare(const Path &p) const
Compares two paths (with strcmp semantics).
Path(const char *s, std::size_t n)
Construct from an UTF-8 encoded path name.
void clear()
Clears the path.
Pt::String dirName() const
Returns the directory part.
~Path()
Destructor.
Path(const char *s)
Construct from an UTF-8 encoded path name.
Path & operator/=(const char *s)
Appends an UTF-8 encoded path name.
Definition Path.h:151
static Pt::String updir()
Returns the parent directory string.
Path(const Pt::String &s)
Construct from a path name.
Pt::String toString() const
Returns the path name.
Path & assign(const Pt::String &s)
Assigns a path name.
Pt::String fileName() const
Returns the file name without the directroy part.
Path operator/(const Path &a, const char *b)
Appends a paths to another.
Definition Path.h:301
Path & concat(const Pt::String &s)
Concatenates a path name.
Path & operator+=(const char *s)
Concatenates a path name.
Definition Path.h:196
Path & concat(const char *s)
Concatenates a path name.
bool operator<(const Path &a, const Path &b)
Compares two paths.
Definition Path.h:328
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33