simgear  3.5.0 [next] git://gitorious.org/fg/simgear.git
SimGear - Simulator Construction Tools
SGPath Class Reference

#include <sg_path.hxx>

Classes

struct  Permissions
 

Public Types

typedef Permissions(* PermissionChecker) (const SGPath &)
 
enum  StandardLocation {
  HOME, DESKTOP, DOWNLOADS, DOCUMENTS,
  PICTURES
}
 

Public Member Functions

 SGPath (PermissionChecker validator=NULL)
 
 SGPath (const SGPath &p)
 
 SGPath (const std::string &p, PermissionChecker validator=NULL)
 
 SGPath (const SGPath &p, const std::string &r, PermissionChecker validator=NULL)
 
 ~SGPath ()
 
void add (const std::string &p)
 
void append (const std::string &p)
 
std::string base () const
 
const char * c_str () const
 
bool canRead () const
 
bool canWrite () const
 
std::string complete_lower_extension () const
 
void concat (const std::string &p)
 
int create_dir (mode_t mode=0755)
 
std::string dir () const
 
bool exists () const
 
std::string extension () const
 
std::string file () const
 
std::string file_base () const
 
PermissionChecker getPermissionChecker () const
 
bool isAbsolute () const
 
bool isDir () const
 
bool isFile () const
 
bool isNull () const
 
bool isRelative () const
 
std::string lower_extension () const
 
time_t modTime () const
 
bool operator!= (const SGPath &other) const
 
SGPath operator/ (const std::string &p) const
 
SGPathoperator= (const SGPath &p)
 
SGPathoperator= (const char *p)
 
bool operator== (const SGPath &other) const
 
std::string realpath () const
 
bool remove ()
 
bool rename (const SGPath &newName)
 
void set (const std::string &p)
 
void set_cached (bool cached)
 
void setPermissionChecker (PermissionChecker validator)
 
std::string str () const
 
std::string str_native () const
 

Static Public Member Functions

static SGPath desktop (const SGPath &def=SGPath())
 
static SGPath documents (const SGPath &def=SGPath())
 
static SGPath fromEnv (const char *name, const SGPath &def=SGPath())
 
static SGPath home (const SGPath &def=SGPath())
 
static SGPath standardLocation (StandardLocation type, const SGPath &def=SGPath())
 

Private Member Functions

void checkAccess () const
 
void fix ()
 
void validate () const
 

Private Attributes

bool _cached: 1
 
bool _cacheEnabled: 1
 cacheing can be disbled if required More...
 
bool _canRead: 1
 
bool _canWrite: 1
 
bool _exists: 1
 
bool _isDir: 1
 
bool _isFile: 1
 
time_t _modTime
 
PermissionChecker _permission_checker
 
bool _rwCached: 1
 
std::string path
 

Detailed Description

A class to hide path separator difference across platforms and assist in managing file system path names.

Paths can be input in any platform format and will be converted automatically to the proper format.

Definition at line 51 of file sg_path.hxx.

Member Typedef Documentation

typedef Permissions(* SGPath::PermissionChecker) (const SGPath &)

Definition at line 60 of file sg_path.hxx.

Member Enumeration Documentation

Enumerator
HOME 
DESKTOP 
DOWNLOADS 
DOCUMENTS 
PICTURES 

Definition at line 263 of file sg_path.hxx.

Constructor & Destructor Documentation

SGPath::SGPath ( PermissionChecker  validator = NULL)
explicit

Default constructor

Definition at line 151 of file sg_path.cxx.

Referenced by fromEnv().

SGPath::SGPath ( const SGPath p)

Copy contructor

Definition at line 186 of file sg_path.cxx.

SGPath::SGPath ( const std::string &  p,
PermissionChecker  validator = NULL 
)

Construct a path based on the starting path provided.

Parameters
pinitial path

Definition at line 162 of file sg_path.cxx.

SGPath::SGPath ( const SGPath p,
const std::string &  r,
PermissionChecker  validator = NULL 
)

Construct a path based on the starting path provided and a relative subpath

Parameters
pinitial path
rrelative subpath

Definition at line 173 of file sg_path.cxx.

SGPath::~SGPath ( )

Destructor

Definition at line 218 of file sg_path.cxx.

Member Function Documentation

void SGPath::add ( const std::string &  p)

