API  4.5.1
For C++ developers
OpenSim::ComponentPath Class Reference

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

Public Member Functions

 ComponentPath ()=default
 Default constructor that constructs an empty path (""). More...
 
 ComponentPath (std::string)
 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...
 
void clear ()
 Clears the content of the ComponentPath. More...
 
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 empty () const
 Returns true if the path is empty. 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...
 

Static Public Member Functions

static constexpr char separator ()
 Returns the separator used to delimit path elements in the path. More...
 
static ComponentPath root ()
 Returns the root component path (i.e. More...
 

Friends

bool operator== (const ComponentPath &lhs, const ComponentPath &rhs)
 
bool operator!= (const ComponentPath &lhs, const ComponentPath &rhs)
 
bool operator< (const ComponentPath &lhs, const ComponentPath &rhs)
 
std::ostream & operator<< (std::ostream &lhs, const ComponentPath &rhs)
 Writes the ComponentPath to the output stream as a string. 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

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

◆ ComponentPath() [2/3]

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

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

◆ clear()

void OpenSim::ComponentPath::clear ( )
inline

Clears the content of the ComponentPath.

◆ empty()

bool OpenSim::ComponentPath::empty ( ) const
inline

Returns true if the path is empty.

◆ 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
inline

◆ 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::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().

◆ 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.

◆ root()

static ComponentPath OpenSim::ComponentPath::root ( )
static

Returns the root component path (i.e.

"/")

◆ separator()

static constexpr char OpenSim::ComponentPath::separator ( )
inlinestatic

Returns the separator used to delimit path elements in the path.

◆ toString()

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

◆ 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.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const ComponentPath lhs,
const ComponentPath rhs 
)
friend

◆ operator<

bool operator< ( const ComponentPath lhs,
const ComponentPath rhs 
)
friend

◆ operator<<

std::ostream& operator<< ( std::ostream &  lhs,
const ComponentPath rhs 
)
friend

Writes the ComponentPath to the output stream as a string.

◆ operator==

bool operator== ( const ComponentPath lhs,
const ComponentPath rhs 
)
friend

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