]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sg_path.hxx
Added a ptr() method to SGPropertyNode_ptr to get the raw pointer.
[simgear.git] / simgear / misc / sg_path.hxx
1 /**
2  * \file sg_path.hxx
3  * Routines to abstract out path separator differences between MacOS
4  * and the rest of the world.
5  */
6
7 // Written by Curtis L. Olson, started April 1999.
8 //
9 // Copyright (C) 1999  Curtis L. Olson - curt@flightgear.org
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Library General Public
13 // License as published by the Free Software Foundation; either
14 // version 2 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 // Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public
22 // License along with this library; if not, write to the
23 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 // Boston, MA  02111-1307, USA.
25 //
26 // $Id$
27
28
29 #ifndef _SG_PATH_HXX
30 #define _SG_PATH_HXX
31
32
33 #include <simgear/compiler.h>
34
35 #include STL_STRING
36
37 SG_USING_STD(string);
38
39
40 #ifdef macintosh
41 #  define SG_PATH_SEP ':'
42 #  define SG_BAD_PATH_SEP '/'
43 #else
44 #  define SG_PATH_SEP '/'
45 #  define SG_BAD_PATH_SEP ':'
46 #endif
47
48
49 /**
50  * A class to hide path separator difference across platforms and assist
51  * in managing file system path names.
52  *
53  * Paths can be input in any platform format and will be converted
54  * automatically to the proper format.
55  */
56
57 class SGPath {
58
59 private:
60
61     string path;
62
63 public:
64
65     /** Default constructor */
66     SGPath();
67
68     /**
69      * Construct a path based on the starting path provided.
70      * @param p initial path
71      */
72     SGPath( const string& p );
73
74     /** Destructor */
75     ~SGPath();
76
77     /**
78      * Set path to a new value
79      * @param p new path
80      */
81     void set( const string& p );
82     SGPath& operator= ( const char* p ) { this->set(p); return *this; }
83
84     /**
85      * Append another piece to the existing path.  Inserts a path
86      * separator between the existing component and the new component.
87      * @param p additional path component */
88     void append( const string& p );
89
90     /**
91      * Concatenate a string to the end of the path without inserting a
92      * path separator.
93      * @param p addtional path suffix
94      */
95     void concat( const string& p );
96
97     /**
98      * Get the directory part of the path.
99      * @return directory string
100      */
101     string dir();
102   
103     /** Get the path string
104      * @return path string
105      */
106     string str() const { return path; }
107
108     /** Get the path string
109      * @return path in "C" string (ptr to char array) form.
110      */
111     const char* c_str() { return path.c_str(); }
112
113     /**
114      * Determine if file exists by attempting to fopen it.
115      * @return true if file exists, otherwise returns false.
116      */
117     bool exists() const;
118
119 private:
120
121     void fix();
122
123 };
124
125
126 #endif // _SG_PATH_HXX
127
128