Enzo
Loading...
Searching...
No Matches
enzo::Path Class Reference

A default path class for creation and manipulation of tree-based paths. More...

#include <Path.h>

Inheritance diagram for enzo::Path:
enzo::NetworkPath

Public Member Functions

 Path ()
 Constructs an empty enzo::Path object.
 
 Path (const std::string &path)
 Constructs an enzo::Path object from a given std::string.
 
 Path (const char *path)
 Constructs an enzo::Path object from a C string.
 
bool isEmpty () const
 Checks if the Path has no characters.
 
bool isRoot () const
 Returns true if the Path is "/".
 
bool isAbsolute () const
 Returns true if the Path is an absolute path.
 
bool isRelative () const
 Returns true if the Path is a relative path.
 
virtual bool isValid () const
 Runs every validation check and returns true if the path is fully valid.
 
std::string getName () const
 Returns the name of the Path, ie, the last component of the path.
 
Path getParent () const
 Returns the parent path as a Path if it exists.
 
std::vector< PathgetPrefixes () const
 Returns every ancestor path leading up to this path, ordered from shortest to longest. The path itself is not included.
 
std::vector< std::string > split () const
 Splits all of the components of a Path and returns them as a vector of strings.
 
const std::string & getString () const
 Return the path of the Path as an std::string.
 
Path append (const enzo::Path &path) const
 Returns a new path formed by appending the given path to this one.
 
virtual Path increment (int increment=1) const
 Increments the numerical suffix of the path's name by a given amount.
 
Path makeRelative () const
 Converts an absolute path to relative, stripping the root character.
 
Path makeAbsolute () const
 Converts a relative path to absolute, adding a root character.
 
Path makeRelativeTo (const Path &anchor) const
 Makes a path relative to a given anchor path.
 
bool hasPrefix (const Path &prefix) const
 Checks if the Path has any additional prefixes.
 
 operator std::string_view () const
 Allows a Path to be viewed as its underlying string, e.g. for comparisons against string_views.
 
bool operator== (std::string_view other) const
 
bool operator!= (std::string_view other) const
 

Static Public Member Functions

static std::string strip (const std::string &str)
 Returns the string with surrounding whitespace removed.
 
static bool isValidFormatting (const std::string &pathString)
 Checks the path to make sure it fits the alphanumeric guidelines.
 
static bool isValidName (const std::string &name)
 Checks the given name to make sure it fits the alphanumeric guidelines.
 

Protected Attributes

std::string path_
 

Detailed Description

A default path class for creation and manipulation of tree-based paths.

Member Function Documentation

◆ append()

enzo::Path enzo::Path::append ( const enzo::Path & path) const

Returns a new path formed by appending the given path to this one.

The appended path may be a single component or a multi component path. A leading root delimiter on the appended path is ignored so it joins as a relative segment.

Parameters
pathThe path to append to the end of this path.
Returns
A new Path with path appended.

◆ getPrefixes()

std::vector< enzo::Path > enzo::Path::getPrefixes ( ) const

Returns every ancestor path leading up to this path, ordered from shortest to longest. The path itself is not included.

E.g. the path "/World/Set/Props/Chair" returns /World /World/Set /World/Set/Props

◆ hasPrefix()

bool enzo::Path::hasPrefix ( const Path & prefix) const

Checks if the Path has any additional prefixes.

Returns
true or false depending on whether the Path contains any prefixes.

◆ increment()

enzo::Path enzo::Path::increment ( int increment = 1) const
virtual

Increments the numerical suffix of the path's name by a given amount.

A name with no numerical suffix is treated as 0, so the first increment produces a "1" suffix.

Parameters
incrementThe amount to increment by. Defaults to 1.
Returns
A new Path with the incremented name.

◆ isValid()

bool enzo::Path::isValid ( ) const
virtual

Runs every validation check and returns true if the path is fully valid.

A path is valid when it is non empty and every component is a valid name. The root path "/" is also valid.

Examples "/geo/mesh_01" valid "geo/mesh" valid relative path "/geo//mesh" invalid empty component "/geo/me!sh" invalid illegal character

See also
isValidName for the per component character rules.

Reimplemented in enzo::NetworkPath.

◆ isValidFormatting()

bool enzo::Path::isValidFormatting ( const std::string & pathString)
static

Checks the path to make sure it fits the alphanumeric guidelines.

Parameters
pathStringA std::string representation of the path.
Returns
true or false based on whether the path formatting is valid or not.
See also
isValidName for the per component character rules.

◆ isValidName()

bool enzo::Path::isValidName ( const std::string & name)
static

Checks the given name to make sure it fits the alphanumeric guidelines.

A valid name is non empty and contains only alphanumeric characters and underscores.

Parameters
nameThe name that is being checked.
Returns
true or false based on whether the name is valid or not.

◆ makeAbsolute()

enzo::Path enzo::Path::makeAbsolute ( ) const

Converts a relative path to absolute, adding a root character.

Returns
A new Path object with the absolute path.

◆ makeRelative()

enzo::Path enzo::Path::makeRelative ( ) const

Converts an absolute path to relative, stripping the root character.

Returns
A new Path object with the new relative path.

◆ makeRelativeTo()

enzo::Path enzo::Path::makeRelativeTo ( const Path & anchor) const

Makes a path relative to a given anchor path.

Parameters
anchorAnother Path object to act as an anchor, the method will return the original path if the anchor is the same as the path.
Returns
A Path object of the new relative path.

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