Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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, boolput (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 *, boollocate_ (std::string const &key, bool in_prolog=false)
 

Static Private Member Functions

static std::vector< std::stringsplit (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

Definition at line 110 of file intermediate_table.h.

Definition at line 111 of file intermediate_table.h.

Definition at line 115 of file intermediate_table.h.

Definition at line 114 of file intermediate_table.h.

Definition at line 112 of file intermediate_table.h.

Definition at line 113 of file intermediate_table.h.

Member Function Documentation

const_iterator intermediate_table::begin ( ) const

Definition at line 57 of file intermediate_table.cc.

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.

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

Definition at line 63 of file intermediate_table.cc.

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.

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 }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
uint size() const
Definition: qcstring.h:201
def key(type, name=None)
Definition: graph.py:13
p
Definition: test.py:223
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
static std::vector< std::string > const names
Definition: FragmentType.hh:8
static QCString * s
Definition: config.cpp:1042
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.

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()
static QCString name
Definition: declinfo.cpp:673
bool is_a(value_tag const t) const noexcept
uint size() const
Definition: qcstring.h:201
def key(type, name=None)
Definition: graph.py:13
p
Definition: test.py:223
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
static QCString * s
Definition: config.cpp:1042
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.

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()
static QCString name
Definition: declinfo.cpp:673
bool is_a(value_tag const t) const noexcept
uint size() const
Definition: qcstring.h:201
def key(type, name=None)
Definition: graph.py:13
p
Definition: test.py:223
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename T >
T fhicl::intermediate_table::get ( std::string const &  name)
inline

Definition at line 274 of file intermediate_table.h.

275 {
276  static detail::it_value_get<T> getter;
277  return getter(*this, key);
278 }
def key(type, name=None)
Definition: graph.py:13
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.

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)
def key(type, name=None)
Definition: graph.py:13
bool intermediate_table::insert ( std::string const &  key,
extended_value const &  value 
)

Definition at line 88 of file intermediate_table.cc.

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 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
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.

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 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
def move(depos, offset)
Definition: depos.py: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 365 of file intermediate_table.h.

366 {
367  extended_value* result = nullptr;
368  auto located = locate_(key);
369  if (located.second) {
370  result = located.first;
371  }
372  return result;
373 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
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.

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_()
static QCString name
Definition: declinfo.cpp:673
static QCString result
bool is_a(value_tag const t) const noexcept
std::string string
Definition: nybbler.cc:12
uint size() const
Definition: qcstring.h:201
def key(type, name=None)
Definition: graph.py:13
p
Definition: test.py:223
fhicl::extended_value::sequence_t sequence_t
static std::vector< std::string > split(std::string const &key)
void set_prolog(bool new_prolog_state)
static QCString * s
Definition: config.cpp:1042
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.

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 }
def key(type, name=None)
Definition: graph.py:13
static std::vector< std::string > split(std::string const &key)
std::pair< extended_value *, bool > locate_(std::string const &key, bool in_prolog=false)
static std::vector< std::string > const names
Definition: FragmentType.hh:8
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

Definition at line 281 of file intermediate_table.h.

284 {
285  return insert(key, in_prolog, STRING, detail::encode(value));
286 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
def key(type, name=None)
Definition: graph.py:13
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.

292 {
293  return insert(key, in_prolog, STRING, detail::encode(value));
294 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
def key(type, name=None)
Definition: graph.py:13
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.

300 {
301  return insert(key, in_prolog, BOOL, detail::encode(value));
302 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
def key(type, name=None)
Definition: graph.py:13
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.

309 {
310  return insert(
311  key,
312  in_prolog,
313  COMPLEX,
315 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
extended_value::complex_t complex_t
def key(type, name=None)
Definition: graph.py:13
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.

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 }
static QCString result
bool putEmptySequence(std::string const &name, bool in_prolog=false)
def key(type, name=None)
Definition: graph.py:13
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
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.

340 {
341  return insert(key, in_prolog, NUMBER, detail::encode(value));
342 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
def key(type, name=None)
Definition: graph.py:13
bool fhicl::intermediate_table::putEmptySequence ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 344 of file intermediate_table.h.

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)
def key(type, name=None)
Definition: graph.py:13
fhicl::extended_value::sequence_t sequence_t
bool fhicl::intermediate_table::putEmptyTable ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 351 of file intermediate_table.h.

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)
def key(type, name=None)
Definition: graph.py:13
bool fhicl::intermediate_table::putNil ( std::string const &  name,
bool  in_prolog = false 
)
inline

Definition at line 358 of file intermediate_table.h.

360 {
361  return insert(key, in_prolog, NIL, detail::encode(nullptr));
362 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
bool insert(std::string const &key, bool in_prolog, value_tag tag, std::any const &value)
def key(type, name=None)
Definition: graph.py:13
std::vector< std::string > intermediate_table::split ( std::string const &  key)
staticprivate

Definition at line 310 of file intermediate_table.cc.

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)
Definition: parse_shims.cc:9
static QCString result
std::string string
Definition: nybbler.cc:12
def key(type, name=None)
Definition: graph.py:13
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
fhicl::extended_value & fhicl::intermediate_table::update ( std::string const &  key)
inline
Exceptions
ifnot able to be updated.

Definition at line 376 of file intermediate_table.h.

377 {
378  auto located = locate_(key);
379  if (!located.second) {
381  << "Requested non-modifiable item \"" << key << "\" for update.\n";
382  }
383  return *located.first;
384 }
def key(type, name=None)
Definition: graph.py:13
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: