ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
manager.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_config
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief daq::config::Manager and associated types.
9  */
10 #include <daq/config/manager.hpp>
11 
12 #include <ostream>
13 
14 namespace daq::config {
15 
16 std::ostream& operator<<(std::ostream& os, Origin origin) {
17  switch (origin) {
18  case Origin::Runtime:
19  os << "Runtime";
20  break;
22  os << "CommandLine";
23  break;
25  os << "Configuration";
26  break;
28  os << "EnvironmentVariable";
29  break;
30  case Origin::Default:
31  os << "Default";
32  break;
33  default:
34  os << "Unknown";
35  break;
36  };
37  return os;
38 }
39 
40 std::ostream& operator<<(std::ostream& os, OriginInfo const& origin) {
41  os << "origin: " << origin.origin << ", details: " << origin.description;
42  return os;
43 }
44 
45 std::optional<std::reference_wrapper<elt::configng::CiiConfigInstanceNode const>>
46 GetParam(std::string const& query, elt::configng::CiiConfigInstanceNode const& node) {
47  if (query.empty()) {
48  // A search in the form `/node/` was made which has a trailing slash
49  return {};
50  }
51  auto pos = query.find('/');
52  if (pos == std::string::npos) {
53  // last node
54  if (node.Has(query)) {
55  return std::cref(node[query]);
56  }
57  return {};
58  }
59  auto next = query.substr(0, pos);
60  auto next_query = query.substr(pos + 1, std::string::npos);
61  if (!node.Has(next)) {
62  return {};
63  }
64  return GetParam(next_query, node[next]);
65 }
66 
67 } // namespace daq::config
daq::config::Manager and associated types.
std::optional< std::reference_wrapper< elt::configng::CiiConfigInstanceNode const > > GetParam(std::string const &query, elt::configng::CiiConfigInstanceNode const &node)
Performs lookup of parameters in the form root/node/leaf relative to the provided node.
Definition: manager.cpp:46
std::string description
May include additional information like which configuration file was used.
Definition: manager.hpp:121
Origin
Configuration origins in descending priority.
Definition: manager.hpp:36
@ Configuration
Configuration file.
@ Default
Built-in default value.
@ Runtime
Runtime change via e.g.
@ CommandLine
Command line argument.
@ EnvironmentVariable
Environment variable.
std::ostream & operator<<(std::ostream &os, Origin origin)
Format Origin.
Definition: manager.cpp:16
Mutable metadata about a configuration attribute that describes where a value comes from.
Definition: manager.hpp:116