LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::intermediate_table Class Reference

#include "intermediate_table.h"

Public Types

using atom_t = extended_value::atom_t
 
using complex_t = extended_value::complex_t
 
using sequence_t = extended_value::sequence_t
 
using table_t = extended_value::table_t
 
using iterator = table_t::iterator
 
using const_iterator = table_t::const_iterator
 

Public Member Functions

bool empty () const
 
bool exists (std::string const &key) const
 
void erase (std::string const &key, bool in_prolog=false)
 
template<typename T >
get (std::string const &name)
 
bool put (std::string const &name, std::string const &value, bool in_prolog=false)
 
bool put (std::string const &name, char const *value, bool in_prolog=false)
 
bool put (std::string const &name, bool value, bool in_prolog=false)
 
template<typename T >
bool put (std::string const &name, std::complex< T > const &value, bool in_prolog=false)
 
template<typename T >
bool put (std::string const &name, std::vector< T > const &value, bool in_prolog=false)
 
template<typename T >
std::enable_if_t< tt::is_numeric< T >::value, bool > put (std::string const &name, T value, bool in_prolog=false)
 
bool putEmptySequence (std::string const &name, bool in_prolog=false)
 
bool putEmptyTable (std::string const &name, bool in_prolog=false)
 
bool putNil (std::string const &name, bool in_prolog=false)
 
const_iterator begin () const
 
const_iterator end () const
 
