API
4.5.1
For C++ developers
|
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... | |
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:
An empty path, "", is allowed. Adjacent separators in a path (e.g. "//") are combined into one separator.
|
default |
Default constructor that constructs an empty path ("").
OpenSim::ComponentPath::ComponentPath | ( | std::string | ) |
Construct a ComponentPath from a path string (e.g.
"/a/b/component").
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.
|
inline |
Clears the content of the ComponentPath.
|
inline |
Returns true if the path is empty.
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 thrownthis
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
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.
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().
const std::string& OpenSim::ComponentPath::getInvalidChars | ( | ) | const |
Returns a string containing a sequence of all invalid characters.
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().
ComponentPath OpenSim::ComponentPath::getParentPath | ( | ) | const |
Returns the sub-path that contains all subdirectory levels except for the last one.
std::string OpenSim::ComponentPath::getParentPathString | ( | ) | const |
Returns the parent path as a string.
|
inline |
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().
bool OpenSim::ComponentPath::isAbsolute | ( | ) | const |
Returns true if the path is absolute (effectively, if it begins with '/').
Referenced by OpenSim::Input< T >::finalizeConnection().
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().
void OpenSim::ComponentPath::pushBack | ( | const std::string & | pathElement | ) |
Push a string onto the end of the path.
Throws if the argument contains invalid characters.
|
static |
Returns the root component path (i.e.
"/")
|
inlinestatic |
Returns the separator used to delimit path elements in the path.
|
inline |
Returns a string representation of the ComponentPath (e.g.
"/a/b/component").
Referenced by OpenSim::Socket< T >::finalizeConnection(), OpenSim::Input< T >::finalizeConnection(), OpenSim::Socket< T >::findAndConnect(), OpenSim::Component::getComponent(), and std::hash< OpenSim::ComponentPath >::operator()().
|
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 normalize
ing the path.
|
friend |
|
friend |
|
friend |
Writes the ComponentPath
to the output stream as a string.
|
friend |