LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
fhicl::intermediate_table Class Reference

#include "intermediate_table.h"

Public Types

typedef extended_value::atom_t atom_t
 
typedef extended_value::complex_t complex_t
 
typedef extended_value::sequence_t sequence_t
 
typedef extended_value::table_t table_t
 
typedef table_t::iterator iterator
 
typedef table_t::const_iterator const_iterator
 

Public Member Functions

 intermediate_table ()
 
bool empty () const
 
bool exists (std::string const &name) const
 
void erase (std::string const &name, 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< tt::is_numeric< T >::value, bool >::type 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 &name, bool in_prolog, value_tag tag, boost::any const &value)
 
bool insert (std::string const &name, extended_value const &value)
 
bool insert (std::string const &name, extended_value &&value)
 
extended_value const & find (std::string const &name) const
 
extended_valuelocate (std::string const &name)
 
extended_valueupdate (std::string const &name)
 

Private Member Functions

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

Private Attributes

extended_value ex_val
 

Detailed Description

Definition at line 64 of file intermediate_table.h.

Member Typedef Documentation

Constructor & Destructor Documentation

intermediate_table::intermediate_table ( )

Definition at line 53 of file intermediate_table.cc.

Member Function Documentation

const_iterator intermediate_table::begin ( ) const

Definition at line 58 of file intermediate_table.cc.

References ex_val, and fhicl::extended_value::value.

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

Definition at line 72 of file intermediate_table.cc.

References ex_val, and fhicl::extended_value::value.

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

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

Definition at line 64 of file intermediate_table.cc.

References ex_val, and fhicl::extended_value::value.

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

Definition at line 183 of file intermediate_table.cc.

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

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

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

Definition at line 149 of file intermediate_table.cc.

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

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

150 {
151  std::vector<std::string> const& key = split(name);
152  extended_value const* p = &ex_val;
153  for (unsigned k = 0, sz = key.size(); k != sz; ++k) {
154  std::string const& this_key = key[k];
155  if (this_key.empty())
156  ;
157  else if (std::isdigit(this_key[0])) {
158  if (!p->is_a(SEQUENCE)) {
159  return false;
160  }
161  sequence_t const& s = boost::any_cast<sequence_t const&>(p->value);
162  unsigned i = std::atoi(this_key.c_str());
163  if (s.size() <= i) {
164  return false;
165  }
166  p = &s[i];
167  } else { /* this_key[0] is alpha or '_' */
168  if (!p->is_a(TABLE)) {
169  return false;
170  }
171  table_t const& t = boost::any_cast<table_t const&>(p->value);
172  const_iterator it = t.find(this_key);
173  if (it == t.end()) {
174  return false;
175  }
176  p = &it->second;
177  }
178  } // for
179  return true;
180 } // exists()
Float_t s
Definition: plot.C:23
iterator end()
Definition: stdmap_shims.h:177
bool is_a(value_tag t) const
fhicl::extended_value::sequence_t sequence_t
iterator find(Key const &key)
Definition: stdmap_shims.h:231
std::vector< std::string > split(std::string const &name) const
extended_value const & intermediate_table::find ( std::string const &  name) const
Exceptions
ifitem does not exist.

Definition at line 115 of file intermediate_table.cc.

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

Referenced by art::BasicPostProcessor::doProcessOptions(), art::detail::exists_outside_prolog(), fhicl::detail::it_value_get< T, typename tt::disable_if< std::is_reference< T >::value|| std::is_pointer< T >::value >::type >::operator()(), fhicl::detail::it_value_get< std::complex< U >, typename tt::disable_if< std::is_reference< std::complex< U > >::value|| std::is_pointer< std::complex< U > >::value >::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()(), and fhicl::detail::it_value_get< intermediate_table::table_t const & >::operator()().

