CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CASM::simpleformatter::DataFormatter< ObjectType > Class Template Referenceabstract

#include <SimpleFormatter.hh>

Detailed Description

template<typename ObjectType>
class CASM::simpleformatter::DataFormatter< ObjectType >

Abstract base class for a DataFormatter implementation

  • Holds a vector of Evaluator pointers (std::unique_ptr<BaseDatumEvaluator<ObjectType>>) which are used sequentially by operator()(ObjectType const &object) to evaluate and format properties of an object.
  • During the course of evaluation, any errors thrown by evaluators are caught and added to a vector of error messages. The values that could not be formatted due to the error are replaced by strings "error_$i", where "$i" is the index into the error message vector.

Example usage (with derived class jsonDataFormatter):

jsonDataFormatter<ConfigEnumData<EnumeratorType, InitialStateType>>
formatter {...options...}; formatter.push_back(
ConfigEnumIO::dof_strain());
formatter.init();
for(auto const &data : config_enum_data) {
formatter(data);
}
jsonParser result;
result["data"] = formatter.value();
result["errors"] = formatter.errors();
GenericDatumFormatter< std::string, ConfigEnumDataType > name()
GenericDatumFormatter< bool, ConfigEnumDataType > selected()

Definition at line 362 of file SimpleFormatter.hh.

Public Member Functions

 DataFormatter ()
 
virtual ~DataFormatter ()
 
virtual std::string formatter_type () const =0
 
virtual void init ()=0
 
virtual void format (std::string const &value_name, bool const &value)=0
 
virtual void format (std::string const &value_name, long const &value)=0
 
virtual void format (std::string const &value_name, double const &value)=0
 
virtual void format (std::string const &value_name, std::string const &value)=0
 
virtual void format (std::string const &value_name, Eigen::MatrixXl const &value)=0
 
virtual void format (std::string const &value_name, Eigen::MatrixXd const &value)=0
 
virtual void format (std::string const &value_name, jsonParser const &value)=0
 
virtual void operator() (ObjectType const &object)=0
 Evaluate all DatumEvaluators and format results. More...
 
std::vector< std::string > const & errors () const
 Access error messages from caught exceptions that occur during evaluation. More...
 
int insert_error (std::string what)
 

Private Attributes

std::vector< std::unique_ptr< BaseDatumEvaluator< ObjectType > > > m_evaluators
 
std::vector< std::string > m_errors
 

Constructor & Destructor Documentation

◆ DataFormatter()

template<typename ObjectType >
CASM::simpleformatter::DataFormatter< ObjectType >::DataFormatter ( )
inline

Definition at line 364 of file SimpleFormatter.hh.

◆ ~DataFormatter()

template<typename ObjectType >
virtual CASM::simpleformatter::DataFormatter< ObjectType >::~DataFormatter ( )
inlinevirtual

Definition at line 366 of file SimpleFormatter.hh.

Member Function Documentation

◆ errors()

template<typename ObjectType >
std::vector<std::string> const& CASM::simpleformatter::DataFormatter< ObjectType >::errors ( ) const

Access error messages from caught exceptions that occur during evaluation.

◆ format() [1/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
bool const &  value 
)
pure virtual

◆ format() [2/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
double const &  value 
)
pure virtual

◆ format() [3/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
Eigen::MatrixXd const &  value 
)
pure virtual

◆ format() [4/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
Eigen::MatrixXl const &  value 
)
pure virtual

◆ format() [5/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
jsonParser const &  value 
)
pure virtual

◆ format() [6/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
long const &  value 
)
pure virtual

◆ format() [7/7]

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::format ( std::string const &  value_name,
std::string const &  value 
)
pure virtual

◆ formatter_type()

template<typename ObjectType >
virtual std::string CASM::simpleformatter::DataFormatter< ObjectType >::formatter_type ( ) const
pure virtual

Return the name of the implemented formatter type (i.e. "csv", "json", "json_array", "MatrixXi", "MatrixXd", etc.)

◆ init()

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::init ( )
pure virtual

Call init after adding all DatumEvaluator and before calling operator() to do things implemented specific things like print headers, set up initial json document, etc.

◆ insert_error()

template<typename ObjectType >
int CASM::simpleformatter::DataFormatter< ObjectType >::insert_error ( std::string  what)

Insert an error string into a vector of unique error messages, return position of error message

◆ operator()()

template<typename ObjectType >
virtual void CASM::simpleformatter::DataFormatter< ObjectType >::operator() ( ObjectType const &  object)
pure virtual

Evaluate all DatumEvaluators and format results.

Member Data Documentation

◆ m_errors

template<typename ObjectType >
std::vector<std::string> CASM::simpleformatter::DataFormatter< ObjectType >::m_errors
private

Definition at line 424 of file SimpleFormatter.hh.

◆ m_evaluators

template<typename ObjectType >
std::vector<std::unique_ptr<BaseDatumEvaluator<ObjectType> > > CASM::simpleformatter::DataFormatter< ObjectType >::m_evaluators
private

Definition at line 423 of file SimpleFormatter.hh.


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