3 * Routines to abstract out path separator differences between MacOS
4 * and the rest of the world.
7 // Written by Curtis L. Olson, started April 1999.
9 // Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include <sys/types.h>
33 #include <simgear/compiler.h>
36 #include <simgear/math/sg_types.hxx>
45 * A class to hide path separator difference across platforms and assist
46 * in managing file system path names.
48 * Paths can be input in any platform format and will be converted
49 * automatically to the proper format.
60 /** Default constructor */
64 * Construct a path based on the starting path provided.
65 * @param p initial path
67 SGPath( const string& p );
73 * Set path to a new value
76 void set( const string& p );
77 SGPath& operator= ( const char* p ) { this->set(p); return *this; }
80 * Append another piece to the existing path. Inserts a path
81 * separator between the existing component and the new component.
82 * @param p additional path component */
83 void append( const string& p );
86 * Append a new piece to the existing path. Inserts a search path
87 * separator to the existing path and the new patch component.
88 * @param p additional path component */
89 void add( const string& p );
92 * Concatenate a string to the end of the path without inserting a
94 * @param p additional path suffix
96 void concat( const string& p );
99 * Get the file part of the path (everything after the last path sep)
100 * @return file string
105 * Get the directory part of the path.
106 * @return directory string
111 * Get the base part of the path (everything but the extension.)
112 * @return the base string
117 * Get the extension part of the path (everything after the final ".")
118 * @return the extension string
120 string extension() const;
123 * Get the path string
124 * @return path string
126 string str() const { return path; }
129 * Get the path string
130 * @return path in "C" string (ptr to char array) form.
132 const char* c_str() { return path.c_str(); }
135 * Determine if file exists by attempting to fopen it.
136 * @return true if file exists, otherwise returns false.
141 * Create the designated directory.
142 * @return 0 on success, or <0 on failure.
144 int create_dir(mode_t mode);
154 * Split a directory string into a list of it's parent directories.
156 string_list sgPathBranchSplit( const string &path );
159 * Split a directory search path into a vector of individual paths
161 string_list sgPathSplit( const string &search_path );
164 #endif // _SG_PATH_HXX