Paths (C++)¶
-
group
Geolib3PathUtils
All of these functions (which take as input an absolute scene graph location path) assume a properly normalized scene graph path:
- no trailing slash ‘/’
- no redundent internal separator (A//B, A/B/, A/./B and A/foo/../B all become A/B.)
Examples of normalized locations:
/root /root/world/geo /root/world/taco/a/b
Examples of un-normalised locations:
/root/ /root/world/ /root/world/../a /root/world/taco//a/b
Functions
-
std::string
NormalizeAbsPath
(const std::string &locationPath)¶
-
std::string
GetLocationParent
(FnPlatform::StringView locationPath)¶ GetLocationParent('/root/world/geo') => '/root/world' GetLocationParent('/root') => ''
- Return
- the parent scene graph location path for the given input e.g.
-
std::string
GetLeafName
(FnPlatform::StringView locationPath)¶ GetLeafName('/a/b/c') => 'c'
- Return
- the leaf for the given input e.g.
-
void
GetLeafAndParent
(std::string &parent, std::string &leaf, FnPlatform::StringView locationPath)¶
-
void
GetLocationStack
(std::vector<std::string> &returnStack, const std::string &locationPath, const std::string &rootPath = std::string())¶ Example:
GetLocationStack('/a/b/c') => ['/a','/a/b','/a/b/c'] GetLocationStack('/a/b/c/d/e', root='/a/b/c') => ['/a/b/c', '/a/b/c/d', '/a/b/c/d/e'] GetLocationStack('/a/b/c', root='/a/b/c') => ['/a/b/c']
- Parameters
returnStack
-container that will be populated with the return stack
locationPath
-the location path to be processed
rootPath
-an optional ‘root’ location from which to begin.
-
bool
IsAncestorOrEqual
(FnPlatform::StringView locA, FnPlatform::StringView locB)¶ Example:
IsAncestorOrEqual('/root/a','/root/a/b/c') => true IsAncestorOrEqual('/root/a','/root/a') => true
- Return
- true if location A is an ancestor or equal of location B
- Parameters
locA
-scene graph location A
locB
-scene graph location B
-
bool
IsAncestor
(FnPlatform::StringView locA, FnPlatform::StringView locB)¶ Example
IsAncestor('/root/a','/root/a/b/c') => true IsAncestor('/root/a','/root/a') => false
- Return
- true if location A is an ancestor of location B
- Parameters
locA
-scene graph location A
locB
-scene graph location B
-
std::string
Join
(FnPlatform::StringView locA, FnPlatform::StringView locB)¶
-
bool
IsRelativePath
(const std::string &path)¶
-
std::string
RelativeToAbsPath
(const std::string &rootPath, const std::string &path)¶ Example:
RelativeToAbsPath('/root/world','../') => '/root'
- Return
- a new absolute path given the
rootPath
andpath
. - Parameters
rootPath
-the path from which to generate the new absolute path
path
-the relative path specifier.
-
std::string
NormalizedRelativePath
(const std::string &rootpath, const std::string &path)¶ Given a
rootpath
, and either a relative or absolute path, create a normalized relative path.Example:
NormalizedRelativePath('/root','/root/world') -> 'world' NormalizedRelativePath('/root','/root/world/geo') -> 'world/geo' NormalizedRelativePath('/root','/root') -> '' NormalizedRelativePath('/root','/notroot') -> EXCEPTION NormalizedRelativePath('/root','a/b/c') -> 'a/b/c'
- Note
- This function will throw an exception if root is not ancestor or equal to path.
- Return
- a normalized relative path
- Parameters
rootpath
-the root path
path
-the full path from which to generate the relative path.
-
std::string
RelativePath
(const std::string &rootPath, const std::string &path)¶ Given two absolute paths, create a relative path from rootPath to path even if rootPath is not an ancestor of path).
Example:
RelativePath('/root/world/geo', '/root/world/geo/a') -> 'a' RelativePath('/root/world/geo/a', '/root/world/geo') -> '..' RelativePath('/root/world/geo/a', '/root/world/geo/b') -> '../b' RelativePath('/root/world/geo/a', '/root/world/geo/a') -> '' RelativePath('/root/world/geo/a', '/root/world/cam/a') -> '../../cam/a'
- Return
- a relative path from rootPath to path
- Parameters
rootPath
-the root path
path
-path to generate the relative path to.
-
void
FnMatch
(FnMatchInfo &matchInfo, FnPlatform::StringView testpath, FnPlatform::StringView pattern)¶ - Note
testpath
and pattern should be absolute scene graph paths, normalized in the style ofpystring::normpath_posix
- Parameters
matchInfo
-instance of match info
testpath
-scene graph path to be tested
pattern
-pattern to match against.
-
void
FnMatchIncludingAncestors
(FnMatchInfo &matchInfo, FnPlatform::StringView testpath, FnPlatform::StringView pattern)¶ - Note
testpath
and pattern should be absolute scene graph paths, normalized in the style ofpystring::normpath_posix
- Parameters
matchInfo
-instance of match info
testpath
-scene graph path to be tested
pattern
-pattern to match against.
-
void
ExactMatch
(FnMatchInfo &matchInfo, FnPlatform::StringView testpath, FnPlatform::StringView pattern)¶ - Note
- testpath and pattern should be absolute scene graph paths, normalized in the style of
pystring::normpath_posix
- Parameters
matchInfo
-instance of match info
testpath
-scene graph path to be tested
pattern
-pattern to match against.
-
std::string
MakeUniqueName
(FnPlatform::StringView baseName, const std::set<std::string> &existingNames)¶
-
std::string
MakeSafeIdentifier
(FnPlatform::StringView identifier)¶
-
int
Compare
(FnPlatform::StringView pathA, FnPlatform::StringView pathB)¶ Compares two scene graph location paths.
Each path component of
pathA
is compared lexicographically with the corresponding component ofpathB
. The function assumes normalized, absolute paths (except for superfluous trailing slashes, which are ignored).- Return
- a negative value if
pathA
sorts beforepathB
, zero if both paths compare equal, and a positive value ifpathA
sorts afterpathB
. - Parameters
pathA
-scene graph location path A
pathB
-scene graph location path A
-
struct
FnMatchInfo
¶