1 #ifndef fhiclcpp_coding_h 2 #define fhiclcpp_coding_h 23 #include "boost/lexical_cast.hpp" 24 #include "boost/numeric/conversion/cast.hpp" 39 #include <type_traits> 60 bool is_nil(std::any
const& val);
90 void decode(std::any
const&, std::string&);
91 void decode(std::any
const&, std::nullptr_t&);
92 void decode(std::any
const&,
bool&);
94 void decode(std::any
const&, std::uintmax_t&);
100 void decode(std::any
const&, std::intmax_t&);
109 std::enable_if_t<std::is_floating_point_v<T>>
decode(std::any
const&,
112 void decode(std::any
const&, std::complex<ldbl>&);
115 void decode(std::any
const&, std::complex<T>&);
118 void decode(std::any
const&, std::vector<T>&);
120 template <
typename U>
123 template <
typename T, std::
size_t SIZE>
125 decode(std::any
const& a, std::array<T, SIZE>& result)
130 template <
typename KEY,
typename VALUE>
132 decode(std::any
const& a, std::pair<KEY, VALUE>& result)
137 template <
typename... ARGS>
139 decode(std::any
const& a, std::tuple<ARGS...>& result)
144 template <
unsigned SIZE,
typename TUPLE>
149 template <
typename TUPLE>
166 return encode(uintmax_t(value));
173 return encode(intmax_t(value));
187 return '(' +
encode(value.real()) +
',' +
encode(value.imag()) +
')';
195 for (
auto const&
e : value) {
196 result.emplace_back(
encode(
e));
205 return boost::lexical_cast<std::string>(
value);
218 result = boost::numeric_cast<T>(via);
229 result = boost::numeric_cast<T>(via);
235 std::enable_if_t<std::is_floating_point_v<T>>
249 std::complex<ldbl> via;
251 result = {boost::numeric_cast<T>(via.real()),
252 boost::numeric_cast<T>(via.imag())};
261 if (a.type() ==
typeid(std::string)) {
266 std::string unparsed;
269 << str <<
"\nat or before:\n" 275 for (
auto const&
e : seq) {
277 result.push_back(via);
285 for (
auto const&
e : seq) {
287 result.push_back(via);
299 template <
typename TUPLE,
size_t I>
303 std::tuple_element_t<I, TUPLE> result_elem;
304 decode(vec.at(I), result_elem);
308 template <
typename TUPLE,
size_t... I>
312 std::index_sequence<I...>)
314 ((std::get<I>(result) = decode_entry<TUPLE, I>(vec)), ...);
319 template <
typename U>
325 constexpr std::size_t TUPLE_SIZE = std::tuple_size_v<U>;
327 if (seq.size() != TUPLE_SIZE) {
328 std::ostringstream errmsg;
329 errmsg <<
"Number of expected arguments (" << TUPLE_SIZE
330 <<
") does not match " 331 <<
"number of FHiCL sequence entries (" << seq.size() <<
"): [ ";
332 for (
auto ca = seq.begin(); ca != seq.cend(); ++ca) {
336 if (ca != seq.cend() - 1) {
341 throw std::length_error(errmsg.str());
353 result = std::any_cast<T>(a);
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
bool is_a(value_tag const t) const noexcept
ps_atom_t encode(std::string const &)
void decode_tuple(std::any const &, U &tuple)
void decode(std::any const &, std::string &)
auto decode_entry(ps_sequence_t const &vec)
void decode_tuple_entries(ps_sequence_t const &vec, TUPLE &result, std::index_sequence< I... >)
std::vector< std::any > ps_sequence_t
static void decode_tuple_entry(ps_sequence_t const &, TUPLE &)
std::vector< extended_value > sequence_t
bool is_nil(std::any const &val)
typename disable_if< b, T >::type disable_if_t
bool is_table(std::any const &val)
cet::coded_exception< error, detail::translate > exception
bool is_sequence(std::any const &val)