1 #ifndef fhiclcpp_coding_h 2 #define fhiclcpp_coding_h 23 #include "boost/any.hpp" 24 #include "boost/lexical_cast.hpp" 25 #include "boost/numeric/conversion/cast.hpp" 26 #include "cetlib_except/demangle.h" 61 bool is_nil(boost::any
const& val);
65 ps_atom_t
encode(std::string
const&);
66 ps_atom_t
encode(
char const*);
70 ps_atom_t
encode(std::uintmax_t);
74 ps_atom_t
encode(std::intmax_t);
83 ps_atom_t
encode(std::complex<T>
const&);
85 ps_sequence_t
encode(std::vector<T>
const&);
92 void decode(boost::any
const&, std::string&);
93 void decode(boost::any
const&,
void*&);
94 void decode(boost::any
const&,
bool&);
96 void decode(boost::any
const&, std::uintmax_t&);
103 void decode(boost::any
const&, std::intmax_t&);
110 void decode(boost::any
const&, ldbl&);
117 void decode(boost::any
const&, std::complex<ldbl>&);
120 void decode(boost::any
const&, std::complex<T>&);
123 void decode(boost::any
const&, std::vector<T>&);
125 template <
typename U>
128 template <
typename T, std::
size_t SIZE>
129 void decode(boost::any
const& a, std::array<T, SIZE>& result)
134 template <
typename KEY,
typename VALUE>
135 void decode(boost::any
const& a, std::pair<KEY, VALUE>& result)
140 template <
typename... ARGS>
141 void decode(boost::any
const& a, std::tuple<ARGS...>& result)
146 template <
unsigned SIZE,
typename TUPLE>
151 template <
typename TUPLE>
170 return encode(uintmax_t(value));
177 return encode(intmax_t(value));
192 return '(' +
encode(value.real()) +
',' +
encode(value.imag()) +
')';
204 result.push_back(boost::any(
encode(*it)));
213 return boost::lexical_cast<std::string>(
value);
226 result = boost::numeric_cast<T>(via);
237 result = boost::numeric_cast<T>(via);
257 std::complex<ldbl> via;
259 result = std::complex<T>(boost::numeric_cast<T>(via.real()),
260 boost::numeric_cast<T>(via.imag()));
269 if (a.type() ==
typeid(std::string)) {
277 std::string unparsed;
280 << str <<
"\nat or before:\n" 288 decode(it->to_string(), via);
289 result.push_back(via);
300 result.push_back(via);
310 template <
typename TUPLE>
316 std::tuple_element_t<0, TUPLE> result_elem;
317 decode(vec.at(0), result_elem);
318 std::get<0>(result) = result_elem;
322 template <
unsigned IENTRY,
typename TUPLE>
328 std::tuple_element_t<IENTRY, TUPLE> result_elem;
329 decode(vec.at(IENTRY), result_elem);
330 std::get<IENTRY>(result) = result_elem;
335 template <
typename U>
343 if (seq.size() != TUPLE_SIZE) {
344 std::ostringstream errmsg;
345 errmsg <<
"Number of expected arguments (" << TUPLE_SIZE
346 <<
") does not match " 347 <<
"number of FHiCL sequence entries (" << seq.size() <<
"): [ ";
348 for (
auto ca = seq.begin(); ca != seq.cend(); ++ca) {
352 if (ca != seq.cend() - 1) {
357 throw std::length_error(errmsg.str());
368 result = boost::any_cast<T>(a);
void decode(boost::any const &, std::string &)
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
ps_atom_t encode(std::string const &)
bool is_nil(boost::any const &val)
bool is_sequence(boost::any const &val)
bool is_table(boost::any const &val)
std::vector< extended_value > sequence_t
bool is_a(value_tag t) const
void decode_tuple(boost::any const &, U &tuple)
fhicl::extended_value::sequence_t sequence_t
std::enable_if<!b, T > disable_if
std::string value(boost::any const &)
cet::coded_exception< error, detail::translate > exception
std::vector< boost::any > ps_sequence_t
static void decode_tuple_entry(ps_sequence_t const &, TUPLE &)