CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::GenericDatumFormatter< ValueType, DataObject > Class Template Reference

#include <DataFormatterTools.hh>

+ Inheritance diagram for CASM::GenericDatumFormatter< ValueType, DataObject >:

Detailed Description

template<typename ValueType, typename DataObject>
class CASM::GenericDatumFormatter< ValueType, DataObject >

A DatumFormatter that returns a value of specified type, via functions that may be specified at runtime.

Definition at line 868 of file DataFormatterTools.hh.

Public Types

using Evaluator = std::function< ValueType(const DataObject &)>
 
using Validator = std::function< bool(const DataObject &)>
 
typedef DataObject DataObject
 
typedef long difference_type
 
typedef DataFormatterDictionary< DataObject, BaseDatumFormatter< DataObject > > DictType
 

Public Member Functions

 GenericDatumFormatter (const std::string &_init_name, const std::string &_desc, Evaluator _evaluator, Validator _validator=always_true< DataObject >)
 Constructor. More...
 
ValueType evaluate (const DataObject &obj) const override
 Returns Container type piece of data about a DataObject, the result of the Evaluator. More...
 
std::unique_ptr< GenericDatumFormatterclone () const
 Clone. More...
 
bool validate (const DataObject &obj) const override
 Returns boolean indicating if the _evaluator can be used successfully, the result of the Validator. More...
 
virtual ValueType operator() (const DataObject &obj) const
 Return requested data from obj, throwing std::runtime_error if not valid. More...
 
virtual void inject (const DataObject &_data_obj, DataStream &_stream, Index pass_index=0) const override
 Default implementation injects each element, via operator<<. More...
 
virtual void print (const DataObject &_data_obj, std::ostream &_stream, Index pass_index=0) const override
 Default implementation prints each element in a column, via operator<<. More...
 
virtual jsonParserto_json (const DataObject &_data_obj, jsonParser &json) const override
 Default implementation calls jsonParser& to_json(const ValueType&, jsonParser&) More...
 
const std::string & name () const
 Returns a name for the formatter, which becomes the tag used for parsing. More...
 
const std::string & description () const
 Returns a short description of the formatter and its allowed arguments (if any). This description is used to automatically generate help screens. More...
 
virtual DatumFormatterClass type () const
 
const DictTypehome () const
 const Access the dictionary containing this formatter, set during DictType::lookup More...
 
void set_home (const DictType &home) const
 Set the dictionary containing this formatter, set during DictType::lookup. More...
 
virtual bool init (const DataObject &_template_obj) const
 Perform all initialization steps using _template_obj. Returns true if initialization is successful and false if _template_obj has insufficient data to complete initialization. More...
 
virtual std::vector< std::string > col_header (const DataObject &_template_obj) const
 Returns a header string for each scalar produced by the formatter parsing the entries in the col_header should reproduce the exact query described by the formatter. Ex: "clex(formation_energy)" or "comp(a)", "comp(c)". More...
 
virtual std::string long_header (const DataObject &_template_obj) const
 Returns a long expression for each scalar produced by the formatter parsing the long_header should reproduce the exact query described by the formatter Ex: "clex(formation_energy)" or "comp(a) comp(c)". More...
 
virtual std::string short_header (const DataObject &_template_obj) const
 Returns a short expression for the formatter parsing the short_header should allow the formatter to be recreated (but the short header does not specify a subset of the elements) Ex: "clex(formation_energy)" or "comp". More...
 
virtual Index num_passes (const DataObject &_data_obj) const
 
virtual bool parse_args (const std::string &args)
 

Protected Types

typedef multivector< Index >::X< 2 > IndexContainer
 

Protected Member Functions

void _parse_index_expression (const std::string &_expr)
 
void _add_rule (const std::vector< Index > &new_rule) const
 
const IndexContainer_index_rules () const
 

Private Member Functions

GenericDatumFormatter_clone () const override
 Clone. More...
 

Private Attributes

Evaluator m_evaluate
 
Validator m_validate
 
std::string m_name
 
std::string m_description
 
IndexContainer m_index_rules
 
const DictTypem_home
 

Member Typedef Documentation

◆ DataObject

Definition at line 334 of file DataFormatter.hh.

◆ DictType

◆ difference_type

Definition at line 335 of file DataFormatter.hh.

◆ Evaluator

template<typename ValueType , typename DataObject >
using CASM::GenericDatumFormatter< ValueType, DataObject >::Evaluator = std::function<ValueType(const DataObject &)>

Definition at line 870 of file DataFormatterTools.hh.

◆ IndexContainer

typedef multivector<Index>::X<2> CASM::BaseDatumFormatter< DataObject >::IndexContainer
protectedinherited

Definition at line 459 of file DataFormatter.hh.

◆ Validator

template<typename ValueType , typename DataObject >
using CASM::GenericDatumFormatter< ValueType, DataObject >::Validator = std::function<bool(const DataObject &)>

Definition at line 871 of file DataFormatterTools.hh.

Constructor & Destructor Documentation

