DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
IssueDeclarationMacro.hpp
Go to the documentation of this file.
1/*
2 * DUNE DAQ modification notice:
3 * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4 * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5 * Renamed since fork: yes (from ers/internal/IssueDeclarationMacro.h to
6 * include/ers/internal/IssueDeclarationMacro.hpp).
7 *
8 * Original copyright:
9 * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
10 * Licensed under the Apache License, Version 2.0.
11 */
12
13#ifndef ERS_ISSUE_DECLARATION_MACRO_H
14#define ERS_ISSUE_DECLARATION_MACRO_H
15
16#include <boost/preprocessor/comparison.hpp>
17#include <boost/preprocessor/if.hpp>
18#include <boost/preprocessor/logical.hpp>
19#include <boost/preprocessor/seq.hpp>
20#include <boost/preprocessor/stringize.hpp>
21#include <boost/preprocessor/tuple.hpp>
22
23#define ERS_EMPTY
24
25#define ERS_IS_EMPTY(x) ERS_IS_EMPTY_I(ERS_IS_EMPTY_HELPER x)
26#define ERS_IS_EMPTY_I(contents) ERS_IS_EMPTY_II(contents())
27#define ERS_IS_EMPTY_II(contents) ERS_IS_EMPTY_III(contents)
28#define ERS_IS_EMPTY_III(contents) BOOST_PP_TUPLE_ELEM(2, 0, (ERS_IS_EMPTY_DEF_##contents))
29#define ERS_IS_EMPTY_HELPER() ERS_IS_EMPTY_TRUE
30#define ERS_IS_EMPTY_DEF_ERS_IS_EMPTY_TRUE 1,
31#define ERS_IS_EMPTY_DEF_ERS_IS_EMPTY_HELPER 0,
32
33#define ERS_TYPE(tuple) BOOST_PP_SEQ_HEAD(tuple)
34#define ERS_NAME(tuple) BOOST_PP_SEQ_TAIL(tuple)
35
36#define ERS_ATTRIBUTE_NAME(_, __, tuple) , ERS_NAME(tuple)
37
38#define ERS_ATTRIBUTE_NAME_TYPE(_, __, tuple) , ERS_TYPE(tuple) ERS_NAME(tuple)
39
40#define ERS_ATTRIBUTE_SERIALIZATION(_, __, tuple) set_value(BOOST_PP_STRINGIZE(ERS_NAME(tuple)), ERS_NAME(tuple));
41
42#define ERS_ATTRIBUTE_ACCESSORS(_, __, tuple) \
43 ERS_TYPE(tuple) \
44 BOOST_PP_CAT(get_, ERS_NAME(tuple))() \
45 { \
46 ERS_TYPE(tuple) val; \
47 ers::Issue::get_value(BOOST_PP_STRINGIZE(ERS_NAME(tuple)), val); \
48 return val; \
49 }
50
51#define ERS_SET_MESSAGE(message) \
52 std::ostringstream out; \
53 out << message; \
54 prepend_message(out.str());
55
56#define ERS_PRINT_LIST(decl, attributes) BOOST_PP_SEQ_FOR_EACH(decl, _, attributes)
57
58#define __ERS_DECLARE_ISSUE_BASE__(namespace_name, class_name, base_class_name, message, base_attributes, attributes) \
59 namespace namespace_name { \
60 class class_name : public base_class_name \
61 { \
62 template<class> \
63 friend class ::ers::IssueRegistrator; \
64 \
65 protected: \
66 BOOST_PP_EXPR_IF( \
67 BOOST_PP_NOT_EQUAL(BOOST_PP_SEQ_SIZE(base_attributes attributes), 0), \
68 class_name(const ers::Context& context) : base_class_name(context) { ; }) \
69 static std::list<std::string> _get_inheritance() \
70 { \
71 auto chain = base_class_name::_get_inheritance(); \
72 chain.push_back(get_uid()); \
73 return chain; \
74 } \
75 \
76 public: \
77 static const char* get_uid() \
78 { \
79 return BOOST_PP_STRINGIZE( namespace_name::class_name ); \
80 } \
81 class_name(const ers::Context& context ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
82 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes)); \
83 class_name(const ers::Context& context, \
84 const std::string& msg ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
85 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes)); \
86 class_name(const ers::Context& context, \
87 const std::string& msg ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
88 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes), \
89 const std::exception& cause); \
90 class_name(const ers::Context& context ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
91 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes), \
92 const std::exception& cause); \
93 void raise() const \
94 { \
95 throw class_name(*this); \
96 } \
97 const char* get_class_name() const \
98 { \
99 return get_uid(); \
100 } \
101 virtual std::list<std::string> get_class_inheritance() const override \
102 { \
103 return _get_inheritance(); \
104 } \
105 base_class_name* clone() const \
106 { \
107 return new namespace_name::class_name(*this); \
108 } \
109 ERS_PRINT_LIST(ERS_ATTRIBUTE_ACCESSORS, ERS_EMPTY attributes) \
110 }; \
111 }
112
113#define __ERS_DEFINE_ISSUE_BASE__( \
114 INLINE, namespace_name, class_name, base_class_name, message, base_attributes, attributes) \
115 namespace namespace_name { \
116 INLINE class_name::class_name(const ers::Context& context ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, \
117 ERS_EMPTY base_attributes) \
118 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes)) \
119 : base_class_name(context ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes)){ ERS_PRINT_LIST( \
120 ERS_ATTRIBUTE_SERIALIZATION, \
121 ERS_EMPTY attributes) BOOST_PP_EXPR_IF(BOOST_PP_NOT(ERS_IS_EMPTY(ERS_EMPTY message)), \
122 ERS_SET_MESSAGE(ERS_EMPTY message)) } \
123 \
124 INLINE class_name::class_name( \
125 const ers::Context& context, \
126 const std::string& msg ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
127 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes)) \
128 : base_class_name(context, msg ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes)){ ERS_PRINT_LIST( \
129 ERS_ATTRIBUTE_SERIALIZATION, \
130 ERS_EMPTY attributes) } \
131 \
132 INLINE class_name::class_name( \
133 const ers::Context& context, \
134 const std::string& msg ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
135 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes), \
136 const std::exception& cause) \
137 : base_class_name(context, \
138 msg ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes), \
139 cause){ ERS_PRINT_LIST(ERS_ATTRIBUTE_SERIALIZATION, ERS_EMPTY attributes) } INLINE \
140 class_name::class_name( \
141 const ers::Context& context ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes) \
142 ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes), \
143 const std::exception& cause) \
144 : base_class_name(context ERS_PRINT_LIST(ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes), cause) \
145 { \
146 ERS_PRINT_LIST(ERS_ATTRIBUTE_SERIALIZATION, ERS_EMPTY attributes) \
147 BOOST_PP_EXPR_IF(BOOST_PP_NOT(ERS_IS_EMPTY(ERS_EMPTY message)), ERS_SET_MESSAGE(ERS_EMPTY message)) \
148 } \
149 } \
150 namespace { \
151 ers::IssueRegistrator<namespace_name::class_name> namespace_name##_##class_name##_instance; \
152 }
153
154#define ERS_DECLARE_ISSUE_BASE_HPP(namespace_name, class_name, base_class_name, message, base_attributes, attributes) \
155 __ERS_DECLARE_ISSUE_BASE__( \
156 namespace_name, class_name, base_class_name, ERS_EMPTY message, ERS_EMPTY base_attributes, ERS_EMPTY attributes)
157
158#define ERS_DEFINE_ISSUE_BASE_CXX(namespace_name, class_name, base_class_name, message, base_attributes, attributes) \
159 __ERS_DEFINE_ISSUE_BASE__(ERS_EMPTY, \
160 namespace_name, \
161 class_name, \
162 base_class_name, \
163 ERS_EMPTY message, \
164 ERS_EMPTY base_attributes, \
165 ERS_EMPTY attributes)
166
167#define ERS_DECLARE_ISSUE_HPP(namespace_name, class_name, message, attributes) \
168 ERS_DECLARE_ISSUE_BASE_HPP(namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, ERS_EMPTY attributes)
169
170#define ERS_DEFINE_ISSUE_CXX(namespace_name, class_name, message, attributes) \
171 ERS_DEFINE_ISSUE_BASE_CXX(namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, ERS_EMPTY attributes)
172
173#define ERS_DECLARE_ISSUE_BASE(namespace_name, class_name, base_class_name, message, base_attributes, attributes) \
174 __ERS_DECLARE_ISSUE_BASE__(namespace_name, class_name, base_class_name, message, base_attributes, attributes) \
175 __ERS_DEFINE_ISSUE_BASE__(inline, namespace_name, class_name, base_class_name, message, base_attributes, attributes)
176
177#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes) \
178 __ERS_DECLARE_ISSUE_BASE__(namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, attributes) \
179 __ERS_DEFINE_ISSUE_BASE__(inline, namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, attributes)
180
181#endif