API 4.4.1-2022-10-19-2c4045e59
For MATLAB, Python, Java, and C++ users
OpenSim::ComponentPath Class Reference

A representation of a path within a Component tree. More...

Public Member Functions

 ComponentPath ()
 Default constructor that constructs an empty path (""). More...
 
 ComponentPath (std::string path)
 Construct a ComponentPath from a path string (e.g. More...
 
 ComponentPath (const std::vector< std::string > &pathVec, bool isAbsolute)
 Construct a ComponentPath from a vector of its elements. More...
 
bool operator== (const ComponentPath &) const
 
bool operator!= (const ComponentPath &) const
 
char getSeparator () const
 
const std::string & getInvalidChars () const
 Returns a string containing a sequence of all invalid characters. More...
 
ComponentPath formAbsolutePath (const ComponentPath &otherPath) const
 Returns a path that is the result of resolving this from otherPath. More...
 
ComponentPath formRelativePath (const ComponentPath &otherPath) const
 Find the relative Path between this Path and another Path (otherPath) (i.e. More...
 
ComponentPath getParentPath () const
 Returns the sub-path that contains all subdirectory levels except for the last one. More...
 
std::string getParentPathString () const
 Returns the parent path as a string. More...
 
std::string getSubcomponentNameAtLevel (size_t index) const
 Returns the name of a subdirectory in the path at the specified level (0-indexed). More...
 
std::string getComponentName () const
 Returns the name of the Component in the path (effectively, the last element in the path). More...
 
const std::string & toString () const
 Returns a string representation of the ComponentPath (e.g. More...
 
bool isAbsolute () const
 Returns true if the path is absolute (effectively, if it begins with '/'). More...
 
size_t getNumPathLevels () const
 Returns the number of levels in the path (e.g. More...
 
void pushBack (const std::string &pathElement)
 Push a string onto the end of the path. More...
 
bool isLegalPathElement (const std::string &pathElement) const
 Returns true if the argument does not contain any invalid characters. More...
 
void trimDotAndDotDotElements ()
 Resolves '. More...
 

Detailed Description

A representation of a path within a Component tree.

This class is effectively a wrapper around a normalized path string. A path string is a sequence of path elements interspersed with '/' as a separator. path elements cannot contain:

  • back-slash ('\')
  • forward-slash ('/')
  • asterisk ('*')
  • plus-sign ('+')

An empty path, "", is allowed. Adjacent separators in a path (e.g. "//") are combined into one separator.

Author
Carmichael Ong

Constructor & Destructor Documentation

◆ ComponentPath() [1/3]

OpenSim::ComponentPath::ComponentPath ( )

Default constructor that constructs an empty path ("").

◆ ComponentPath() [2/3]

OpenSim::ComponentPath::ComponentPath ( std::string  path)

Construct a ComponentPath from a path string (e.g.

"/a/b/component").

◆ ComponentPath() [3/3]

OpenSim::ComponentPath::ComponentPath ( const std::vector< std::string > &  pathVec,
bool  isAbsolute 
)

Construct a ComponentPath from a vector of its elements.

Throws if any element in pathVec contains an invalid character.

Member Function Documentation

◆ formAbsolutePath()

ComponentPath OpenSim::ComponentPath::formAbsolutePath ( const ComponentPath otherPath) const

Returns a path that is the result of resolving this from otherPath.

  • otherPath must be an absolute path; otherwise, an exception will be thrown
  • if this is absolute, then this function just returns a copy of this

Examples:

ComponentPath{"b/c"}.formAbsolutePath("/a") == "/a/b/c"
ComponentPath{"/b/c"}.formAbsolutePath("/a") == "/b/c"
ComponentPath{"b/c"}.formAbsolutePath("a")  // throws

◆ formRelativePath()

ComponentPath OpenSim::ComponentPath::formRelativePath ( const ComponentPath otherPath) const

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.

◆ getComponentName()

std::string OpenSim::ComponentPath::getComponentName ( ) const

Returns the name of the Component in the path (effectively, the last element in the path).

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

◆ getInvalidChars()

const std::string & OpenSim::ComponentPath::getInvalidChars ( ) const

Returns a string containing a sequence of all invalid characters.

◆ getNumPathLevels()

size_t OpenSim::ComponentPath::getNumPathLevels ( ) const

Returns the number of levels in the path (e.g.

"/a/b/c" == 3).

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

◆ getParentPath()

ComponentPath OpenSim::ComponentPath::getParentPath ( ) const

Returns the sub-path that contains all subdirectory levels except for the last one.

◆ getParentPathString()

std::string OpenSim::ComponentPath::getParentPathString ( ) const

Returns the parent path as a string.

◆ getSeparator()

char OpenSim::ComponentPath::getSeparator ( ) const

◆ getSubcomponentNameAtLevel()

std::string OpenSim::ComponentPath::getSubcomponentNameAtLevel ( size_t  index) const

Returns the name of a subdirectory in the path at the specified level (0-indexed).

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

◆ isAbsolute()

bool OpenSim::ComponentPath::isAbsolute ( ) const

Returns true if the path is absolute (effectively, if it begins with '/').

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

◆ isLegalPathElement()

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

Returns true if the argument does not contain any invalid characters.

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

◆ operator!=()

bool OpenSim::ComponentPath::operator!= ( const ComponentPath ) const

◆ operator==()

bool OpenSim::ComponentPath::operator== ( const ComponentPath ) const

◆ pushBack()

void OpenSim::ComponentPath::pushBack ( const std::string &  pathElement)

Push a string onto the end of the path.

Throws if the argument contains invalid characters.

◆ toString()

const std::string & OpenSim::ComponentPath::toString ( ) const

Returns a string representation of the ComponentPath (e.g.

"/a/b/component").

Referenced by OpenSim::Socket< T >::finalizeConnection(), OpenSim::Input< T >::finalizeConnection(), and OpenSim::Socket< T >::findAndConnect().

◆ trimDotAndDotDotElements()

void OpenSim::ComponentPath::trimDotAndDotDotElements ( )
inline

Resolves '.

' and ".." elements in the path if possible. Leading ".." elements are allowed only in relative paths (throws if found at the start of an absolute path). Also checks for invalid characters.

Effectively, this is the same as internally normalizeing the path.


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