API 4.4.1-2022-10-19-2c4045e59
For MATLAB, Python, Java, and C++ users
|
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... | |
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.
OpenSim::ComponentPath::ComponentPath | ( | ) |
Default constructor that constructs an empty path ("").
OpenSim::ComponentPath::ComponentPath | ( | std::string | path | ) |
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.
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.
char OpenSim::ComponentPath::getSeparator | ( | ) | const |
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::Socket< T >::finalizeConnection(), and 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().
bool OpenSim::ComponentPath::operator!= | ( | const ComponentPath & | ) | const |
bool OpenSim::ComponentPath::operator== | ( | const ComponentPath & | ) | const |
void OpenSim::ComponentPath::pushBack | ( | const std::string & | pathElement | ) |
Push a string onto the end of the path.
Throws if the argument contains invalid characters.
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().
|
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.