cisst-saw
Loading...
Searching...
No Matches
cmnPath Class Reference

Search path to find a file. This class contains a list of directories used to locate a file. More...

#include <cmnPath.h>

Inheritance diagram for cmnPath:
cmnGenericObject

Public Types

enum  { HEAD = true , TAIL = false }
enum  { EXIST = 00 , WRITE = 02 , READ = 04 , EXECUTE = 04 }
typedef std::list< std::string > ContainerType
typedef ContainerType::iterator iterator
typedef ContainerType::const_iterator const_iterator

Public Member Functions

 cmnPath (void)
 cmnPath (const std::string &path)
virtual ~cmnPath (void)
void Set (const std::string &path)
void Add (const std::string &path, bool head=HEAD)
bool AddFromEnvironment (const std::string &variableName, bool head=HEAD)
bool AddRelativeToCisstRoot (const std::string &relativePath, bool head=HEAD)
bool AddRelativeToCisstShare (const std::string &relativePath, bool head=HEAD)
std::string Find (const std::string &filename, short mode=READ) const
std::string FindWithSubdirectory (const std::string &filename, const std::string &subdirectory, short mode=READ) const
bool Remove (const std::string &directory)
bool Has (const std::string &directory) const
void ToStream (std::ostream &outputStream) const override
Public Member Functions inherited from cmnGenericObject
virtual ~cmnGenericObject (void)
virtual const cmnClassServicesBaseServices (void) const =0
bool ReconstructFrom (const cmnGenericObject &other)
std::string ToString (void) const
virtual void ToStreamRaw (std::ostream &outputStream, const char delimiter=' ', bool headerOnly=false, const std::string &headerPrefix="") const
virtual bool FromStreamRaw (std::istream &inputStream, const char delimiter=' ')
virtual void SerializeRaw (std::ostream &outputStream) const
virtual void DeSerializeRaw (std::istream &inputStream)
virtual cmnLogger::StreamBufTypeGetLogMultiplexer (void) const
virtual size_t ScalarNumber (void) const
virtual bool ScalarNumberIsFixed (void) const
virtual double Scalar (const size_t CMN_UNUSED(index)) const CISST_THROW(std
virtual std::string ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const

Static Public Member Functions

static const std::string & DirectorySeparator (void)
static std::string GetWorkingDirectory (void)
static bool GetCisstRoot (std::string &result)
static bool GetCisstShare (std::string &result)
static bool Exists (const std::string &fullPath, short more=READ)
static bool DeleteFile (const std::string &fullPath)
static bool RenameFile (const std::string &fullPathOld, const std::string &fullPathNew)
static std::string SharedLibrary (const std::string &name)
static std::string Executable (const std::string &name)

Detailed Description

Search path to find a file. This class contains a list of directories used to locate a file.

The directories can be added either at the head or the tail of the list. This class doesn't check weither the directories in the path actually exist, mostly to allow a portable program (e.g. one program can add both "/usr/local/bin" and "C:\Program Files").

As a convention, the separator between subdirectories should be a "/" (slash) and the separation between two directories in the path is ";" (semi-colon). For example, "/bin;/usr/bin" will add both "/bin" and "/usr/bin".

Member Typedef Documentation

◆ const_iterator

typedef ContainerType::const_iterator cmnPath::const_iterator

◆ ContainerType

typedef std::list<std::string> cmnPath::ContainerType

Container used to store the directories.

◆ iterator

typedef ContainerType::iterator cmnPath::iterator

STL like iterators.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Defines the mode to be used for a given file.

Enumerator
EXIST 
WRITE 
READ 
EXECUTE 

◆ anonymous enum

anonymous enum

Defines how to add a path to the search list.

Enumerator
HEAD 
TAIL 

Constructor & Destructor Documentation

◆ cmnPath() [1/2]

cmnPath::cmnPath ( void )

◆ cmnPath() [2/2]

cmnPath::cmnPath ( const std::string & path)

Create a search path from a string.

◆ ~cmnPath()

virtual cmnPath::~cmnPath ( void )
inlinevirtual

Destructor

Member Function Documentation

◆ Add()

void cmnPath::Add ( const std::string & path,
bool head = HEAD )

Add one or more directories to the path.

◆ AddFromEnvironment()

bool cmnPath::AddFromEnvironment ( const std::string & variableName,
bool head = HEAD )

Add one or more directories to the path using an environment variable.

◆ AddRelativeToCisstRoot()

bool cmnPath::AddRelativeToCisstRoot ( const std::string & relativePath,
bool head = HEAD )

Add path relative to the CISST_ROOT environment variable. This can be useful to find shared libraries. To find data files, use AddRelativeToCisstShare.

◆ AddRelativeToCisstShare()

bool cmnPath::AddRelativeToCisstShare ( const std::string & relativePath,
bool head = HEAD )

Add path relative to the shared cisst directory, i.e. CISST_ROOT/share/cisst-<version>.

◆ DeleteFile()

bool cmnPath::DeleteFile ( const std::string & fullPath)
static

Delete file. This function doesn't use any search path.

◆ DirectorySeparator()

const std::string & cmnPath::DirectorySeparator ( void )
static

A platform-independent string for separating subdirectory or file name from the parent directory name. It's equal to "/" on Linux, "\\" on Windows, etc.

◆ Executable()

std::string cmnPath::Executable ( const std::string & name)
inlinestatic

Construct the executable name based on OS suffix. For example, the return value for "MyProgram" would be "MyProgram" on most Unix systems and "MyProgram.exe" on Windows. Suffix is based on CMake and saved in cisstConfig.h.

◆ Exists()

bool cmnPath::Exists ( const std::string & fullPath,
short more = READ )
static

Check if a file exists assuming the path provided is either relative or absolute, this function doesn't use any search path.

◆ Find()

std::string cmnPath::Find ( const std::string & filename,
short mode = READ ) const

Find the full name for a given file.

Returns
The full path including the filename or an empty string.

◆ FindWithSubdirectory()

std::string cmnPath::FindWithSubdirectory ( const std::string & filename,
const std::string & subdirectory,
short mode = READ ) const

Find the full name for a given file using all directories in path as well as given "sub directory" in each directory. E.g if the path contains /bin and /usr/bin and the sub-directory provided is "Release", the full search path if /bin/Release, /bin, /usr/bin/Release, /usr/bin. One can also #include <cisstBuildType.h> which defines the string CISST_BUILD_SUFFIX.

Returns
The full path including the filename or an empty string.

◆ GetCisstRoot()

bool cmnPath::GetCisstRoot ( std::string & result)
static

Get CISST_ROOT from the environment variable

◆ GetCisstShare()

bool cmnPath::GetCisstShare ( std::string & result)
static

Get cisst shared directory based on CISST_ROOT from the environment variable

◆ GetWorkingDirectory()

std::string cmnPath::GetWorkingDirectory ( void )
static

Get working directory

◆ Has()

bool cmnPath::Has ( const std::string & directory) const

Indicates if a given directory is in the search list.

◆ Remove()

bool cmnPath::Remove ( const std::string & directory)

Remove the first occurence of a directory from the search list.

◆ RenameFile()

bool cmnPath::RenameFile ( const std::string & fullPathOld,
const std::string & fullPathNew )
static

Rename file. This function doesn't use any search path.

◆ Set()

void cmnPath::Set ( const std::string & path)

Set the path from a string.

◆ SharedLibrary()

std::string cmnPath::SharedLibrary ( const std::string & name)
inlinestatic

Construct the shared library name based on OS prefix and suffix. For example, the return value for "MyLib" would be "libMyLib.so" on most Unix systems and "MyLib.dll" on Windows. Prefix and suffix are based on CMake and saved in cisstConfig.h.

◆ ToStream()

void cmnPath::ToStream ( std::ostream & outputStream) const
overridevirtual

Write the path to a stream.

Reimplemented from cmnGenericObject.


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