8 #include "cetlib/container_algorithms.h" 22 using namespace fhicl;
42 std::string
const& key,
50 std::ostringstream oss;
51 oss << key <<
"[" << i++ <<
"]";
52 src_map[oss.str()] = xval.src_info;
53 fill_src_info(xval, oss.str(), src_map);
58 get_pset_via_any(std::any
const& a)
71 for (
auto const& [key,
value] : tbl) {
87 auto const& tbl =
table_t(xval);
88 for (
auto const& [key,
value] : tbl) {
108 cet::filepath_maker& maker)
125 result = std::string(
"@id::") + psid.to_string();
131 result.append(stringify_(*seq.begin(), compact));
132 for (
auto it = seq.cbegin(),
e = seq.cend(); ++it !=
e;) {
133 result.append(1,
',').append(stringify_(*it, compact));
136 result.append(1,
']');
139 result = str == string(9,
'\0') ?
"@nil" : str;
149 return mapping_.empty();
155 if (!id_.is_valid()) {
165 if (mapping_.empty()) {
168 auto it = mapping_.begin();
169 result.append(it->first).append(1,
':').append(
170 stringify_(it->second, compact));
171 for (
auto const e = mapping_.end(); ++it !=
e;) {
172 result.append(1,
' ').append(it->first).append(1,
':').append(
173 stringify_(it->second, compact));
182 cet::transform_all(mapping_, std::back_inserter(keys), [](
auto const& pr) {
192 for (
auto const& [key,
value] : mapping_) {
213 auto it = mapping_.find(skey.name());
214 if (it == mapping_.end()) {
222 std::optional<ParameterSet>
226 return std::make_optional(*
this);
229 std::optional<ParameterSet> result;
230 for (
auto const& name : names) {
231 if (!p->find_one_(name)) {
234 if (!p->is_key_to_table(name)) {
238 if (result = p->get_one_<
ParameterSet>(name); not result) {
250 auto ps = descend_(keys.tables());
251 return ps ? ps->find_one_(keys.last()) :
false;
259 auto result = srcMapping_.find(key);
260 return result != srcMapping_.cend() ? result->second :
"";
274 put_or_replace(key,
nullptr);
281 check_put_local_key(std::string
const& key)
283 if (key.find(
'.') != std::string::npos) {
292 check_put_local_key(key);
293 if (!mapping_.emplace(key, value).second) {
302 check_put_local_key(key);
303 mapping_[key] =
value;
310 check_put_local_key(key);
311 auto item = mapping_.find(key);
312 if (item == mapping_.end()) {
317 auto is_non_nil_atom = [](any
const& v) {
323 <<
"can't use non-sequence to replace sequence.";
326 }
else if (is_non_nil_atom(item->second) &&
329 <<
"can't use non-atom to replace non-nil atom.";
332 item->second =
value;
340 bool const did_erase{1u == mapping_.erase(key)};
347 std::function<
bool(std::any
const&)> func)
const 350 auto ps = descend_(split_keys.tables());
357 auto it = ps->mapping_.find(skey.name());
358 if (it == ps->mapping_.end()) {
364 skey.indices().cbegin(), skey.indices().cend(), a) ?
411 auto insert = [
this, &
value](
auto const& key) {
413 this->insert_(key, std::any(
encode(value)));
414 fill_src_info(value, key, srcMapping_);
425 std::stack<ParameterSet const*> ps_stack;
428 std::function<void(std::string const&, std::any const&)> act_on_element =
429 [&psw, &ps_stack, &act_on_element](std::string
const& key,
431 auto const* ps = ps_stack.top();
438 for (
auto const& [nested_key, nested_a] : ps->
mapping_) {
439 act_on_element(nested_key, nested_a);
446 for (
auto const& elem : any_cast<ps_sequence_t>(a)) {
447 std::string
const new_key = key +
"["s +
std::to_string(i++) +
"]";
448 act_on_element(new_key, elem);
458 for (
auto const& [key,
value] : mapping_) {
459 act_on_element(key,
value);
468 return to_indented_string(0u);
474 return to_indented_string(initial_indent_level,
false);
479 bool const annotate)
const 518 #define _INSTANTIATE_GET(FHICL_TYPE, T) \ 519 template _DECODE_##FHICL_TYPE##_(T); \ 520 template _GET_ONE_(T); \ 522 template _GET_WITH_DEFAULT(T); \ 523 template _GET_IF_PRESENT(T)
void do_before_action(key_t const &k, any_t const &a, ParameterSet const *ps)
bool is_a(value_tag const t) const noexcept
ps_atom_t encode(std::string const &)
static ParameterSet make(intermediate_table const &tbl)
static collection_type const & get() noexcept
Keys get_names(std::string const &key)
std::unordered_map< std::string, std::string > annot_t
intermediate_table::table_t table_t
void do_enter_sequence(key_t const &k, any_t const &a)
void do_exit_table(key_t const &k, any_t const &a)
std::vector< std::any > ps_sequence_t
std::vector< std::string > get_pset_names() const
void try_insert(L l, std::string const &key)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
#define _INSTANTIATE_GET(FHICL_TYPE, T)
std::vector< extended_value > sequence_t
static constexpr std::size_t max_str_size() noexcept
std::string to_indented_string() const
fhicl::detail::ps_atom_t ps_atom_t
void insert_(std::string const &key, std::any const &value)
std::optional< ParameterSet > descend_(std::vector< std::string > const &names) const
void insert_or_replace_compatible_(std::string const &key, std::any const &value)
void walk(ParameterSetWalker &psw) const
bool has_key(std::string const &key) const
bool is_nil(std::any const &val)
bool find_an_any(std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
void do_after_action(key_t const &k)
SequenceKey get_sequence_indices(std::string const &key)
std::vector< std::string > get_all_keys() const
fhicl::detail::ps_sequence_t ps_sequence_t
ParameterSetID id() const
void do_exit_sequence(key_t const &k, any_t const &a)
std::vector< key_t > const & result()
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
std::string get_src_info(std::string const &key) const
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
std::string result() const
void reset(ParameterSet const &)
std::vector< std::string > get_names() const
std::string stringify_(std::any const &a, bool compact=false) const
bool is_table(std::any const &val)
bool erase(std::string const &key)
void do_atom(key_t const &k, any_t const &a)
bool find_one_(std::string const &key) const
void put_or_replace(std::string const &key)
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
bool is_sequence(std::any const &val)
void do_enter_table(key_t const &k, any_t const &a)
std::string to_string_(bool compact=false) const
void insert_or_replace_(std::string const &key, std::any const &value)