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

A class for working with formatted strings related to ModelParts. More...

Inheritance diagram for ModelPartPattern:
Collaboration diagram for ModelPartPattern:

Public Member Functions

Type Definitions
 KRATOS_CLASS_POINTER_DEFINITION (ModelPartPattern)
 
Life Cycle
 ModelPartPattern ()=default
 
 ModelPartPattern (const std::string &rPattern)
 
 ModelPartPattern (ModelPartPattern &&rOther)=default
 
 ModelPartPattern (const ModelPartPattern &rOther)=default
 
Operations
std::string Apply (const ModelPart &rModelPart) const
 Substitute values from the specified ModelPart in the stored pattern. More...
 
std::string Apply (Ref< const PlaceholderMap > rPlaceholderValueMap) const
 Substitute values in the stored pattern. More...
 
Operators
PlaceholderPatternoperator= (PlaceholderPattern &&rOther)=default
 
PlaceholderPatternoperator= (const PlaceholderPattern &rOther)=default
 
- Public Member Functions inherited from PlaceholderPattern
 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
 
PlaceholderPatternoperator= (PlaceholderPattern &&rOther)=default
 
PlaceholderPatternoperator= (const PlaceholderPattern &rOther)=default
 
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...
 
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...
 
 KRATOS_CLASS_POINTER_DEFINITION (PlaceholderPattern)
 

Protected Methods

 ModelPartPattern (const std::string &rPattern, const PlaceholderMap &rPlaceholderMap)
 Forwarding constructor for derived classes. More...
 
virtual void PopulatePlaceholderMap (PlaceholderMap &rMap, const ModelPart &rModelPart) const
 Populate a key-value map of registered placeholders from a ModelPart. More...
 
static PlaceholderMap GetPlaceholderMap ()
 

Additional Inherited Members

- Public Types inherited from PlaceholderPattern
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
 

Detailed Description

A class for working with formatted strings related to ModelParts.

Operations on strings with the following placeholders are supported:

  • <model_part_name>
  • <step>
  • <time>
  • <rank> See PlaceholderPattern for supported functionalities. Other placeholders can be added at compile time by tweaking the construction of the static member ModelPartPattern::mModelpartPlaceholderMap.

Constructor & Destructor Documentation

◆ ModelPartPattern() [1/5]

ModelPartPattern ( )
default

◆ ModelPartPattern() [2/5]

ModelPartPattern ( const std::string &  rPattern)

◆ ModelPartPattern() [3/5]

ModelPartPattern ( ModelPartPattern &&  rOther)
default

◆ ModelPartPattern() [4/5]

ModelPartPattern ( const ModelPartPattern rOther)
default

◆ ModelPartPattern() [5/5]

ModelPartPattern ( const std::string &  rPattern,
const PlaceholderMap rPlaceholderMap 
)
protected

Forwarding constructor for derived classes.

Member Function Documentation

◆ Apply() [1/2]

std::string Apply ( const ModelPart &  rModelPart) const

Substitute values from the specified ModelPart in the stored pattern.

Parameters
rModelPartModel part to extract the values of placeholders from.
Note
rModelPart must store STEP and TIME.
Todo:
Add support for string formatting. Options are:
  • snprintf from the C STL (security issues due to allowing the user to freely specify the format)
  • fmt::format (requires fmtlib)
  • std::format (==fmtlib adopted in the standard, requires C++20)
  • boost::format (requires boost)

◆ Apply() [2/2]

std::string Apply

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"}

◆ GetPlaceholderMap()

static PlaceholderMap GetPlaceholderMap ( )
staticprotected

◆ KRATOS_CLASS_POINTER_DEFINITION()

KRATOS_CLASS_POINTER_DEFINITION ( ModelPartPattern  )

◆ operator=() [1/2]

PlaceholderPattern& operator=
default

◆ operator=() [2/2]

PlaceholderPattern& operator=
default

◆ PopulatePlaceholderMap()

virtual void PopulatePlaceholderMap ( PlaceholderMap rMap,
const ModelPart &  rModelPart 
) const
protectedvirtual

Populate a key-value map of registered placeholders from a ModelPart.

Reimplemented in CheckpointPattern.


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