]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sg_path.hxx
Updates to build system to better support automake-1.5
[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
83     /**
84      * Append another piece to the existing path.  Inserts a path
85      * separator between the existing component and the new component.
86      * @param p additional path component */
87     void append( const string p );
88
89     /**
90      * Concatenate a string to the end of the path without inserting a
91      * path separator.
92      * @param p addtional path suffix
93      */
94     void concat( const string p );
95
96     /**
97      * Get the directory part of the path.
98      * @return directory string
99      */
100     string dir();
101   
102     /** Get the path string
103      * @return path string
104      */
105     inline string str() const { return path; }
106
107     /** Get the path string
108      * @return path in "C" string (ptr to char array) form.
109      */
110     inline const char *c_str() { return path.c_str(); }
111 };
112
113
114 #endif // _SG_PATH_HXX
115
116