Project
Loading...
Searching...
No Matches
Configurable.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef O2_FRAMEWORK_CONFIGURABLE_H_
12#define O2_FRAMEWORK_CONFIGURABLE_H_
14#include "Framework/Traits.h"
15#include <string>
16#include <vector>
17namespace o2::framework
18{
19namespace expressions
20{
21struct PlaceholderNode;
22}
23
24template <typename T, ConfigParamKind K>
26 ConfigurableBase(std::string const& name, T&& defaultValue, std::string const& help)
27 : name(name), value{std::forward<T>(defaultValue)}, help(help)
28 {
29 }
30 using type = T;
31 std::string name;
33 std::string help;
34 static constexpr ConfigParamKind kind = K;
35};
36
37template <typename T, ConfigParamKind K>
39 ConfigurablePolicyConst(std::string const& name, T&& defaultValue, std::string const& help)
40 : ConfigurableBase<T, K>{name, std::forward<T>(defaultValue), help}
41 {
42 }
43 operator T()
44 {
45 return this->value;
46 }
47 T const* operator->() const
48 {
49 return &this->value;
50 }
51};
52
53template <typename T, ConfigParamKind K>
55 ConfigurablePolicyMutable(std::string const& name, T&& defaultValue, std::string const& help)
56 : ConfigurableBase<T, K>{name, std::forward<T>(defaultValue), help}
57 {
58 }
59 operator T()
60 {
61 return this->value;
62 }
64 {
65 return &this->value;
66 }
67};
68
71template <typename T, ConfigParamKind K = ConfigParamKind::kGeneric, typename IP = ConfigurablePolicyConst<T, K>>
72struct Configurable : IP {
73 Configurable(std::string const& name, T&& defaultValue, std::string const& help)
74 : IP{name, std::forward<T>(defaultValue), help}
75 {
76 }
77 auto node()
78 {
79 return expressions::PlaceholderNode{*this};
80 }
81};
82
83template <typename T, ConfigParamKind K = ConfigParamKind::kGeneric>
85
86template <typename T>
87concept is_configurable = requires(T& t) {
88 typename T::type;
89 requires std::same_as<std::string, decltype(t.name)>;
90 &T::operator typename T::type;
91};
92
94
95template <typename T>
97 requires()
98{
100};
101
102template <typename R, typename T, typename... As>
103struct ProcessConfigurable : Configurable<bool, ConfigParamKind::kProcessFlag> {
104 ProcessConfigurable(R (T::*process_)(As...), std::string const& name_, bool&& value_, std::string const& help_)
105 : process{process_},
106 Configurable<bool, ConfigParamKind::kProcessFlag>(name_, std::forward<bool>(value_), help_)
107 {
108 }
110 (As...);
111};
112
113template <typename T>
114concept is_process_configurable = is_configurable<T> && requires(T& t) { t.process; };
115
116#define PROCESS_SWITCH(_Class_, _Name_, _Help_, _Default_) \
117 decltype(ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_}) do##_Name_ = ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_};
118#define PROCESS_SWITCH_FULL(_Class_, _Method_, _Name_, _Help_, _Default_) \
119 decltype(ProcessConfigurable{&_Class_ ::_Method_, #_Name_, _Default_, _Help_}) do##_Name_ = ProcessConfigurable{&_Class_ ::_Method_, #_Name_, _Default_, _Help_};
120
121template <typename T, ConfigParamKind K, typename IP>
122std::ostream& operator<<(std::ostream& os, Configurable<T, K, IP> const& c)
123{
124 os << c.value;
125 return os;
126}
127
143};
144
145template <typename T>
146concept is_configurable_group = std::derived_from<T, ConfigurableGroup>;
147
148} // namespace o2::framework
149#endif // O2_FRAMEWORK_CONFIGURABLE_H_
uint32_t c
Definition RawData.h:2
GLsizei const GLchar *const * string
Definition glcorearb.h:809
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::ostream & operator<<(std::ostream &s, ChannelType const &type)
Stream operators so that we can use ChannelType with Boost.Test.
Defining DataPointCompositeObject explicitly as copiable.
ConfigurableBase(std::string const &name, T &&defaultValue, std::string const &help)
static constexpr ConfigParamKind kind
ConfigurablePolicyConst(std::string const &name, T &&defaultValue, std::string const &help)
ConfigurablePolicyMutable(std::string const &name, T &&defaultValue, std::string const &help)
Configurable(std::string const &name, T &&defaultValue, std::string const &help)
ProcessConfigurable(R(T::*process_)(As...), std::string const &name_, bool &&value_, std::string const &help_)
A placeholder node for simple type configurable.