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
96template <typename Column>
97struct ConfigurableCCDBPath : Configurable<std::string> {
99 : Configurable<std::string>{std::string{"ccdb:"} + Column::mLabel,
100 std::string{Column::query},
101 std::string{"CCDB path for "} + Column::mLabel + " (default: " + Column::query + ")"}
102 {
103 }
104};
105
106template <typename T>
107concept is_configurable = requires(T t) {
108 requires std::same_as<std::string, decltype(t.name)>;
109 requires std::same_as<std::string, decltype(t.help)>;
110 requires std::same_as<typename std::decay_t<T>::type, decltype(t.value)>;
111};
112
114
115template <typename T>
117 requires() {
119 };
120
121template <typename T, typename... As>
122struct ProcessConfigurable : Configurable<bool, ConfigParamKind::kProcessFlag> {
123 ProcessConfigurable(void (T::*process_)(As...), std::string const& name_, bool&& value_, std::string const& help_)
124 : process{process_},
125 Configurable<bool, ConfigParamKind::kProcessFlag>(name_, std::forward<bool>(value_), help_)
126 {
127 }
128 void (T::*process)(As...);
129};
130
131template <typename T>
132concept is_process_configurable = is_configurable<T> && requires(T t) { t.process; };
133
134#define PROCESS_SWITCH(_Class_, _Name_, _Help_, _Default_) \
135 decltype(o2::framework::ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_}) do##_Name_ = o2::framework::ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_};
136#define PROCESS_SWITCH_FULL(_Class_, _Method_, _Name_, _Help_, _Default_) \
137 decltype(o2::framework::ProcessConfigurable{&_Class_ ::_Method_, #_Name_, _Default_, _Help_}) do##_Name_ = o2::framework::ProcessConfigurable{&_Class_ ::_Method_, #_Name_, _Default_, _Help_};
138
139template <typename T, ConfigParamKind K, typename IP>
140std::ostream& operator<<(std::ostream& os, Configurable<T, K, IP> const& c)
141{
142 os << c.value;
143 return os;
144}
145
161};
162
163template <typename T>
164concept is_configurable_group = std::derived_from<T, ConfigurableGroup>;
165
166} // namespace o2::framework
167#endif // O2_FRAMEWORK_CONFIGURABLE_H_
std::vector< std::shared_ptr< gandiva::Expression > > expressions
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
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::ostream & operator<<(std::ostream &s, ChannelType const &type)
Stream operators so that we can use ChannelType with Boost.Test.
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(void(T::*process_)(As...), std::string const &name_, bool &&value_, std::string const &help_)
A placeholder node for simple type configurable.