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