bool insert (std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
 
bool insert (std::string const &key, extended_value const &value)
 
bool insert (std::string const &key, extended_value &&value)
 
extended_value const & find (std::string const &key) const
 
extended_valuelocate (std::string const &key)
 
extended_valueupdate (std::string const &key)
 
template<typename T >
std::enable_if< tt::is_numeric< T >::value, bool >::type put (std::string const &key, T const value, bool const in_prolog)
 

Private Member Functions

extended_valuepre_insert_ (std::string const &key, extended_value const &value)
 
std::pair< extended_value *, bool > locate_ (std::string const &key, bool in_prolog=false)
 

Static Private Member Functions

static std::vector< std::string > split (std::string const &key)
 

Private Attributes

extended_value ex_val {false, TABLE, table_t{}}
 

Detailed Description

Definition at line 65 of file intermediate_table.h.

Member Typedef Documentation

Member Function Documentation

const_iterator intermediate_table::begin ( ) const

Definition at line 57 of file intermediate_table.cc.

References util::begin().

58 {
59  return std::any_cast<table_t const&>(ex_val.value).begin();
60 }
const_iterator begin() const
bool intermediate_table::empty ( ) const

Definition at line 71 of file intermediate_table.cc.

References util::empty().

Referenced by art::BasicOptionsHandler::doProcessOptions().

72 {
73  return std::any_cast<table_t const&>(ex_val.value).empty();
74 }
const_iterator intermediate_table::end ( void  ) const

Definition at line 63 of file intermediate_table.cc.

References util::end().

64 {
65  return std::any_cast<table_t const&>(ex_val.value).end();
66 }
const_iterator end() const
void intermediate_table::erase ( std::string const &  key,
bool  in_prolog = false 
)

Definition at line 174 of file intermediate_table.cc.

References fhicl::cant_find, shims::map< Key, T, Compare, Allocator >::find(), fhicl::protection_violation, fhicl::SEQUENCE, fhicl::TABLE, and fhicl::unimplemented.

Referenced by art::BasicOutputOptionsHandler::doCheckOptions(), art::DebugOptionsHandler::doProcessOptions(), art::FileCatalogOptionsHandler::doProcessOptions(), and art::detail::prune_config_if_enabled().

175 {
176  // A missing part of the "a.b.c.d" chain will not cause an error; it
177  // is an error for an intermediate link in the chain *not* to be a
178  // table.
179  auto p(&ex_val);
180  auto t(std::any_cast<table_t>(&p->value));
181  auto it(t->end());
182  auto const names = split(key);
183  if ((!in_prolog) &&
184  (((it = t->find(names[0])) == t->end()) || it->second.in_prolog)) {
185  return;
186  }
187  bool at_sequence(false);
188  for (auto const& name : names) {
189  if (name.empty()) {
190  } else if (std::isdigit(name[0])) {
191  if (!p->is_a(SEQUENCE))
192  throw exception(cant_find, name)
193  << "-- not a sequence (at part \"" << name << "\")";
194  auto& s = std::any_cast<sequence_t&>(p->value);
195  unsigned i = std::atoi(name.c_str());
196  if (s.size() <= i) {
197  return;
198  }
199  p = &s[i];
200  at_sequence = true;
201  } else { /* name[0] is alpha or '_' */
202  if (!p->is_a(TABLE))
203  throw exception(cant_find, name)
204  << "-- not a table (at part \"" << name << "\")";
205  at_sequence = false;
206  t = std::any_cast<table_t>(&p->value);
207  it = t->find(name);
208  if (it == t->end()) {
209  return;
210  }
211  p = &it->second;
212  auto prot = p->protection;
213  if (prot == Protection::PROTECT_ERROR) {
215  << ((name != key) ? (std::string("Part \"") + name +
216  "\" of specification to be erased\n") :
217  "")
218  << '"' << name << "\" is protected on " << p->pretty_src_info()
219  << '\n';
220  } else if (prot == Protection::PROTECT_IGNORE) {
221  return;
222  }
223  }
224  } // for
225  if (at_sequence) {
226  throw fhicl::exception(unimplemented, "erase sequence member");
227  }
228  if (it != t->end()) {
229  t->erase(it);
230  }
231 }
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
iterator find(Key const &key)
Definition: stdmap_shims.h:236
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool intermediate_table::exists ( std::string const &  key) const

Definition at line 143 of file intermediate_table.cc.

References shims::map< Key, T, Compare, Allocator >::find(), fhicl::extended_value::is_a(), fhicl::SEQUENCE, fhicl::TABLE, and fhicl::extended_value::value.

Referenced by art::ensureTable(), and art::detail::exists_outside_prolog().

144 {
145  extended_value const* p = &ex_val;
146  for (auto const& name : split(key)) {
147  if (name.empty()) {
148  } else if (std::isdigit(name[0])) {
149  if (!p->is_a(SEQUENCE)) {
150  return false;
151  }
152  auto const& s = std::any_cast<sequence_t const&>(p->value);
153  unsigned i = std::atoi(name.c_str());
154  if (s.size() <= i) {
155  return false;
156  }
157  p = &s[i];
158  } else { /* name[0] is alpha or '_' */
159  if (!p->is_a(TABLE)) {
160  return false;
161  }
162  auto const& t = std::any_cast<table_t const&>(p->value);
163  auto it = t.find(name);
164  if (it == t.end()) {
165  return false;
166  }
167  p = &it->second;
168  }
169  } // for
170  return true;
171 } // exists()
bool is_a(value_tag const t) const noexcept
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
iterator find(Key const &key)
Definition: stdmap_shims.h:236
extended_value const & intermediate_table::find ( std::string const &  key) const
Exceptions
ifitem does not exist.

Definition at line 112 of file intermediate_table.cc.

References fhicl::cant_find, shims::map< Key, T, Compare, Allocator >::find(), fhicl::extended_value::is_a(), fhicl::SEQUENCE, fhicl::TABLE, and fhicl::extended_value::value.

Referenced by art::detail::exists_outside_prolog(), fhicl::detail::it_value_get< T, typename tt::disable_if< std::is_reference_v< T >|| std::is_pointer_v< T > >::type >::operator()(), fhicl::detail::it_value_get< std::complex< U >, typename tt::disable_if< std::is_reference_v< std::complex< U > >|| std::is_pointer_v< std::complex< U > > >::type >::operator()(), fhicl::detail::it_value_get< intermediate_table::sequence_t >::operator()(), fhicl::detail::it_value_get< intermediate_table::sequence_t const & >::operator()(), fhicl::detail::it_value_get< intermediate_table::table_t >::operator()(), fhicl::detail::it_value_get< intermediate_table::table_t const & >::operator()(), art::detail::path_specs(), and art::detail::prune_config_if_enabled().

113 {
114  extended_value const* p = &ex_val;
115  for (auto const& name : split(key)) {
116  if (name.empty()) {
117  } else if (std::isdigit(name[0])) {
118  if (!p->is_a(SEQUENCE))
119  throw exception(cant_find, key)
120  << "-- not a sequence (at part \"" << name << "\")";
121  auto const& s = std::any_cast<sequence_t const&>(p->value);
122  unsigned i = std::atoi(name.c_str());
123  if (s.size() <= i)
124  throw exception(cant_find, key) << "(at part \"" << name << "\")";
125  p = &s[i];
126  } else { /* name[0] is alpha or '_' */
127  if (!p->is_a(TABLE))
128  throw exception(cant_find, key)
129  << "-- not a table (at part \"" << name << "\")";
130  auto const& t = std::any_cast<table_t const&>(p->value);
131  auto it = t.find(name);
132  if (it == t.end())
133  throw exception(cant_find, key) << "(at part \"" << name << "\")";
134  p = &it->second;
135  }
136  } // for
137  return *p;
138 } // find()
bool is_a(value_tag const t) const noexcept
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
iterator find(Key const &key)
Definition: stdmap_shims.h:236
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename T >
T fhicl::intermediate_table::get ( std::string const &  name)
inline
bool intermediate_table::insert ( std::string const &  key,
bool  in_prolog,
value_tag  tag,
std::any const &  value 
)

Definition at line 79 of file intermediate_table.cc.

Referenced by put(), putEmptySequence(), putEmptyTable(), and putNil().

83 {
84  return insert(key, extended_value(in_prolog, tag, value));
85 }
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
double value
Definition: spectrum.C:18
bool intermediate_table::insert ( std::string const &  key,
extended_value const &  value 
)

Definition at line 88 of file intermediate_table.cc.

References value.

89 {
90  auto found_val = pre_insert_(key, value);
91  bool result = (found_val != nullptr);
92  if (result) {
93  *found_val = value;
94  }
95  return result;
96 }
double value
Definition: spectrum.C:18
extended_value * pre_insert_(std::string const &key, extended_value const &value)
bool intermediate_table::insert ( std::string const &  key,
extended_value &&  value 
)

Definition at line 99 of file intermediate_table.cc.

References value.

100 {
101  auto found_val = pre_insert_(key, value);
102  bool result = (found_val != nullptr);
103  if (result) {
104  *found_val = std::move(value);
105  }
106  return result;
107 }
extended_value * pre_insert_(std::string const &key, extended_value const &value)
fhicl::extended_value * fhicl::intermediate_table::locate ( std::string const &  key)
inline
Returns
nullptr if not able to be updated.

Definition at line 366 of file intermediate_table.h.

References locate_().

Referenced by fhicl::detail::it_value_get< intermediate_table::sequence_t & >::operator()(), and fhicl::detail::it_value_get< intermediate_table::table_t & >::operator()().

367 {
368  extended_value* result = nullptr;
369  auto located = locate_(key);
370  if (located.second) {
371  result = located.first;
372  }
373  return result;
374 }
std::pair< extended_value *, bool > locate_(std::string const &key, bool in_prolog=false)
std::pair< extended_value *, bool > intermediate_table::locate_ ( std::string const &  key,
bool  in_prolog = false 
)
private

Definition at line 257 of file intermediate_table.cc.

References fhicl::cant_find, fhicl::extended_value::is_a(), fhicl::NIL, fhicl::extended_value::pretty_src_info(), fhicl::extended_value::protection, fhicl::protection_violation, fhicl::SEQUENCE, fhicl::extended_value::set_prolog(), fhicl::TABLE, and fhicl::extended_value::value.

Referenced by locate(), and update().

258 {
259  std::pair<extended_value*, bool> result(nullptr, true);
260  extended_value*& p = result.first;
261  p = &ex_val;
262  for (auto const& name : split(key)) {
263  if (name.empty()) {
264  } else if (std::isdigit(name[0])) {
265  if (p->is_a(NIL)) {
266  *p = empty_seq();
267  }
268  if (!p->is_a(SEQUENCE))
269  throw exception(cant_find, name)
270  << "-- not a sequence (at part \"" << name << "\")";
271  auto& s = std::any_cast<sequence_t&>(p->value);
272  unsigned i = std::atoi(name.c_str());
273  while (s.size() <= i) {
274  s.push_back(nil_item());
275  }
276  p->set_prolog(in_prolog);
277  p = &s[i];
278  } else { /* name[0] is alpha or '_' */
279  if (p->is_a(NIL)) {
280  *p = empty_tbl();
281  p->set_prolog(in_prolog);
282  }
283  if (!p->is_a(TABLE))
284  throw exception(cant_find, name)
285  << "-- not a table (at part \"" << name << "\")";
286  auto& t = std::any_cast<table_t&>(p->value);
287  // This will do what we need whether the key is already in the
288  // map or not.
289  p = &t.emplace(name, nil_item()).first->second;
290  p->set_prolog(in_prolog);
291  }
292 
293  auto prot = p->protection;
294  if (prot == Protection::PROTECT_ERROR) {
296  << ((name != key) ? (std::string("Part \"") + name +
297  "\" of specification to be overwritten\n") :
298  "")
299  << '"' << key << "\" is protected on " << p->pretty_src_info() << '\n';
300  } else if (prot == Protection::PROTECT_IGNORE) {
301  result.second = false;
302  // Keep going since we might need definition location
303  // information for specified item upstream.
304  }
305  } // for
306  return result;
307 } // locate_()
bool is_a(value_tag const t) const noexcept
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
void set_prolog(bool new_prolog_state)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
extended_value * intermediate_table::pre_insert_ ( std::string const &  key,
extended_value const &  value 
)
private

Definition at line 234 of file intermediate_table.cc.

References fhicl::extended_value::in_prolog, fhicl::NIL, fhicl::extended_value::protection, and fhicl::protection_violation.

236 {
237  if (!value.in_prolog) {
238  auto& t = std::any_cast<table_t&>(ex_val.value);
239  auto const names = split(key);
240  auto it = t.find(names[0]);
241  if (it != t.end() && it->second.in_prolog) {
242  t.erase(it);
243  }
244  }
245  auto located = locate_(key, value.in_prolog);
246  if ((!located.first->is_a(NIL)) &&
247  value.protection > located.first->protection) {
249  << '"' << key << "\" cannot be assigned with increased protection"
250  << "\n(previous definition on " << located.first->pretty_src_info()
251  << ")\n";
252  }
253  return located.second ? located.first : nullptr;
254 }
double value
Definition: spectrum.C:18
static std::vector< std::string > split(std::string const &key)
std::pair< extended_value *, bool > locate_(std::string const &key, bool in_prolog=false)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool fhicl::intermediate_table::put ( std::string const &  name,
std::string const &  value,
bool  in_prolog = false 
)
inline
bool fhicl::intermediate_table::put ( std::string const &  name,
char const *  value,
bool  in_prolog = false 
)
inline

Definition at line 289 of file intermediate_table.h.

References fhicl::detail::encode(), insert(), and fhicl::STRING.

292 {
293  return insert(key, in_prolog, STRING, detail::encode(value));
294 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
double value
Definition: spectrum.C:18
bool fhicl::intermediate_table::put ( std::string const &  name,
bool  value,
bool  in_prolog = false 
)
inline

Definition at line 297 of file intermediate_table.h.

References fhicl::BOOL, fhicl::detail::encode(), and insert().

300 {
301  return insert(key, in_prolog, BOOL, detail::encode(value));
302 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
double value
Definition: spectrum.C:18
template<typename T >
bool fhicl::intermediate_table::put ( std::string const &  name,
std::complex< T > const &  value,
bool  in_prolog = false 
)

Definition at line 306 of file intermediate_table.h.

References fhicl::COMPLEX, fhicl::detail::encode(), and insert().

309 {
310  return insert(
311  key,
312  in_prolog,
313  COMPLEX,
315 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
extended_value::complex_t complex_t
double value
Definition: spectrum.C:18
template<typename T >
bool fhicl::intermediate_table::put ( std::string const &  name,
std::vector< T > const &  value,
bool  in_prolog = false 
)
inline

Definition at line 319 of file intermediate_table.h.

References put(), putEmptySequence(), util::to_string(), and value.

322 {
323  bool result = putEmptySequence(key, in_prolog);
324  if (!result) {
325  return result;
326  }
327  size_t count(0);
328  for (auto const& item : value) {
329  result =
330  result && put(key + "[" + std::to_string(count++) + "]", item, in_prolog);
331  }
332  return result;
333 }
bool putEmptySequence(std::string const &name, bool in_prolog=false)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
template<typename T >
std::enable_if_t<tt::is_numeric<T>::value, bool> fhicl::intermediate_table::put ( std::string const &  name,
value,
bool  in_prolog = false 
)
template<typename T >
std::enable_if<tt::is_numeric<T>::value, bool>::type fhicl::intermediate_table::put ( std::string const &  key,
T const  value,
bool const  in_prolog 
)
inline

Definition at line 337 of file intermediate_table.h.

References fhicl::detail::encode(), insert(), and fhicl::NUMBER.

340 {
341  return insert(key, in_prolog, NUMBER, detail::encode(value));
342 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
double value
Definition: spectrum.C:18
bool fhicl::intermediate_table::putEmptySequence ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 345 of file intermediate_table.h.

References insert(), and fhicl::SEQUENCE.

Referenced by art::ProcessingOptionsHandler::doProcessOptions(), and put().

347 {
348  return insert(key, in_prolog, SEQUENCE, sequence_t{});
349 }
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
fhicl::extended_value::sequence_t sequence_t
bool fhicl::intermediate_table::putEmptyTable ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 352 of file intermediate_table.h.

References insert(), and fhicl::TABLE.

Referenced by art::DebugOptionsHandler::doProcessOptions(), and art::ensureTable().

354 {
355  return insert(key, in_prolog, TABLE, table_t{});
356 }
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
bool fhicl::intermediate_table::putNil ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 359 of file intermediate_table.h.

References fhicl::detail::encode(), insert(), and fhicl::NIL.

361 {
362  return insert(key, in_prolog, NIL, detail::encode(nullptr));
363 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
std::vector< std::string > intermediate_table::split ( std::string const &  key)
staticprivate

Definition at line 310 of file intermediate_table.cc.

References shims::isSnippetMode().

311 {
312  static std::string const splitChars{shims::isSnippetMode() ? "[]" : ".[]"};
313  std::vector<std::string> result;
314  boost::algorithm::split(result, key, boost::algorithm::is_any_of(splitChars));
315  return result;
316 }
bool isSnippetMode(bool m=false) noexcept
fhicl::extended_value & fhicl::intermediate_table::update ( std::string const &  key)
inline
Exceptions
ifnot able to be updated.

Definition at line 377 of file intermediate_table.h.

References locate_(), and fhicl::protection_violation.

378 {
379  auto located = locate_(key);
380  if (!located.second) {
382  << "Requested non-modifiable item \"" << key << "\" for update.\n";
383  }
384  return *located.first;
385 }
std::pair< extended_value *, bool > locate_(std::string const &key, bool in_prolog=false)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

extended_value fhicl::intermediate_table::ex_val {false, TABLE, table_t{}}
private

Definition at line 149 of file intermediate_table.h.


The documentation for this class was generated from the following files: