API  4.0
For C++ developers
OpenSim::Path Class Referenceabstract

An abstract class for handling a Path. More...

+ Inheritance diagram for OpenSim::Path:

Public Member Functions

 Path (const char separator, const std::string invalidChars)
 Create an empty path. More...
 
 Path (const std::string path, const char separator, const std::string invalidChars)
 Construct Path from a string, given separator character and a string of invalidChars. More...
 
 Path (const std::vector< std::string > pathVec, const char separator, const std::string invalidChars, bool isAbsolute)
 Construct Path from a vector of strings (pathVec), given separator character and a string of invalidChars. More...
 
 Path (const Path &)=default
 Use default copy constructor and assignment operator. More...
 
Pathoperator= (const Path &)=default
 
virtual ~Path ()=default
 Destructor. More...
 
std::string toString () const
 Write out the path to a string with each element separated by the specified separator. More...
 
bool isAbsolute () const
 Return true if this Path is an absolute path. More...
 
size_t getNumPathLevels () const
 Return the number of levels (or elements) in the Path. More...
 
void pushBack (const std::string &pathElement)
 Push a string to the back of a path (i.e. More...
 
virtual const char getSeparator () const =0
 Pure virtual function that returns a char for the designated separator. More...
 
virtual const std::string getInvalidChars () const =0
 Pure virtual function that returns a string of invalid characters. More...
 
bool isLegalPathElement (const std::string &pathElement) const
 Return true if pathElement does not contain any chars from the list of getInvalidChars() More...
 
void trimDotAndDotDotElements ()
 This removes "." elements and resolves ".." elements if possible (i.e., it will not remove leading ".." but otherwise will remove pairs of ".." and the preceding element). More...
 

Protected Member Functions

std::vector< std::string > formAbsolutePathVec (const Path &otherPath) const
 Get an absolute path by resolving it relative to a given otherPath. More...
 
std::vector< std::string > formRelativePathVec (const Path &otherPath) const
 Find the relative Path between this Path and another Path (otherPath) (i.e. More...
 
std::vector< std::string > getParentPathVec () const
 Return the sub-path that contains all pathElements except for the last one. More...
 
std::string getPathElement (size_t pos) const
 Return the pathElement from the specified position as a string. More...
 
std::string getPathName () const
 Return the last pathElement as a string. More...
 

Detailed Description

An abstract class for handling a Path.

A Path refers to a list of strings that represent a different level in a hierarchical structure. Each level is divided by designated separators (e.g., "/" or "\"). The string name related to each level is called a "pathElement" here. This class is unrelated to the GeometryPath class used in PathActuators.

This class stores the list of levels as a vector of strings. One char is used to denote a path separator when either reading in or writing the Path out to a string. A bool is stored to determine whether this Path should be resolved relative to the root (denoted with a leading separator char) or not.

Author
Carmichael Ong

Constructor & Destructor Documentation

◆ Path() [1/4]

OpenSim::Path::Path ( const char  separator,
const std::string  invalidChars 
)

Create an empty path.

◆ Path() [2/4]

OpenSim::Path::Path ( const std::string  path,
const char  separator,
const std::string  invalidChars 
)

Construct Path from a string, given separator character and a string of invalidChars.

This constructor removes "." elements and resolves ".." if possible.

◆ Path() [3/4]

OpenSim::Path::Path ( const std::vector< std::string >  pathVec,
const char  separator,
const std::string  invalidChars,
bool  isAbsolute 
)

Construct Path from a vector of strings (pathVec), given separator character and a string of invalidChars.

This constructor removes "." elements and resolves ".." if possible.

◆ Path() [4/4]

OpenSim::Path::Path ( const Path )
default

Use default copy constructor and assignment operator.

◆ ~Path()

virtual OpenSim::Path::~Path ( )
virtualdefault

Destructor.

Member Function Documentation

◆ formAbsolutePathVec()

std::vector<std::string> OpenSim::Path::formAbsolutePathVec ( const Path otherPath) const
protected

Get an absolute path by resolving it relative to a given otherPath.

If the current Path is already absolute, return the same Path.

◆ formRelativePathVec()

std::vector<std::string> OpenSim::Path::formRelativePathVec ( const Path otherPath) const
protected

Find the relative Path between this Path and another Path (otherPath) (i.e.

the Path to go FROM otherPath TO this Path). Both Paths must be absolute.

◆ getInvalidChars()

virtual const std::string OpenSim::Path::getInvalidChars ( ) const
pure virtual

Pure virtual function that returns a string of invalid characters.

Implemented in OpenSim::ComponentPath.

◆ getNumPathLevels()

size_t OpenSim::Path::getNumPathLevels ( ) const
inline

Return the number of levels (or elements) in the Path.

Referenced by OpenSim::Input< T >::finalizeConnection(), and OpenSim::Component::traversePathToComponent().

◆ getParentPathVec()

std::vector<std::string> OpenSim::Path::getParentPathVec ( ) const
inlineprotected

Return the sub-path that contains all pathElements except for the last one.

◆ getPathElement()

std::string OpenSim::Path::getPathElement ( size_t  pos) const
inlineprotected

Return the pathElement from the specified position as a string.

This does not do any checks on the bounds.

◆ getPathName()

std::string OpenSim::Path::getPathName ( ) const
inlineprotected

Return the last pathElement as a string.

◆ getSeparator()

virtual const char OpenSim::Path::getSeparator ( ) const
pure virtual

Pure virtual function that returns a char for the designated separator.

Implemented in OpenSim::ComponentPath.

◆ isAbsolute()

bool OpenSim::Path::isAbsolute ( ) const
inline

Return true if this Path is an absolute path.

Referenced by OpenSim::Input< T >::finalizeConnection(), and OpenSim::Component::traversePathToComponent().

◆ isLegalPathElement()

bool OpenSim::Path::isLegalPathElement ( const std::string &  pathElement) const

Return true if pathElement does not contain any chars from the list of getInvalidChars()

Referenced by OpenSim::AbstractSocket::checkConnecteePathProperty().

◆ operator=()

Path& OpenSim::Path::operator= ( const Path )
default

◆ pushBack()

void OpenSim::Path::pushBack ( const std::string &  pathElement)
inline

Push a string to the back of a path (i.e.

the end). First checks if the pathElement is valid. This function does not alter whether this path is absolute or relative.

Referenced by OpenSim::Component::findComponent().

◆ toString()

std::string OpenSim::Path::toString ( ) const

◆ trimDotAndDotDotElements()

void OpenSim::Path::trimDotAndDotDotElements ( )

This removes "." elements and resolves ".." elements if possible (i.e., it will not remove leading ".." but otherwise will remove pairs of ".." and the preceding element).

This method also checks if a path is invalid due to an absolute path starting with "..".

Referenced by OpenSim::Component::traversePathToComponent().


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