8 #include "cetlib/container_algorithms.h" 21 using namespace fhicl;
27 using boost::any_cast;
41 std::string
const& key,
49 std::ostringstream oss;
50 oss << key <<
"[" << i++ <<
"]";
51 src_map[oss.str()] = xval.src_info;
52 fill_src_info(xval, oss.str(), src_map);
57 get_pset_via_any(boost::any
const& a)
75 result = std::string(
"@id::") + psid.to_string();
81 result.append(stringify_(*seq.begin(), compact));
82 for (
auto it = seq.cbegin(),
e = seq.cend(); ++it !=
e;) {
83 result.append(1,
',').append(stringify_(*it, compact));
86 result.append(1,
']');
89 result = str == string(9,
'\0') ?
"@nil" : str;
99 return mapping_.empty();
105 if (!id_.is_valid()) {
115 if (mapping_.empty()) {
118 auto it = mapping_.begin();
119 result.append(it->first).append(1,
':').append(
120 stringify_(it->second, compact));
121 for (
auto const e = mapping_.end(); ++it !=
e;) {
122 result.append(1,
' ').append(it->first).append(1,
':').append(
123 stringify_(it->second, compact));
132 cet::transform_all(mapping_, std::back_inserter(keys), [](
auto const& pr) {
142 for (
auto const& pr : mapping_) {
144 keys.push_back(pr.first);
163 auto it = mapping_.find(skey.name());
164 if (it == mapping_.end()) {
178 for (
auto const& table : names) {
179 if (!p->get_one_(table, tmp)) {
193 return descend_(keys.tables(), ps) ? ps.
find_one_(keys.last()) :
false;
201 auto result = srcMapping_.find(key);
202 return result != srcMapping_.cend() ? result->second :
"";
210 void*
const value{
nullptr};
217 void*
const value{
nullptr};
218 put_or_replace(key,
value);
225 check_put_local_key(std::string
const& key)
227 if (key.find(
'.') != std::string::npos) {
236 check_put_local_key(key);
237 if (!mapping_.emplace(key, value).second) {
246 check_put_local_key(key);
247 mapping_[key] =
value;
254 check_put_local_key(key);
255 auto item = mapping_.find(key);
256 if (item == mapping_.end()) {
261 auto is_non_nil_atom = [](any
const& v) {
267 <<
"can't use non-sequence to replace sequence.";
270 }
else if (is_non_nil_atom(item->second) &&
273 <<
"can't use non-atom to replace non-nil atom.";
276 item->second =
value;
284 bool const did_erase{1u == mapping_.erase(key)};
291 std::function<
bool(boost::any
const&)> func)
const 295 if (!descend_(split_keys.tables(), ps)) {
301 auto it = ps.
mapping_.find(skey.name());
308 skey.indices().cbegin(), skey.indices().cend(), a) ?
355 auto insert = [
this, &
value](
auto const& key) {
357 this->insert_(key, boost::any(
encode(value)));
358 fill_src_info(value, key, srcMapping_);
369 std::stack<ParameterSet const*> ps_stack;
372 std::function<void(std::string const&, boost::any const&)> act_on_element =
373 [&psw, &ps_stack, &act_on_element](std::string
const& key,
374 boost::any
const& a) {
375 auto const* ps = ps_stack.top();
382 for (
auto const& elem : ps->
mapping_) {
383 act_on_element(elem.first, elem.second);
390 for (
auto const& elem : any_cast<ps_sequence_t>(a)) {
392 act_on_element(new_key, elem);
402 for (
const auto& entry : mapping_) {
403 act_on_element(entry.first, entry.second);
412 return to_indented_string(0u);
418 return to_indented_string(initial_indent_level,
false);
423 bool const annotate)
const std::string stringify_(boost::any const &a, bool compact=false) const
void do_before_action(key_t const &k, any_t const &a, ParameterSet const *ps)
ps_atom_t encode(std::string const &)
void insert_or_replace_compatible_(std::string const &key, boost::any const &value)
bool is_nil(boost::any const &val)
static collection_type const & get() noexcept
Keys get_names(std::string const &key)
std::unordered_map< std::string, std::string > annot_t
bool is_sequence(boost::any const &val)
bool is_table(boost::any const &val)
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::string > get_pset_names() const
void try_insert(L l, std::string const &key)
static std::size_t max_str_size()
std::vector< extended_value > sequence_t
void insert_(std::string const &key, boost::any const &value)
std::string to_indented_string() const
fhicl::detail::ps_atom_t ps_atom_t
bool is_a(value_tag t) const
void walk(ParameterSetWalker &psw) const
void insert_or_replace_(std::string const &key, boost::any const &value)
bool has_key(std::string const &key) const
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(boost::any const &)> func) const
std::string value(boost::any const &)
bool descend_(std::vector< std::string > const &names, ParameterSet &ps) const
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
std::string get_src_info(std::string const &key) const
std::string result() const
void reset(ParameterSet const &)
std::vector< std::string > get_names() const
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
void do_enter_table(key_t const &k, any_t const &a)
std::vector< boost::any > ps_sequence_t
std::string to_string_(bool compact=false) const
bool find_an_any(cit_size_t it, cit_size_t const cend, boost::any &a)