Append a new piece to the existing path. Inserts a search path separator to the existing path and the new patch component.

Parameters
padditional path component

Definition at line 273 of file sg_path.cxx.

Referenced by main().

string SGPath::base ( ) const

Get the base part of the path (everything but the final extension.)

Returns
the base string

Definition at line 315 of file sg_path.cxx.

bool SGPath::canRead ( ) const

Check if reading file is allowed. Readabilty does not imply the existance of the file.

Note
By default all files will be marked as readable. No check is made if the operating system allows the given file to be read. Derived classes may actually implement custom read/write rights.

Definition at line 455 of file sg_path.cxx.

Referenced by rename().

bool SGPath::canWrite ( ) const

Definition at line 462 of file sg_path.cxx.

Referenced by create_dir(), remove(), and rename().

void SGPath::checkAccess ( ) const
private

Definition at line 428 of file sg_path.cxx.

Referenced by canRead(), and canWrite().

string SGPath::complete_lower_extension ( ) const

Get the complete extension part of the path (everything after the first ".") this might look like 'tar.gz' or 'txt.Z', or might be identical to 'extension' above the extension is converted to lowercase.

Returns
the extension string

Definition at line 365 of file sg_path.cxx.

void SGPath::concat ( const std::string &  p)

Concatenate a string to the end of the path without inserting a path separator.

Parameters
padditional path suffix

Definition at line 280 of file sg_path.cxx.

Referenced by create_dir(), main(), and simgear::Dir::tempDir().

SGPath SGPath::desktop ( const SGPath def = SGPath())
static

Get path to the user's desktop directory

Definition at line 775 of file sg_path.cxx.

SGPath SGPath::documents ( const SGPath def = SGPath())
static

Get path to the user's documents directory

Definition at line 781 of file sg_path.cxx.

string SGPath::extension ( ) const

Get the extension part of the path (everything after the final ".")

Returns
the extension string

Definition at line 352 of file sg_path.cxx.

Referenced by lower_extension(), and sgLoad3DModel_internal().

string SGPath::file ( ) const

Get the file part of the path (everything after the last path sep)

Returns
file string

Definition at line 293 of file sg_path.cxx.

Referenced by simgear::pkg::Install::createFromPath(), main(), simgear::SVNDirectory::mergeUpdateReportDetails(), and simgear::pathSortPredicate().

string SGPath::file_base ( ) const

Get the base part of the filename (everything before the first '.')

Returns
the base filename

Definition at line 332 of file sg_path.cxx.

void SGPath::fix ( )
private

Definition at line 134 of file sg_path.cxx.

Referenced by append(), concat(), set(), and SGPath().

SGPath SGPath::fromEnv ( const char *  name,
const SGPath def = SGPath() 
)
static

Get a path stored in the environment variable with the given name.

Parameters
nameName of the environment variable
defDefault path to return if the environment variable does not exist or is empty.

Definition at line 751 of file sg_path.cxx.

Referenced by getXDGDir(), and home().

SGPath::PermissionChecker SGPath::getPermissionChecker ( ) const

Definition at line 238 of file sg_path.cxx.

Referenced by appleSpecialFolder(), and getXDGDir().

SGPath SGPath::home ( const SGPath def = SGPath())
static

Get path to user's home directory

Definition at line 768 of file sg_path.cxx.

Referenced by getXDGDir(), and standardLocation().

bool SGPath::isAbsolute ( ) const

Is this an absolute path? I.e starts with a directory seperator, or a single character + colon

Definition at line 581 of file sg_path.cxx.

Referenced by isRelative().

bool SGPath::isDir ( ) const
bool SGPath::isFile ( ) const

Definition at line 474 of file sg_path.cxx.

Referenced by simgear::Dir::children(), and test_dir().

bool SGPath::isRelative ( ) const
inline

Opposite sense to isAbsolute

Definition at line 233 of file sg_path.hxx.

string SGPath::lower_extension ( ) const

Get the extension part of the path (everything after the final ".") converted to lowercase

Returns
the extension string

Definition at line 361 of file sg_path.cxx.

Referenced by SGMaterial::read_properties(), and simgear::ReaderWriterSTG::_ModelBin::DelayLoadReadFileCallback::readNode().

time_t SGPath::modTime ( ) const

modification time of the file

