1 #ifndef CASM_DataFormatterTools_impl
2 #define CASM_DataFormatterTools_impl
11 template <
typename ValueType,
typename ArgType,
typename DataObject>
13 const std::string &_args) {
14 if (_args.size() == 0)
return true;
15 if (!m_arg_formatter.empty())
return false;
17 std::vector<std::string> format_tags, subexprs;
23 for (
Index i = 0; i < format_tags.size(); i++) {
24 std::string ttag(format_tags[i].size(),
' ');
25 std::transform(format_tags[i].cbegin(), format_tags[i].cend(), ttag.begin(),
29 if (boost::is_any_of(
"-+.0123456789")(ch)) {
30 if (std::any_of(ttag.cbegin(), ttag.cend(), boost::is_any_of(
".e"))) {
33 val = std::stod(ttag);
35 throw std::runtime_error(
"Unable to parse '" + ttag +
36 "' from subexpression " + _args +
"\n");
38 m_arg_formatter.push_back(
43 val = std::stol(ttag);
45 throw std::runtime_error(
"Unable to parse '" + ttag +
46 "' from subexpression " + _args +
"\n");
48 m_arg_formatter.push_back(
51 }
else if (ttag ==
"false")
52 m_arg_formatter.push_back(
54 else if (ttag ==
"true")
55 m_arg_formatter.push_back(
57 else if ((ch ==
'\'' || ch ==
'\"') && ch == ttag.back() &&
61 std::string((++format_tags[i].cbegin()), (--format_tags[i].cend()))));
66 *this->home().lookup(ttag);
68 m_arg_formatter.push_back(proto_format, subexprs[i]);
76 template <
typename ValueType,
typename ArgType,
typename DataObject>
78 const DataObject &_obj)
const {
79 std::stringstream t_ss;
80 m_arg_formatter.print_header(_obj, t_ss);
82 std::vector<std::string> format_tags, subexprs;
87 if (format_tags.size()) {
89 for (
Index i = 0; i < format_tags.size(); i++) {
90 t_ss << format_tags[i];
91 if (subexprs[i].size() > 0) t_ss <<
'(' << subexprs[i] <<
')';
92 if (i + 1 < format_tags.size()) t_ss <<
',';
void split_formatter_expression(const std::string &input_expr, std::vector< std::string > &tag_names, std::vector< std::string > &sub_exprs)
GenericDatumFormatter< std::string, DataObject > name()
INDEX_TYPE Index
For long integer indexing: