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 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.
32 #include <sys/types.h>
34 #include <simgear/compiler.h>
37 #include <simgear/math/sg_types.hxx>
46 * A class to hide path separator difference across platforms and assist
47 * in managing file system path names.
49 * Paths can be input in any platform format and will be converted
50 * automatically to the proper format.
61 /** Default constructor */
65 * Construct a path based on the starting path provided.
66 * @param p initial path
68 SGPath( const string& p );
74 * Set path to a new value
77 void set( const string& p );
78 SGPath& operator= ( const char* p ) { this->set(p); return *this; }
81 * Append another piece to the existing path. Inserts a path
82 * separator between the existing component and the new component.
83 * @param p additional path component */
84 void append( const string& p );
87 * Append a new piece to the existing path. Inserts a search path
88 * separator to the existing path and the new patch component.
89 * @param p additional path component */
90 void add( const string& p );
93 * Concatenate a string to the end of the path without inserting a
95 * @param p addtional path suffix
97 void concat( const string& p );
100 * Get the file part of the path (everything after the last path sep)
101 * @return file string
106 * Get the directory part of the path.
107 * @return directory string
112 * Get the base part of the path (everything but the extension.)
113 * @return the base string
118 * Get the extention part of the path (everything after the final ".")
119 * @return the extention string
121 string extension() const;
124 * Get the path string
125 * @return path string
127 string str() const { return path; }
130 * Get the path string
131 * @return path in "C" string (ptr to char array) form.
133 const char* c_str() { return path.c_str(); }
136 * Determine if file exists by attempting to fopen it.
137 * @return true if file exists, otherwise returns false.
142 * Create the designated directory.
144 void 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