10 #ifndef DAQ_CONFIG_MANAGER_HPP
11 #define DAQ_CONFIG_MANAGER_HPP
15 #include <unordered_map>
17 #include <fmt/format.h>
18 #include <log4cplus/logger.h>
19 #include <log4cplus/loggingmacros.h>
113 Manager(C* config, log4cplus::Logger
const& logger) : m_config(config), m_logger(logger) {
125 template <
class AttrType>
137 template <
class AttrType,
class T>
143 template <
class AttrType>
155 template <
class AttrType>
156 CurrentValue<AttrType>
Get(AttrType C::*ptr)
const;
166 log4cplus::Logger m_logger;
168 std::unordered_map<void*, State> m_update;
172 template <
class AttrType>
177 void* vptr = &((*m_config).*ptr);
178 if (
auto it = m_update.find(vptr); it != m_update.end()) {
179 throw std::invalid_argument(
"Attribute already registered");
181 m_update.insert(std::make_pair(vptr,
State{m}));
185 template <
class AttrType>
190 void* vptr = &((*m_config).*ptr);
191 if (
auto it = m_update.find(vptr); it == m_update.end()) {
192 throw std::invalid_argument(
"Attribute not previously registered");
194 return CurrentValue<AttrType>{(*m_config).*ptr, it->second.origin, it->second.metadata};
199 template <
class AttrType,
class T>
201 void* vptr = &((*m_config).*ptr);
202 if (
auto it = m_update.find(vptr); it == m_update.end()) {
203 throw std::invalid_argument(
"Attribute not previously registered");
206 auto old_value = (*m_config).*ptr;
207 ((*m_config).*ptr) = value;
208 auto const& new_value = (*m_config).*ptr;
209 auto const& meta = it->second.metadata;
210 auto const& old_origin = it->second.origin;
212 if (new_origin.
origin <= it->second.origin.origin) {
214 LOG4CPLUS_INFO(m_logger,
215 fmt::format(
"Updating configuration value for <{}> from "
216 "old value {} ({}) -> new value {} ({})",
222 it->second.origin = new_origin;
226 LOG4CPLUS_DEBUG(m_logger,
227 fmt::format(
"Will _not_ update configuration value for <{}> from "
228 "old value {} (origin {}) -> new value {} (origin {}) as "
229 "current origin has higher priority",
241 #endif // DAQ_CONFIG_MANAGER_HPP