CASM
AClustersApproachtoStatisticalMechanics
|
#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 154 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 |
Output data as specified by *this of the given DataObject to json with format {"name1":x, "name2":x, ...}. More... | |
jsonParser & | 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], ...}. More... | |
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) |
Private Member Functions | |
void | _initialize (const DataObject &_tmplt) const |
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 160 of file DataFormatter.hh.
|
inline |
Definition at line 165 of file DataFormatter.hh.
|
inline |
Definition at line 171 of file DataFormatter.hh.
|
private |
Definition at line 269 of file DataFormatter_impl.hh.
|
inline |
Definition at line 270 of file DataFormatter.hh.
|
inline |
Definition at line 180 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 257 of file DataFormatter_impl.hh.
|
inline |
Definition at line 176 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 115 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 137 of file DataFormatter_impl.hh.
ValueType CASM::DataFormatter< DataObject >::evaluate_as_scalar | ( | const DataObject & | _obj | ) | const |
Useful when formatted output can be represented as single value.
Definition at line 94 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 105 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 126 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 62 of file DataFormatter_impl.hh.
|
inline |
Definition at line 185 of file DataFormatter.hh.
|
inline |
Definition at line 197 of file DataFormatter.hh.
|
inline |
Definition at line 276 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 146 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 229 of file DataFormatter_impl.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 243 of file DataFormatter.hh.
|
inline |
Definition at line 258 of file DataFormatter.hh.
|
inline |
Definition at line 265 of file DataFormatter.hh.
|
inline |
Definition at line 281 of file DataFormatter.hh.
|
inline |
Definition at line 189 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 190 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 203 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 49 of file DataFormatter_impl.hh.
|
mutableprivate |
Definition at line 288 of file DataFormatter.hh.
|
mutableprivate |
Definition at line 289 of file DataFormatter.hh.
|
private |
Definition at line 297 of file DataFormatter.hh.
|
private |
Definition at line 287 of file DataFormatter.hh.
|
private |
Definition at line 295 of file DataFormatter.hh.
|
mutableprivate |
Definition at line 285 of file DataFormatter.hh.
|
private |
Definition at line 291 of file DataFormatter.hh.
|
private |
Definition at line 293 of file DataFormatter.hh.