Definition at line 644 of file sg_path.cxx.

Referenced by test_dir().

bool SGPath::operator!= ( const SGPath other) const

Definition at line 655 of file sg_path.cxx.

SGPath SGPath::operator/ ( const std::string &  p) const

Get a copy of this path with another piece appended.

Parameters
padditional path component

Definition at line 265 of file sg_path.cxx.

SGPath & SGPath::operator= ( const SGPath p)

Definition at line 201 of file sg_path.cxx.

SGPath& SGPath::operator= ( const char *  p)
inline

Definition at line 93 of file sg_path.hxx.

bool SGPath::operator== ( const SGPath other) const

Definition at line 650 of file sg_path.cxx.

std::string SGPath::realpath ( ) const

Returns a string with the absolute pathname that names the same file, whose resolution does not involve '.', '..', or symbolic links.

Definition at line 787 of file sg_path.cxx.

bool SGPath::remove ( )

delete the file, if possible

Definition at line 622 of file sg_path.cxx.

Referenced by simgear::SVNDirectory::deleteChildByName(), simgear::Dir::removeChildren(), and rename().

bool SGPath::rename ( const SGPath newName)

rename the file / directory we point at, to a new name this may fail if the new location is on a different volume / share, or if the destination already exists, or is not writeable

Definition at line 661 of file sg_path.cxx.

Referenced by simgear::pkg::Install::PackageArchiveDownloader::onDone(), and simgear::SVNDirectory::writeCache().

void SGPath::set ( const std::string &  p)

Set path to a new value

Parameters
pnew path

Definition at line 223 of file sg_path.cxx.

Referenced by operator=(), and SGTime::updateLocal().

void SGPath::set_cached ( bool  cached)

Set if file information (exists, type, mod-time) is cached or retrieved each time it is queried. Caching is enabled by default

Definition at line 244 of file sg_path.cxx.

Referenced by simgear::Dir::Dir(), and simgear::Dir::file().

void SGPath::setPermissionChecker ( PermissionChecker  validator)

Definition at line 231 of file sg_path.cxx.

SGPath SGPath::standardLocation ( StandardLocation  type,
const SGPath def = SGPath() 
)
static

Definition at line 701 of file sg_path.cxx.

Referenced by desktop(), documents(), and test_dir().

std::string SGPath::str_native ( ) const

Get the path string in OS native form

Definition at line 604 of file sg_path.cxx.

Referenced by simgear::SGTerraSync::SvnThread::runExternalSyncCommand().

void SGPath::validate ( ) const
private

Definition at line 383 of file sg_path.cxx.

Referenced by exists(), isDir(), isFile(), and modTime().

Member Data Documentation

bool SGPath::_cached
mutableprivate

Definition at line 309 of file sg_path.hxx.

Referenced by append(), concat(), operator=(), remove(), rename(), set(), and validate().

bool SGPath::_cacheEnabled
private

cacheing can be disbled if required

Definition at line 311 of file sg_path.hxx.

Referenced by checkAccess(), operator=(), set_cached(), and validate().

bool SGPath::_canRead
mutableprivate

Definition at line 312 of file sg_path.hxx.

Referenced by canRead(), checkAccess(), and operator=().

bool SGPath::_canWrite
mutableprivate

Definition at line 313 of file sg_path.hxx.

Referenced by canWrite(), checkAccess(), and operator=().

bool SGPath::_exists
mutableprivate

Definition at line 314 of file sg_path.hxx.

Referenced by exists(), isDir(), isFile(), operator=(), and validate().

bool SGPath::_isDir
mutableprivate

Definition at line 315 of file sg_path.hxx.

Referenced by isDir(), operator=(), and validate().

bool SGPath::_isFile
mutableprivate

Definition at line 316 of file sg_path.hxx.

Referenced by isFile(), operator=(), and validate().

time_t SGPath::_modTime
mutableprivate

Definition at line 317 of file sg_path.hxx.

Referenced by modTime(), operator=(), and validate().

PermissionChecker SGPath::_permission_checker
private
bool SGPath::_rwCached
mutableprivate

Definition at line 310 of file sg_path.hxx.

Referenced by append(), checkAccess(), concat(), operator=(), remove(), rename(), set(), and setPermissionChecker().


The documentation for this class was generated from the following files: