TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::PropertyExtractor::PatternValidator Class Reference

Validates patterns that are passed to PropertyExtractor calls. More...

#include <PatternValidator.h>

Public Member Functions

 PatternValidator ()
 
void setNumRequiredComponentIndices (int numRequiredComponentIndices)
 
void setAllowedSubindexFlags (const std::vector< Subindex > &allowedSubindexFlags)
 
void setCallingFunctionName (const std::string &callingFunctionsName)
 
void validate (const std::vector< Index > &patterns) const
 

Detailed Description

Validates patterns that are passed to PropertyExtractor calls.

The PatternValidator checks whether a list of Indices satisfies given rules. It is used by PropertyExtractors to verify that the Indices that are passed to its calculate-functions have the right format.

The PatternValidator is used as follows

PatternValidator patternValidator;
//Configure the PatternValidator here
//...
patternValidator.validate(patterns);

Here patterns is a list of Indices that can contain Subindex flags. If all patterns pass, nothing happens. If some pattern does not pass, an error message is generated.

Number of component Index Indices

A multi-component Index is an Index such as {{x, y, z}, {x, y, z}}, which has two component Indices. By default, any number of component Indices are allowed. However, it is possible to configure the PatternValidator to require a given number of component Indices using

patternValidator.setNumRequiredComponentIndices(2);

Allowed Subindex flags

By default, no Subindex flags are allowed in the patterns. To allow a number of Subindex flags to be present in the pattern, add them using, for example

patternValidator.setAllowedSubindexFlags({IDX_ALL, IDX_SPIN});

Example

#include "TBTK/PropertyExtractor/PatternValidator.h"
#include "TBTK/TBTK.h"
using namespace TBTK;
using namespace PropertyExtractor;
int main(){
PatternValidator patternValidator;
patternValidator.setNumRequiredComponentIndices(2);
patternValidator.setAllowedSubindexFlags({IDX_ALL, IDX_SPIN});
patternValidator.validate({
{{1, IDX_ALL, IDX_SPIN}, {2, 3, 4}},
{{2, IDX_ALL, IDX_SPIN}, {2, 3, 4}}
});
Streams::out << "Validation passed\n";
}

Output

Validation passed

Constructor & Destructor Documentation

◆ PatternValidator()

TBTK::PropertyExtractor::PatternValidator::PatternValidator ( )
inline

Constructor.

Member Function Documentation

◆ setAllowedSubindexFlags()

void TBTK::PropertyExtractor::PatternValidator::setAllowedSubindexFlags ( const std::vector< Subindex > &  allowedSubindexFlags)
inline

Specify a list of Subindex flags that are allowed.

Parameters
allowedSubindexFlagsList of allowed Subindex flags.

◆ setCallingFunctionName()

void TBTK::PropertyExtractor::PatternValidator::setCallingFunctionName ( const std::string &  callingFunctionsName)
inline

Set the name of the calling function. Will be included in the error message if the validation fails.

Parameters
callingFunctionNameThe name of the calling function.

◆ setNumRequiredComponentIndices()

void TBTK::PropertyExtractor::PatternValidator::setNumRequiredComponentIndices ( int  numRequiredComponentIndices)
inline

Set the number of required component Indices. For example, {{x, y, z}, {x, y, z}} has two component Indices.

Parameters
numRequiredComponentIndicesThe number of component Indices the pattern must have. The default number -1 means that any number of components is allowed.

◆ validate()

void TBTK::PropertyExtractor::PatternValidator::validate ( const std::vector< Index > &  patterns) const
inline

Validate patterns.


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