116 {
117  std::vector<std::string> const& key = split(name);
118  extended_value const* p = &ex_val;
119  for (unsigned k = 0, sz = key.size(); k != sz; ++k) {
120  std::string const& this_key = key[k];
121  if (this_key.empty())
122  ;
123  else if (std::isdigit(this_key[0])) {
124  if (!p->is_a(SEQUENCE))
125  throw exception(cant_find, name)
126  << "-- not a sequence (at part \"" << this_key << "\")";
127  sequence_t const& s = boost::any_cast<sequence_t const&>(p->value);
128  unsigned i = std::atoi(this_key.c_str());
129  if (s.size() <= i)
130  throw exception(cant_find, name) << "(at part \"" << this_key << "\")";
131  p = &s[i];
132  } else { /* this_key[0] is alpha or '_' */
133  if (!p->is_a(TABLE))
134  throw exception(cant_find, name)
135  << "-- not a table (at part \"" << this_key << "\")";
136  table_t const& t = boost::any_cast<table_t const&>(p->value);
137  const_iterator it = t.find(this_key);
138  if (it == t.end())
139  throw exception(cant_find, name) << "(at part \"" << this_key << "\")";
140  p = &it->second;
141  }
142  } // for
143  return *p;
144 } // find()
Float_t s
Definition: plot.C:23
iterator end()
Definition: stdmap_shims.h:177
bool is_a(value_tag t) const
fhicl::extended_value::sequence_t sequence_t
iterator find(Key const &key)
Definition: stdmap_shims.h:231
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< std::string > split(std::string const &name) const
template<typename T >
T fhicl::intermediate_table::get ( std::string const &  name)
inline

Definition at line 283 of file intermediate_table.h.

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

284 {
285  static detail::it_value_get<T> getter;
286  return getter(*this, name);
287 }
bool intermediate_table::insert ( std::string const &  name,
bool  in_prolog,
value_tag  tag,
boost::any const &  value 
)

Definition at line 80 of file intermediate_table.cc.

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

84 {
85  return insert(name, extended_value(in_prolog, tag, value));
86 }
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
std::string value(boost::any const &)
bool intermediate_table::insert ( std::string const &  name,
extended_value const &  value 
)

Definition at line 89 of file intermediate_table.cc.

References pre_insert_(), and fhicl::detail::atom::value().

90 {
91  auto found_val = pre_insert_(name, value);
92  bool result = (found_val != nullptr);
93  if (result) {
94  *found_val = value;
95  }
96  return result;
97 }
extended_value * pre_insert_(std::string const &name, extended_value const &value)
std::string value(boost::any const &)
bool intermediate_table::insert ( std::string const &  name,
extended_value &&  value 
)

Definition at line 100 of file intermediate_table.cc.

References pre_insert_(), and fhicl::detail::atom::value().

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

Definition at line 373 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()().

374 {
375  extended_value* result = nullptr;
376  auto located = locate_(name);
377  if (located.second) {
378  result = located.first;
379  }
380  return result;
381 }
std::pair< extended_value *, bool > locate_(std::string const &name, bool in_prolog=false)
std::pair< extended_value *, bool > intermediate_table::locate_ ( std::string const &  name,
bool  in_prolog = false 
)
private

Definition at line 267 of file intermediate_table.cc.

References fhicl::cant_find, ex_val, fhicl::extended_value::is_a(), fhicl::NIL, fhicl::extended_value::pretty_src_info(), fhicl::PROTECT_ERROR, fhicl::PROTECT_IGNORE, fhicl::extended_value::protection, fhicl::protection_violation, s, fhicl::SEQUENCE, fhicl::extended_value::set_prolog(), split(), fhicl::TABLE, and fhicl::extended_value::value.

Referenced by locate(), pre_insert_(), and update().

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

Definition at line 244 of file intermediate_table.cc.

References shims::map< Key, T, Compare, Allocator >::end(), shims::map< Key, T, Compare, Allocator >::erase(), ex_val, shims::map< Key, T, Compare, Allocator >::find(), fhicl::extended_value::in_prolog, locate_(), fhicl::NIL, fhicl::extended_value::protection, fhicl::protection_violation, split(), and fhicl::extended_value::value.

Referenced by insert().

