OptionalTableAs.h
Go to the documentation of this file.
1 #ifndef fhiclcpp_types_OptionalTableAs_h
2 #define fhiclcpp_types_OptionalTableAs_h
3 
4 #include "fhiclcpp/type_traits.h"
9 
10 #include <memory>
11 #include <string>
12 #include <utility>
13 
14 namespace fhicl {
15 
16  //==================================================================
17  // e.g. OptionalTableAs<T, Config> ====> T as created by convert(Config)
18  //
19  template <typename T, typename Config>
20  class OptionalTableAs {
21  public:
22  explicit OptionalTableAs(Name&& name);
23  explicit OptionalTableAs(Name&& name, Comment&& comment);
24  explicit OptionalTableAs(Name&& name,
25  Comment&& comment,
26  std::function<bool()> maybeUse);
27 
28  std::optional<T>
29  operator()() const
30  {
31  if (auto via = tableObj_()) {
32  return std::make_optional(convert(*via));
33  }
34  return std::nullopt;
35  }
36 
37  // Obsolete
38  bool
40  {
41  auto t = operator()();
42  if (t) {
43  result = *t;
44  }
45  return t.has_value();
46  }
47 
48  bool
49  hasValue() const
50  {
51  return tableObj_.hasValue();
52  }
53 
54  private:
56 
57  Comment
59  {
60  std::string const preface =
61  "N.B. The following table is converted to type:";
62  std::string const name =
63  " '" + cet::demangle_symbol(typeid(T).name()) + "'";
64  std::string const user_comment =
65  comment.value.empty() ? "" : "\n\n" + comment.value;
66 
67  std::ostringstream oss;
68  oss << preface << '\n' << name << user_comment;
69 
70  return Comment{oss.str().c_str()};
71  }
72  };
73 
74  //==================================================================
75  // IMPLEMENTATION
76 
77  template <typename T, typename Config>
80  {}
81 
82  template <typename T, typename Config>
85  {}
86 
87  template <typename T, typename Config>
89  Comment&& comment,
90  std::function<bool()> maybeUse)
93  maybeUse}
94  {}
95 }
96 
97 #endif /* fhiclcpp_types_OptionalTableAs_h */
98 
99 // Local variables:
100 // mode: c++
101 // End:
static QCString name
Definition: declinfo.cpp:673
static QCString result
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
Comment conversion_comment(Comment &&comment) const
int comment
OptionalTable< Config > tableObj_
OptionalTableAs(Name &&name)
def move(depos, offset)
Definition: depos.py:107
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
bool operator()(T &result) const
#define Comment
std::optional< T > operator()() const
bool hasValue() const
Definition: OptionalTable.h:62
void function(int client, int *resource, int parblock, int *test, int p)