]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sg_path.hxx
renamed to sgstream.[ch]xx
[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 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #include <simgear/compiler.h>
38
39 #include STL_STRING
40
41 SG_USING_STD(string);
42
43
44 #ifdef macintosh
45 #  define SG_PATH_SEP ':'
46 #  define SG_BAD_PATH_SEP '/'
47 #else
48 #  define SG_PATH_SEP '/'
49 #  define SG_BAD_PATH_SEP ':'
50 #endif
51
52
53 /**
54  * A class to hide path separator difference across platforms and assist
55  * in managing file system path names.
56  *
57  * Paths can be input in any platform format and will be converted
58  * automatically to the proper format.
59  */
60
61 class SGPath {
62
63 private:
64
65     string path;
66
67 public:
68
69     /** Default constructor */
70     SGPath();
71
72     /**
73      * Construct a path based on the starting path provided.
74      * @param p initial path
75      */
76     SGPath( const string p );
77
78     /** Destructor */
79     ~SGPath();
80
81     /**
82      * Set path to a new value
83      * @param p new path
84      */
85     void set( const string p );
86
87     /**
88      * Append another piece to the existing path.  Inserts a path
89      * separator between the existing component and the new component.
90      * @param p additional path component */
91     void append( const string p );
92
93     /**
94      * Concatenate a string to the end of the path without inserting a
95      * path separator.
96      * @param p addtional path suffix
97      */
98     void concat( const string p );
99
100     /**
101      * Get the directory part of the path.
102      * @return directory string
103      */
104     string dir();
105   
106     /** Get the path string
107      * @return path string
108      */
109     inline string str() const { return path; }
110
111     /** Get the path string
112      * @return path in "C" string (ptr to char array) form.
113      */
114     inline const char *c_str() { return path.c_str(); }
115 };
116
117
118 #endif // _SG_PATH_HXX
119
120