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>
43 * A class to hide path separator difference across platforms and assist
44 * in managing file system path names.
46 * Paths can be input in any platform format and will be converted
47 * automatically to the proper format.
58 /** Default constructor */
62 * Construct a path based on the starting path provided.
63 * @param p initial path
65 SGPath( const string& p );
71 * Set path to a new value
74 void set( const string& p );
75 SGPath& operator= ( const char* p ) { this->set(p); return *this; }
78 * Append another piece to the existing path. Inserts a path
79 * separator between the existing component and the new component.
80 * @param p additional path component */
81 void append( const string& p );
84 * Append a new piece to the existing path. Inserts a search path
85 * separator to the existing path and the new patch component.
86 * @param p additional path component */
87 void add( const string& p );
90 * Concatenate a string to the end of the path without inserting a
92 * @param p addtional path suffix
94 void concat( const string& p );
97 * Get the file part of the path (everything after the last path sep)
103 * Get the directory part of the path.
104 * @return directory string
109 * Get the base part of the path (everything but the extension.)
110 * @return the base string
115 * Get the extention part of the path (everything after the final ".")
116 * @return the extention string
118 string extension() const;
120 /** Get the path string
121 * @return path string
123 string str() const { return path; }
125 /** Get the path string
126 * @return path in "C" string (ptr to char array) form.
128 const char* c_str() { return path.c_str(); }
131 * Determine if file exists by attempting to fopen it.
132 * @return true if file exists, otherwise returns false.
137 * Create the designated directory.
139 void create_dir(mode_t mode);
149 * Split a directory search path into a vector of individual paths
151 string_list sgPathSplit( const string &search_path );
154 #endif // _SG_PATH_HXX