◆ GenericDatumFormatter()

template<typename ValueType , typename DataObject >
CASM::GenericDatumFormatter< ValueType, DataObject >::GenericDatumFormatter ( const std::string &  _init_name,
const std::string &  _desc,
Evaluator  _evaluator,
Validator  _validator = always_true<DataObject> 
)
inline

Constructor.

Parameters
_nameName of formatter
_descDescription of the formatter
_evaluatorReturns a ValueType type piece of data about a DataObject
_validatorReturns boolean indicating if the _evaluator can be used successfully

Definition at line 881 of file DataFormatterTools.hh.

Member Function Documentation

◆ _add_rule()

void CASM::BaseDatumFormatter< DataObject >::_add_rule ( const std::vector< Index > &  new_rule) const
inlineprotectedinherited

Definition at line 472 of file DataFormatter.hh.

◆ _clone()

template<typename ValueType , typename DataObject >
GenericDatumFormatter* CASM::GenericDatumFormatter< ValueType, DataObject >::_clone ( ) const
inlineoverrideprivatevirtual

Clone.

Implements CASM::BaseValueFormatter< ValueType, DataObject >.

Definition at line 915 of file DataFormatterTools.hh.

◆ _index_rules()

const IndexContainer& CASM::BaseDatumFormatter< DataObject >::_index_rules ( ) const
inlineprotectedinherited

Definition at line 476 of file DataFormatter.hh.

◆ _parse_index_expression()

void CASM::BaseDatumFormatter< DataObject >::_parse_index_expression ( const std::string &  _expr)
protectedinherited

Derived DatumFormatters have some optional functionality for parsing index expressions in order to make it easy to handle ranges such as:

formatter_name(3,4:8)

in which case, DerivedDatumFormatter::parse_args() is called with the string "3,4:8" by dispatching that string to BaseDatumFormatter::_parse_index_expression(), m_index_rules will be populated with {{3,4},{3,5},{3,6},{3,7},{3,8}}

Definition at line 470 of file DataFormatter_impl.hh.

◆ clone()

template<typename ValueType , typename DataObject >
std::unique_ptr<GenericDatumFormatter> CASM::GenericDatumFormatter< ValueType, DataObject >::clone ( ) const
inline

Clone.

Definition at line 900 of file DataFormatterTools.hh.

◆ col_header()

virtual std::vector<std::string> CASM::BaseDatumFormatter< DataObject >::col_header ( const DataObject _template_obj) const
inlinevirtualinherited

Returns a header string for each scalar produced by the formatter parsing the entries in the col_header should reproduce the exact query described by the formatter. Ex: "clex(formation_energy)" or "comp(a)", "comp(c)".

  • Default uses short_header

Reimplemented in CASM::Base2DDatumFormatter< Container, DataObject >, CASM::Base1DDatumFormatter< Container, DataObject >, and CASM::DatumFormatterAlias< DataObject >.

Definition at line 389 of file DataFormatter.hh.

◆ description()

const std::string& CASM::BaseDatumFormatter< DataObject >::description ( ) const
inlineinherited

Returns a short description of the formatter and its allowed arguments (if any). This description is used to automatically generate help screens.

Definition at line 352 of file DataFormatter.hh.

◆ evaluate()

template<typename ValueType , typename DataObject >
ValueType CASM::GenericDatumFormatter< ValueType, DataObject >::evaluate ( const DataObject obj) const
inlineoverridevirtual

Returns Container type piece of data about a DataObject, the result of the Evaluator.

Implements CASM::BaseValueFormatter< ValueType, DataObject >.

Definition at line 895 of file DataFormatterTools.hh.

◆ home()

const DictType& CASM::BaseDatumFormatter< DataObject >::home ( ) const
inlineinherited

const Access the dictionary containing this formatter, set during DictType::lookup

Definition at line 360 of file DataFormatter.hh.

◆ init()

virtual bool CASM::BaseDatumFormatter< DataObject >::init ( const DataObject _template_obj) const
inlinevirtualinherited

Perform all initialization steps using _template_obj. Returns true if initialization is successful and false if _template_obj has insufficient data to complete initialization.

Reimplemented in CASM::Base2DDatumFormatter< Container, DataObject >, CASM::Base1DDatumFormatter< Container, DataObject >, and CASM::DatumFormatterAlias< DataObject >.

Definition at line 376 of file DataFormatter.hh.

◆ inject()

template<typename ValueType , typename DataObject >
virtual void CASM::BaseValueFormatter< ValueType, DataObject >::inject ( const DataObject _data_obj,
DataStream _stream,
Index  pass_index = 0 
) const
inlineoverridevirtualinherited

Default implementation injects each element, via operator<<.

Implements CASM::BaseDatumFormatter< DataObject >.

Reimplemented in CASM::Base2DDatumFormatter< Container, DataObject >, and CASM::Base1DDatumFormatter< Container, DataObject >.

Definition at line 821 of file DataFormatterTools.hh.

◆ long_header()

