CASM
1.1.0
A Clusters Approach to Statistical Mechanics
|
#include <DataFormatter.hh>
Extract data from objects of 'DataObject' class.
A DataFormatter performs extraction of disparate types of data from objects of 'DataObject' class. The DataFormatter is composed of one or more 'DatumFormatters', with each DatumFormatter knowing how to access or calculate and then format a particular type of data from the 'DataObject'.
BaseDatumFormatter<DataObject> is a virtual class from which all DatumFormatters that access the particular DataObject derive.
As an example, consider a Configuration object, which has numerous attributes (name, energy, composition, etc) which can either be accessed or calculated. These attributes can be accessed or calculated and then formatted using a DataFormatter<Configuration>, which contains a number of DatumFormatter<Configuration> objects.
Example DatumFormatter<Configuration> include:
A DataFormatter<Configuration> can either be constructed explicitly with the desired set of DatumFormatter, or via a DataFormatterDictionary<Configuration> which parses a string containing descriptions of the DatumFormatter to include and optionally arguments for initializing the DatumParser. Additional DatumFormatter can also be added via 'DataFormatter::push_back' or the '<<' operator.
Explicit construction example:
Construction via DataFormatterDictionary and a string with arguments:
Calling DataFormatterDictionary::parse will for each name in the 'args' push back the DatumFormatters with the same name and then call BaseDatumFormatter::parse_args with the content inside the parentheses (empty string otherwise).
Adding additional DatumFormatter:
Once a DataFormatter has been constructed, it can be used to output formatted data from a single DataObject or a range of DataObject. The output can be sent to an output stream, a DataStream, or a jsonParser. For example:
Definition at line 168 of file DataFormatter.hh.
Classes | |
class | FormattedIteratorPair |
Implements generic formatting member functions for ranges of data objects. More... | |
class | FormattedObject |
Implements generic formatting member functions for individual data objects. More... | |
Public Types | |
typedef _DataObject | DataObject |
Public Member Functions | |
DataFormatter (int _sep=4, int _precision=12, std::string _comment="#") | |
template<typename... Args> | |
DataFormatter (const Args &... formatters) | |
bool | empty () const |
void | clear () |
template<typename IteratorType > | |
FormattedIteratorPair< IteratorType > | operator() (IteratorType begin, IteratorType end) const |
void | set_indent (int _indent) |
FormattedObject | operator() (const DataObject &data_obj) const |
bool | validate (const DataObject &_obj) const |
Returns true if _obj has valid data for all portions of query. More... | |
void | inject (const DataObject &_obj, DataStream &_stream) const |
Output selected data from DataObject to DataStream. More... | |
template<typename ValueType > | |
ValueType | evaluate_as_scalar (const DataObject &_obj) const |
Useful when formatted output can be represented as single value. More... | |
template<typename ValueType > | |
std::vector< ValueType > | evaluate_as_vector (const DataObject &_obj) const |
Useful when formatted output can be represented as std::vector. More... | |
Eigen::MatrixXd | evaluate_as_matrix (const DataObject &_obj) const |
Useful when formatted output can be represented as Eigen::MatrixXd. More... | |
template<typename ValueType , typename IteratorType > | |
std::vector< ValueType > | evaluate_as_vector (IteratorType begin, IteratorType end) const |
Useful when formatted output can be represented as std::vector. More... | |
template<typename IteratorType > | |
Eigen::MatrixXd | evaluate_as_matrix (IteratorType begin, IteratorType end) const |
Useful when formatted output can be represented as an Eigen::MatrixXd. More... | |
void | print (const DataObject &_obj, std::ostream &_stream) const |
Output data as specified by *this of the given DataObject. More... | |
jsonParser & | to_json (const DataObject &_obj, jsonParser &json) const |
jsonParser & | to_json_arrays (const DataObject &_obj, jsonParser &json) const |
void | print_header (const DataObject &_tmplt_obj, std::ostream &_stream) const |
print the header, using _tmplt_obj to inspect array sizes, etc. More... | |
std::vector< std::string > | col_header (const DataObject &_template_obj) const |
Returns all column header strings as std::vector<std::string> More... | |
void | push_back (const BaseDatumFormatter< DataObject > &new_formatter, const std::string &args) |
void | push_back (const BaseDatumFormatter< DataObject > &new_formatter) |
template<typename... Args> | |
void | push_back (const BaseDatumFormatter< DataObject > &new_formatter, const Args &... formatters) |
void | append (const DataFormatter< DataObject > &_tail) |
DataFormatter< DataObject > & | operator<< (const BaseDatumFormatter< DataObject > &new_formatter) |
void | set_header_prefix (const std::string &_prefix) |
bool | initialize (const DataObject &_tmplt) const |
template<typename ObjectType > | |
void | push_back (std::unique_ptr< BaseDatumEvaluator< ObjectType >> evaluator_ptr) |
template<typename... Args> | |
void | push_back (std::unique_ptr< BaseDatumEvaluator< ObjectType >> evaluator_ptr, Args &&...args) |
Private Attributes | |
bool | m_initialized |
std::vector< notstd::cloneable_ptr< BaseDatumFormatter< DataObject > > > | m_data_formatters |
std::vector< Index > | m_col_sep |
std::vector< Index > | m_col_width |
int | m_prec |
int | m_sep |
int | m_indent |
std::string | m_comment |
typedef _DataObject CASM::DataFormatter< _DataObject >::DataObject |
Definition at line 177 of file DataFormatter.hh.
|
inline |
Definition at line 179 of file DataFormatter.hh.
|
inline |
Definition at line 189 of file DataFormatter.hh.
|
inline |
Definition at line 290 of file DataFormatter.hh.
|
inline |
Definition at line 195 of file DataFormatter.hh.
std::vector< std::string > CASM::DataFormatter< DataObject >::col_header | ( | const DataObject & | _template_obj | ) | const |
Returns all column header strings as std::vector<std::string>
Definition at line 246 of file DataFormatter_impl.hh.
|
inline |
Definition at line 193 of file DataFormatter.hh.
Eigen::MatrixXd CASM::DataFormatter< DataObject >::evaluate_as_matrix | ( | const DataObject & | _obj | ) | const |
Useful when formatted output can be represented as Eigen::MatrixXd.
Definition at line 101 of file DataFormatter_impl.hh.
Eigen::MatrixXd CASM::DataFormatter< DataObject >::evaluate_as_matrix | ( | IteratorType | begin, |
IteratorType | end | ||
) | const |
Useful when formatted output can be represented as an Eigen::MatrixXd.
Definition at line 125 of file DataFormatter_impl.hh.
template double CASM::DataFormatter< _DataObject >::evaluate_as_scalar< double > | ( | const DataObject & | _obj | ) | const |
Useful when formatted output can be represented as single value.
Definition at line 78 of file DataFormatter_impl.hh.
std::vector< ValueType > CASM::DataFormatter< DataObject >::evaluate_as_vector | ( | const DataObject & | _obj | ) | const |
Useful when formatted output can be represented as std::vector.
Definition at line 90 of file DataFormatter_impl.hh.
std::vector< ValueType > CASM::DataFormatter< DataObject >::evaluate_as_vector | ( | IteratorType | begin, |
IteratorType | end | ||
) | const |
Useful when formatted output can be represented as std::vector.
Definition at line 113 of file DataFormatter_impl.hh.
bool CASM::DataFormatter< DataObject >::initialize | ( | const DataObject & | _tmplt | ) | const |
Definition at line 259 of file DataFormatter_impl.hh.
void CASM::DataFormatter< DataObject >::inject | ( | const DataObject & | _obj, |
DataStream & | _stream | ||
) | const |
Output selected data from DataObject to DataStream.
Definition at line 46 of file DataFormatter_impl.hh.
|
inline |
Definition at line 210 of file DataFormatter.hh.
|
inline |
Definition at line 198 of file DataFormatter.hh.
|
inline |
Definition at line 290 of file DataFormatter.hh.
void CASM::DataFormatter< DataObject >::print | ( | const DataObject & | _obj, |
std::ostream & | _stream | ||
) | const |
Output data as specified by *this of the given DataObject.
Definition at line 135 of file DataFormatter_impl.hh.
void CASM::DataFormatter< DataObject >::print_header | ( | const DataObject & | _tmplt_obj, |
std::ostream & | _stream | ||
) | const |
print the header, using _tmplt_obj to inspect array sizes, etc.
Definition at line 216 of file DataFormatter_impl.hh.
|
inline |
Definition at line 277 of file DataFormatter.hh.
|
inline |
Definition at line 284 of file DataFormatter.hh.
|
inline |
Add a particular BaseDatumFormatter to *this If the previous Formatter matches the new formatter, try to just parse the new args into it
Definition at line 261 of file DataFormatter.hh.
void CASM::DataFormatter< _DataObject >::push_back | ( | std::unique_ptr< BaseDatumEvaluator< ObjectType >> | evaluator_ptr | ) |
Push back BaseDatumEvaluator<DataObject>. Will be evaluated sequentially by operator()
.
Definition at line 512 of file SimpleFormatter.hh.
void CASM::DataFormatter< _DataObject >::push_back | ( | std::unique_ptr< BaseDatumEvaluator< ObjectType >> | evaluator_ptr, |
Args &&... | args | ||
) |
Push back BaseDatumEvaluator<DataObject>. Will be evaluated sequentially by operator()
.
Definition at line 521 of file SimpleFormatter.hh.
|
inline |
Definition at line 300 of file DataFormatter.hh.
|
inline |
Definition at line 203 of file DataFormatter.hh.
jsonParser & CASM::DataFormatter< DataObject >::to_json | ( | const DataObject & | _obj, |
jsonParser & | json | ||
) | const |
Output data as specified by *this of the given DataObject to json with format {"name1":x, "name2":x, ...}
Definition at line 178 of file DataFormatter_impl.hh.
jsonParser & CASM::DataFormatter< DataObject >::to_json_arrays | ( | const DataObject & | _obj, |
jsonParser & | json | ||
) | const |
Output data as specified by *this of the given DataObject to json with format {"name1":[..., x], "name2":[..., x], ...}
Definition at line 192 of file DataFormatter_impl.hh.
bool CASM::DataFormatter< DataObject >::validate | ( | const DataObject & | _obj | ) | const |
Returns true if _obj has valid data for all portions of query.
Definition at line 35 of file DataFormatter_impl.hh.
|
mutableprivate |
Definition at line 309 of file DataFormatter.hh.
|
mutableprivate |
Definition at line 310 of file DataFormatter.hh.
|
private |
Definition at line 318 of file DataFormatter.hh.
|
private |
Definition at line 308 of file DataFormatter.hh.
|
private |
Definition at line 316 of file DataFormatter.hh.
|
mutableprivate |
Definition at line 305 of file DataFormatter.hh.
|
private |
Definition at line 312 of file DataFormatter.hh.
|
private |
Definition at line 314 of file DataFormatter.hh.