]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sg_path.hxx
MSVC .NET 2003 fix
[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 #include STL_STRING
35
36 #include <simgear/math/sg_types.hxx>
37
38 SG_USING_STD(string);
39
40
41 /**
42  * A class to hide path separator difference across platforms and assist
43  * in managing file system path names.
44  *
45  * Paths can be input in any platform format and will be converted
46  * automatically to the proper format.
47  */
48
49 class SGPath {
50
51 private:
52
53     string path;
54
55 public:
56
57     /** Default constructor */
58     SGPath();
59
60     /**
61      * Construct a path based on the starting path provided.
62      * @param p initial path
63      */
64     SGPath( const string& p );
65
66     /** Destructor */
67     ~SGPath();
68
69     /**
70      * Set path to a new value
71      * @param p new path
72      */
73     void set( const string& p );
74     SGPath& operator= ( const char* p ) { this->set(p); return *this; }
75
76     /**
77      * Append another piece to the existing path.  Inserts a path
78      * separator between the existing component and the new component.
79      * @param p additional path component */
80     void append( const string& p );
81
82     /**
83      * Concatenate a string to the end of the path without inserting a
84      * path separator.
85      * @param p addtional path suffix
86      */
87     void concat( const string& p );
88
89     /**
90      * Get the file part of the path (everything after the last path sep)
91      * @return file string
92      */
93     string file() const;
94   
95     /**
96      * Get the directory part of the path.
97      * @return directory string
98      */
99     string dir() const;
100   
101     /**
102      * Get the base part of the path (everything but the extension.)
103      * @return the base string
104      */
105     string base() const;
106
107     /**
108      * Get the extention part of the path (everything after the final ".")
109      * @return the extention string
110      */
111     string extension() const;
112
113     /** Get the path string
114      * @return path string
115      */
116     string str() const { return path; }
117
118     /** Get the path string
119      * @return path in "C" string (ptr to char array) form.
120      */
121     const char* c_str() { return path.c_str(); }
122
123     /**
124      * Determine if file exists by attempting to fopen it.
125      * @return true if file exists, otherwise returns false.
126      */
127     bool exists() const;
128
129 private:
130
131     void fix();
132
133 };
134
135
136 /**
137  * Split a directory search path into a vector of individual paths
138  */
139 string_list sgPathSplit( const string &search_path );
140
141
142 #endif // _SG_PATH_HXX
143
144