WRApplication
External kratos "application" for multiscale time integration.
PlaceholderPattern Class Reference

A class for interfacing placeholders and regular expressions. More...

Inheritance diagram for PlaceholderPattern:
Collaboration diagram for PlaceholderPattern:

Public Member Functions

Life Cycle
 PlaceholderPattern ()=default
 
 PlaceholderPattern (Ref< const std::string > rPattern, Ref< const PlaceholderMap > rPlaceholderMap)
 Construct from a placeholder pattern and its associated map. More...
 
 PlaceholderPattern (PlaceholderPattern &&rOther)=default
 
 PlaceholderPattern (const PlaceholderPattern &rOther)=default
 
virtual ~PlaceholderPattern ()=default
 
Operators
PlaceholderPatternoperator= (PlaceholderPattern &&rOther)=default
 
PlaceholderPatternoperator= (const PlaceholderPattern &rOther)=default
 
Operations
bool IsAMatch (Ref< const std::string > rString) const
 Check whether a string satisfies the pattern. More...
 
MatchType Match (Ref< const std::string > rString) const
 Find all placeholders' values in the input string. More...
 
std::string Apply (Ref< const PlaceholderMap > rPlaceholderValueMap) const
 Substitute values in the stored pattern. More...
 
template<class TOutputIterator >
void Glob (TOutputIterator it) const
 Collect all file/directory paths that match the pattern. More...
 
Inquiry
bool IsConst () const
 Return true if the input pattern contains no placeholders. More...
 
Ref< const std::regex > GetRegex () const
 Get the regex for the input pattern. More...
 
Ref< const std::string > GetRegexString () const
 Get the string representation of the regex. More...
 
PlaceholderMap GetPlaceholderMap () const
 Get a map of all placeholders and their associated regex representations. More...
 
Ref< const std::string > GetPatternString () const
 Get the pattern with placeholders. More...
 

Type Definitions

using PlaceholderMap = std::map< std::string, std::string >
 
using PlaceholderGroupMap = std::map< std::string, std::optional< std::vector< std::size_t > >>
 
using MatchType = std::map< std::string, std::vector< std::string > >
 
using PathType = std::filesystem::path
 
 KRATOS_CLASS_POINTER_DEFINITION (PlaceholderPattern)
 

Detailed Description

A class for interfacing placeholders and regular expressions.

Note
placeholders should be separated by literals, otherwise regex will probably not capture them as you'd expect. BAD example:
pattern: "<placeholder_1><placeholder_2>"
string: "abcdefg"
result:
"<placeholder_1>" : "abcdef"
"<placeholder_2>" : "g"
CORRECT example:
pattern: "<placeholder_1>d<placeholder_2>"
string: "abcdefg"
result:
"<placeholder_1>" : "abc"
"<placeholder_2>" : "efg"

Member Typedef Documentation

◆ MatchType

using MatchType = std::map<std::string,std::vector<std::string> >

◆ PathType

using PathType = std::filesystem::path

◆ PlaceholderGroupMap

using PlaceholderGroupMap = std::map<std::string,std::optional<std::vector<std::size_t> >>

◆ PlaceholderMap

using PlaceholderMap = std::map<std::string,std::string>

Constructor & Destructor Documentation

◆ PlaceholderPattern() [1/4]

PlaceholderPattern ( )
default

◆ PlaceholderPattern() [2/4]

PlaceholderPattern ( Ref< const std::string >  rPattern,
Ref< const PlaceholderMap rPlaceholderMap 
)

Construct from a placeholder pattern and its associated map.

Parameters
rPatternPattern string with placeholders.
rPlaceholderMapPairs of placeholders and their corresponding regex strings. Example:
{{"<name>", ".+"}, {"<identifier>", "[0-9]+"}}
Warning
The corresponding regexes must be bare, not containing groups (checked) or position constraints such as line begin or end modifiers (not checked).

◆ PlaceholderPattern() [3/4]

PlaceholderPattern ( PlaceholderPattern &&  rOther)
default

◆ PlaceholderPattern() [4/4]

PlaceholderPattern ( const PlaceholderPattern rOther)
default

◆ ~PlaceholderPattern()

virtual ~PlaceholderPattern ( )
virtualdefault

Member Function Documentation

◆ Apply()

std::string Apply ( Ref< const PlaceholderMap rPlaceholderValueMap) const

Substitute values in the stored pattern.

Return a copy of the pattern that has its placeholders replaced with the corresponding values specified in the input map.

Parameters
rPlaceholderValueMapstring - string map associating values to placeholders
{"palceholder" : "placeholder_value"}

◆ GetPatternString()

Ref<const std::string> GetPatternString ( ) const

Get the pattern with placeholders.

◆ GetPlaceholderMap()

PlaceholderMap GetPlaceholderMap ( ) const

Get a map of all placeholders and their associated regex representations.

◆ GetRegex()

Ref<const std::regex> GetRegex ( ) const

Get the regex for the input pattern.

◆ GetRegexString()

Ref<const std::string> GetRegexString ( ) const

Get the string representation of the regex.

◆ Glob()

void Glob ( TOutputIterator  it) const

Collect all file/directory paths that match the pattern.

Template Parameters
TOutputIteratoroutput iterator with value type constructible from PathType.
Note
the search begins from the filesystem root if the pattern is an absolute path, otherwise it begins from cwd.

◆ IsAMatch()

bool IsAMatch ( Ref< const std::string >  rString) const

Check whether a string satisfies the pattern.

◆ IsConst()

bool IsConst ( ) const

Return true if the input pattern contains no placeholders.

◆ KRATOS_CLASS_POINTER_DEFINITION()

KRATOS_CLASS_POINTER_DEFINITION ( PlaceholderPattern  )

◆ Match()

MatchType Match ( Ref< const std::string >  rString) const

Find all placeholders' values in the input string.

Parameters
rStringString matching the input pattern.
Returns
Map associating a vector of strings, i.e. the values of placeholders in the input string, to the placeholders.
Note
The returned placeholder values appear in the same order they do in the input pattern.

◆ operator=() [1/2]

PlaceholderPattern& operator= ( const PlaceholderPattern rOther)
default

◆ operator=() [2/2]

PlaceholderPattern& operator= ( PlaceholderPattern &&  rOther)
default

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