virtual std::string CASM::BaseDatumFormatter< DataObject >::long_header ( const DataObject _template_obj) const
inlinevirtualinherited

Returns a long expression for each scalar produced by the formatter parsing the long_header should reproduce the exact query described by the formatter Ex: "clex(formation_energy)" or "comp(a) comp(c)".

  • Default uses col_header

Definition at line 399 of file DataFormatter.hh.

◆ name()

const std::string& CASM::BaseDatumFormatter< DataObject >::name ( ) const
inlineinherited

Returns a name for the formatter, which becomes the tag used for parsing.

Definition at line 347 of file DataFormatter.hh.

◆ num_passes()

virtual Index CASM::BaseDatumFormatter< DataObject >::num_passes ( const DataObject _data_obj) const
inlinevirtualinherited

If data must be printed on multiple rows, returns number of rows needed to output all data from _data_obj DataFormatter class will subsequently pass over _data_obj multiple times to complete printing (if necessary)

Reimplemented in CASM::Base2DDatumFormatter< Container, DataObject >, and CASM::DatumFormatterAlias< DataObject >.

Definition at line 424 of file DataFormatter.hh.

◆ operator()()

template<typename ValueType , typename DataObject >
virtual ValueType CASM::BaseValueFormatter< ValueType, DataObject >::operator() ( const DataObject obj) const
inlinevirtualinherited

Return requested data from obj, throwing std::runtime_error if not valid.

Definition at line 803 of file DataFormatterTools.hh.

◆ parse_args()

◆ print()

template<typename ValueType , typename DataObject >
virtual void CASM::BaseValueFormatter< ValueType, DataObject >::print ( const DataObject _data_obj,
std::ostream &  _stream,
Index  pass_index = 0 
) const
inlineoverridevirtualinherited

Default implementation prints each element in a column, via operator<<.

  • Prints "unknown" if validation fails

Implements CASM::BaseDatumFormatter< DataObject >.

Reimplemented in CASM::Base2DDatumFormatter< Container, DataObject >, and CASM::Base1DDatumFormatter< Container, DataObject >.

Definition at line 833 of file DataFormatterTools.hh.

◆ set_home()

void CASM::BaseDatumFormatter< DataObject >::set_home ( const DictType home) const
inlineinherited

Set the dictionary containing this formatter, set during DictType::lookup.

Definition at line 364 of file DataFormatter.hh.

◆ short_header()

virtual std::string CASM::BaseDatumFormatter< DataObject >::short_header ( const DataObject _template_obj) const
inlinevirtualinherited

Returns a short expression for the formatter parsing the short_header should allow the formatter to be recreated (but the short header does not specify a subset of the elements) Ex: "clex(formation_energy)" or "comp".

Reimplemented in CASM::DatumFormatterAlias< DataObject >, and CASM::DataFormatterOperator< ValueType, ArgType, DataObject >.

Definition at line 417 of file DataFormatter.hh.

◆ to_json()

template<typename ValueType , typename DataObject >
virtual jsonParser& CASM::BaseValueFormatter< ValueType, DataObject >::to_json ( const DataObject _data_obj,
jsonParser json 
) const
inlineoverridevirtualinherited

Default implementation calls jsonParser& to_json(const ValueType&, jsonParser&)

  • Does nothing if validation fails

Implements CASM::BaseDatumFormatter< DataObject >.

Definition at line 847 of file DataFormatterTools.hh.

◆ type()

◆ validate()

template<typename ValueType , typename DataObject >
bool CASM::GenericDatumFormatter< ValueType, DataObject >::validate ( const DataObject obj) const
inlineoverridevirtual

Returns boolean indicating if the _evaluator can be used successfully, the result of the Validator.

Reimplemented from CASM::BaseDatumFormatter< DataObject >.

Definition at line 909 of file DataFormatterTools.hh.

Member Data Documentation

◆ m_description

std::string CASM::BaseDatumFormatter< DataObject >::m_description
privateinherited

Definition at line 486 of file DataFormatter.hh.

◆ m_evaluate

template<typename ValueType , typename DataObject >
Evaluator CASM::GenericDatumFormatter< ValueType, DataObject >::m_evaluate
private

Definition at line 919 of file DataFormatterTools.hh.

◆ m_home

const DictType* CASM::BaseDatumFormatter< DataObject >::m_home
mutableprivateinherited

Definition at line 488 of file DataFormatter.hh.

◆ m_index_rules

IndexContainer CASM::BaseDatumFormatter< DataObject >::m_index_rules
mutableprivateinherited

Definition at line 487 of file DataFormatter.hh.

◆ m_name

std::string CASM::BaseDatumFormatter< DataObject >::m_name
privateinherited

{ return notstd::make_unique<DerivedDatumFormatter>(*this);}

Definition at line 485 of file DataFormatter.hh.

◆ m_validate

template<typename ValueType , typename DataObject >
Validator CASM::GenericDatumFormatter< ValueType, DataObject >::m_validate
private

Definition at line 920 of file DataFormatterTools.hh.


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