API
4.0
For C++ developers
|
An abstract class for handling a Path. More...
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... | |
Path & | operator= (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... | |
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.
OpenSim::Path::Path | ( | const char | separator, |
const std::string | invalidChars | ||
) |
Create an empty path.
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.
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.
|
default |
Use default copy constructor and assignment operator.
|
virtualdefault |
Destructor.
|
protected |
|
protected |
|
pure virtual |
Pure virtual function that returns a string of invalid characters.
Implemented in OpenSim::ComponentPath.
|
inline |
Return the number of levels (or elements) in the Path.
Referenced by OpenSim::Input< T >::finalizeConnection(), and OpenSim::Component::traversePathToComponent().
|
inlineprotected |
Return the sub-path that contains all pathElements except for the last one.
|
inlineprotected |
Return the pathElement from the specified position as a string.
This does not do any checks on the bounds.
|
inlineprotected |
Return the last pathElement as a string.
|
pure virtual |
Pure virtual function that returns a char for the designated separator.
Implemented in OpenSim::ComponentPath.
|
inline |
Return true if this Path is an absolute path.
Referenced by OpenSim::Input< T >::finalizeConnection(), and OpenSim::Component::traversePathToComponent().
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().
|
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().
std::string OpenSim::Path::toString | ( | ) | const |
Write out the path to a string with each element separated by the specified separator.
Referenced by OpenSim::Input< T >::finalizeConnection(), OpenSim::Socket< T >::findAndConnect(), OpenSim::Component::findComponent(), OpenSim::Component::getComponent(), OpenSim::ComponentPath::operator!=(), and OpenSim::ComponentPath::operator==().
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().