SearchAllowedConfiguration.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_detail_SearchAllowedConfiguration_h
2 #define fhiclcpp_types_detail_SearchAllowedConfiguration_h
3 
4 // ============================================================================
5 //
6 // SearchAllowedConfiguration
7 //
8 // This class provides an interface for determining if a supplied
9 // ParameterBase object supports a specified key.
10 //
11 // Implemented behavior:
12 //
13 // - All querying of allowed configurations happens through the
14 // static member function 'supports_key' (the default c'tor of
15 // SearchAllowedConfiguration is private).
16 //
17 // - The supplied key is interpreted to be relative to the
18 // ParameterBase object's key. For example, if the key of the
19 // ParameterBase object is 'table1.table2', and the user
20 // specifies:
21 //
22 // bool const result {SearchAllowedConfiguration::supports_key(pb,
23 // "atom")};
24 //
25 // then the searched-for key is "table.table2.atom".
26 //
27 // - Specifying a ParameterBase object that is not of sequence type
28 // or table type throws an exception.
29 //
30 // - Specifying an empty searched-for key throws an exception.
31 //
32 // The searching happens by using the fhicl::detail::ParameterWalker
33 // interface. With the current implementation, if a match is found,
34 // the walker continues checking for matches for the rest of the
35 // parameters of the given nesting level, without descending further.
36 // This is an inefficiency that should be optimized if the need
37 // arises. Note, however, that the only way to completely stop a tree
38 // walk with the current implementation is to throw an exception,
39 // which we do not do.
40 //
41 // ============================================================================
42 
43 #include "fhiclcpp/type_traits.h"
46 
47 #include <string>
48 
49 namespace fhicl::detail {
50 
52  : public ParameterWalker<tt::const_flavor::require_const> {
53  public:
54  static bool supports_key(ParameterBase const& pb,
55  std::string const& searched_for_key);
56 
57  private:
59  bool supportsKey_{false};
60 
62  std::string const& searched_for_key);
63 
64  bool
65  result() const noexcept
66  {
67  return supportsKey_;
68  };
69 
70  bool before_action(ParameterBase const& pb) override;
71  void
72  enter_table(TableBase const&) override
73  {}
74  void
75  enter_sequence(SequenceBase const&) override
76  {}
77  void
78  atom(AtomBase const&) override
79  {}
80  void
82  {}
83 
84  static std::string form_absolute(ParameterBase const& pb,
85  std::string const& searched_for_key);
86  };
87 }
88 
89 #endif /* fhiclcpp_types_detail_SearchAllowedConfiguration_h */
90 
91 // Local variables:
92 // mode: c++
93 // End:
static std::string form_absolute(ParameterBase const &pb, std::string const &searched_for_key)
void enter_sequence(SequenceBase const &) override
std::string string
Definition: nybbler.cc:12
bool before_action(ParameterBase const &pb) override
SearchAllowedConfiguration(ParameterBase const &pb, std::string const &searched_for_key)
void delegated_parameter(DelegateBase const &) override
static constexpr double pb
Definition: Units.h:82
static bool supports_key(ParameterBase const &pb, std::string const &searched_for_key)