LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
SearchAllowedConfiguration.cc
Go to the documentation of this file.
2 
3 using namespace fhicl::detail;
5 
6 bool
8  std::string const& searched_for_key)
9 {
10  SearchAllowedConfiguration sac{pb, searched_for_key};
11  sac.walk_over(pb);
12  return sac.result();
13 }
14 
16  ParameterBase const& pb,
17  std::string const& searched_for_key)
18  : key_{form_absolute(pb, searched_for_key)}
19 {}
20 
21 bool
23 {
24  supportsKey_ = supportsKey_ || pb.key() == key_;
25  // If supportsKey_ is true, then a match has been found, and no
26  // extra tree-walking is required--so this function should
27  // return false. If supportsKey_ is false, then continue
28  // looking through the tree to see if another parameter
29  // matches--i.e. it should return true.
30  return !supportsKey_;
31 }
32 
33 std::string
35  std::string const& searched_for_key)
36 {
37  if (searched_for_key.empty()) {
38  throw exception{error::other, "SearchAllowedConfiguration::form_absolute"}
39  << "The specified searched-for key is empty.\n";
40  }
41 
42  auto const pt = pb.parameter_type();
43  if (!is_table(pt) && !is_sequence(pt)) {
44  throw exception{error::other, "SearchAllowedConfiguration::form_absolute"}
45  << "Attempt to search for '" << searched_for_key
46  << "' as supported by a\n"
47  << "parameter that is not a table or sequence.\n";
48  }
49 
50  // assume searched-for key is meant to be relative to the
51  // top_level_key.
52  std::string const appending_character{is_table(pt) ? "." : ""};
53  std::string absolute_key{pb.key()};
54  absolute_key += appending_character;
55  absolute_key += searched_for_key;
56  return absolute_key;
57 }
static std::string form_absolute(ParameterBase const &pb, std::string const &searched_for_key)
bool is_sequence(boost::any const &val)
Definition: coding.h:50
bool is_table(boost::any const &val)
Definition: coding.h:56
par_type parameter_type() const
Definition: ParameterBase.h:74
TMarker * pt
Definition: egs.C:25
bool before_action(ParameterBase const &pb) override
SearchAllowedConfiguration(ParameterBase const &pb, std::string const &searched_for_key)
static bool supports_key(ParameterBase const &pb, std::string const &searched_for_key)
std::string key() const
Definition: ParameterBase.h:44
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33