246 {
247  if (!value.in_prolog) {
248  table_t& t = boost::any_cast<table_t&>(ex_val.value);
249  std::vector<std::string> const& key = split(name);
250  iterator it = t.find(key[0]);
251  if (it != t.end() && it->second.in_prolog) {
252  t.erase(it);
253  }
254  }
255  auto located = locate_(name, value.in_prolog);
256  if ((!located.first->is_a(NIL)) &&
257  value.protection > located.first->protection) {
259  << '"' << name << "\" cannot be assigned with increased protection"
260  << "\n(previous definition on " << (located.first)->pretty_src_info()
261  << ")\n";
262  }
263  return located.second ? located.first : nullptr;
264 }
size_t erase(Key const &key)
Definition: stdmap_shims.h:259
std::pair< extended_value *, bool > locate_(std::string const &name, bool in_prolog=false)
iterator end()
Definition: stdmap_shims.h:177
std::string value(boost::any const &)
iterator find(Key const &key)
Definition: stdmap_shims.h:231
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< std::string > split(std::string const &name) const
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 298 of file intermediate_table.h.

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

301 {
302  return insert(name, in_prolog, STRING, detail::encode(value));
303 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
std::string value(boost::any const &)
bool fhicl::intermediate_table::put ( std::string const &  name,
bool  value,
bool  in_prolog = false 
)
inline

Definition at line 306 of file intermediate_table.h.

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

309 {
310  return insert(name, in_prolog, BOOL, detail::encode(value));
311 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
std::string value(boost::any const &)
template<typename T >
bool fhicl::intermediate_table::put ( std::string const &  name,
std::complex< T > const &  value,
bool  in_prolog = false 
)

Definition at line 315 of file intermediate_table.h.

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

318 {
319  return insert(
320  name,
321  in_prolog,
322  COMPLEX,
324 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
extended_value::complex_t complex_t
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
std::string value(boost::any const &)
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 328 of file intermediate_table.h.

References put(), putEmptySequence(), util::flags::to_string(), and fhicl::detail::atom::value().

331 {
332  bool result = putEmptySequence(name, in_prolog);
333  if (!result) {
334  return result;
335  }
336  size_t count(0);
337  for (auto const& item : value) {
338  result = result &&
339  put(name + "[" + std::to_string(count++) + "]", item, in_prolog);
340  }
341  return result;
342 }
bool putEmptySequence(std::string const &name, bool in_prolog=false)
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
template<typename T >
std::enable_if< tt::is_numeric< T >::value, bool >::type fhicl::intermediate_table::put ( std::string const &  name,
value,
bool  in_prolog = false 
)
inline

Definition at line 346 of file intermediate_table.h.

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

349 {
350  return insert(name, in_prolog, NUMBER, detail::encode(value));
351 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
std::string value(boost::any const &)
bool fhicl::intermediate_table::putEmptySequence ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 353 of file intermediate_table.h.

References insert(), and fhicl::SEQUENCE.

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

356 {
357  return insert(name, in_prolog, SEQUENCE, sequence_t());
358 }
extended_value::sequence_t sequence_t
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
bool fhicl::intermediate_table::putEmptyTable ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 360 of file intermediate_table.h.

References insert(), and fhicl::TABLE.

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

362 {
363  return insert(name, in_prolog, TABLE, table_t());
364 }
extended_value::table_t table_t
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
bool fhicl::intermediate_table::putNil ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 366 of file intermediate_table.h.

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

368 {
369  return insert(name, in_prolog, NIL, detail::encode((void*)0));
370 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &name, bool in_prolog, value_tag tag, boost::any const &value)
std::vector< std::string > intermediate_table::split ( std::string const &  name) const
private

Definition at line 322 of file intermediate_table.cc.

References shims::isSnippetMode().

Referenced by erase(), exists(), find(), locate_(), and pre_insert_().

323 {
324  std::vector<std::string> result;
325  boost::algorithm::split(
326  result,
327  name,
328  boost::algorithm::is_any_of(shims::isSnippetMode() ? "[]" : ".[]"));
329  return result;
330 }
bool isSnippetMode(bool m)
Definition: parse_shims.cc:9
fhicl::extended_value & fhicl::intermediate_table::update ( std::string const &  name)
inline
Exceptions
ifnot able to be updated.

Definition at line 384 of file intermediate_table.h.

References locate_(), and fhicl::protection_violation.

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

385 {
386  auto located = locate_(name);
387  if (!located.second) {
389  << "Requested non-modifiable item \"" << name << "\" for update.\n";
390  }
391  return *located.first;
392 }
std::pair< extended_value *, bool > locate_(std::string const &name, 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
private

Definition at line 151 of file intermediate_table.h.

Referenced by begin(), empty(), end(), erase(), exists(), find(), locate_(), and pre_insert_().


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