DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
include
ers
internal
IssueDeclarationMacro.hpp
Go to the documentation of this file.
1
#ifndef ERS_ISSUE_DECLARATION_MACRO_H
2
#define ERS_ISSUE_DECLARATION_MACRO_H
3
4
#include <boost/preprocessor/if.hpp>
5
#include <boost/preprocessor/seq.hpp>
6
#include <boost/preprocessor/tuple.hpp>
7
#include <boost/preprocessor/logical.hpp>
8
#include <boost/preprocessor/stringize.hpp>
9
#include <boost/preprocessor/comparison.hpp>
10
11
#define ERS_EMPTY
12
13
#define ERS_IS_EMPTY(x) ERS_IS_EMPTY_I(ERS_IS_EMPTY_HELPER x)
14
#define ERS_IS_EMPTY_I(contents) ERS_IS_EMPTY_II( contents() )
15
#define ERS_IS_EMPTY_II(contents) ERS_IS_EMPTY_III( contents )
16
#define ERS_IS_EMPTY_III(contents) BOOST_PP_TUPLE_ELEM( 2, 0, ( ERS_IS_EMPTY_DEF_ ## contents ) )
17
#define ERS_IS_EMPTY_HELPER() ERS_IS_EMPTY_TRUE
18
#define ERS_IS_EMPTY_DEF_ERS_IS_EMPTY_TRUE 1 ,
19
#define ERS_IS_EMPTY_DEF_ERS_IS_EMPTY_HELPER 0 ,
20
21
#define ERS_TYPE( tuple ) BOOST_PP_SEQ_HEAD(tuple)
22
#define ERS_NAME( tuple ) BOOST_PP_SEQ_TAIL(tuple)
23
24
#define ERS_ATTRIBUTE_NAME( _, __, tuple ) \
25
, ERS_NAME(tuple)
26
27
#define ERS_ATTRIBUTE_NAME_TYPE( _, __, tuple ) \
28
, ERS_TYPE(tuple) \
29
ERS_NAME(tuple)
30
31
#define ERS_ATTRIBUTE_SERIALIZATION( _, __, tuple ) \
32
set_value( BOOST_PP_STRINGIZE(ERS_NAME(tuple)), \
33
ERS_NAME(tuple) );
34
35
#define ERS_ATTRIBUTE_ACCESSORS( _, __, tuple ) \
36
ERS_TYPE(tuple) \
37
BOOST_PP_CAT( get_, ERS_NAME(tuple) ) () { \
38
ERS_TYPE(tuple) val; \
39
ers::Issue::get_value( BOOST_PP_STRINGIZE(ERS_NAME(tuple)), val ); \
40
return val; \
41
}
42
43
#define ERS_SET_MESSAGE( message ) \
44
std::ostringstream out;\
45
out << message;\
46
prepend_message( out.str() );
47
48
#define ERS_PRINT_LIST( decl, attributes ) \
49
BOOST_PP_SEQ_FOR_EACH( decl, _, attributes )
50
51
#define __ERS_DECLARE_ISSUE_BASE__( namespace_name, class_name, base_class_name, message, base_attributes, attributes ) \
52
namespace namespace_name { \
53
class class_name : public base_class_name { \
54
template <class> friend class ::ers::IssueRegistrator; \
55
protected: \
56
BOOST_PP_EXPR_IF( BOOST_PP_NOT_EQUAL( BOOST_PP_SEQ_SIZE( base_attributes attributes ), 0 ), \
57
class_name( const ers::Context & context ) : base_class_name( context ) { ; } )\
58
static std::list<std::string> _get_inheritance() { \
59
auto chain = base_class_name::_get_inheritance(); \
60
chain.push_back( get_uid() ); \
61
return chain; \
62
} \
63
public: \
64
static const char * get_uid() { return BOOST_PP_STRINGIZE( namespace_name::class_name ); } \
65
class_name( const ers::Context & context \
66
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
67
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ) ); \
68
class_name( const ers::Context & context, \
69
const std::string & msg \
70
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
71
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ) ); \
72
class_name( const ers::Context & context, \
73
const std::string & msg \
74
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
75
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ), \
76
const std::exception & cause ); \
77
class_name( const ers::Context & context \
78
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
79
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ), \
80
const std::exception & cause ); \
81
void raise() const { throw class_name(*this); } \
82
const char * get_class_name() const { return get_uid(); } \
83
virtual std::list<std::string> get_class_inheritance() const override { return _get_inheritance() ; } \
84
base_class_name * clone() const { return new namespace_name::class_name( *this ); } \
85
ERS_PRINT_LIST( ERS_ATTRIBUTE_ACCESSORS, ERS_EMPTY attributes ) \
86
}; \
87
}
88
89
#define __ERS_DEFINE_ISSUE_BASE__( INLINE, namespace_name, class_name, base_class_name, message, base_attributes, attributes ) \
90
namespace namespace_name { \
91
INLINE class_name::class_name( const ers::Context & context \
92
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
93
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ) ) \
94
: base_class_name( context ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes ) ) \
95
{ \
96
ERS_PRINT_LIST( ERS_ATTRIBUTE_SERIALIZATION, ERS_EMPTY attributes ) \
97
BOOST_PP_EXPR_IF( BOOST_PP_NOT( ERS_IS_EMPTY( ERS_EMPTY message ) ), ERS_SET_MESSAGE( ERS_EMPTY message ) )\
98
} \
99
\
100
INLINE class_name::class_name( const ers::Context & context, \
101
const std::string & msg \
102
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
103
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ) ) \
104
: base_class_name( context, msg ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes ) ) \
105
{ \
106
ERS_PRINT_LIST( ERS_ATTRIBUTE_SERIALIZATION, ERS_EMPTY attributes ) \
107
} \
108
\
109
INLINE class_name::class_name( const ers::Context & context, \
110
const std::string & msg \
111
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
112
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ), \
113
const std::exception & cause ) \
114
: base_class_name( context, msg ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes ), cause ) \
115
{ \
116
ERS_PRINT_LIST( ERS_ATTRIBUTE_SERIALIZATION, ERS_EMPTY attributes ) \
117
} \
118
INLINE class_name::class_name( const ers::Context & context \
119
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY base_attributes ) \
120
ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME_TYPE, ERS_EMPTY attributes ), \
121
const std::exception & cause ) \
122
: base_class_name( context ERS_PRINT_LIST( ERS_ATTRIBUTE_NAME, ERS_EMPTY base_attributes ), cause ) \
123
{ \
124
ERS_PRINT_LIST( ERS_ATTRIBUTE_SERIALIZATION, ERS_EMPTY attributes ) \
125
BOOST_PP_EXPR_IF( BOOST_PP_NOT( ERS_IS_EMPTY( ERS_EMPTY message ) ), ERS_SET_MESSAGE( ERS_EMPTY message ) )\
126
} \
127
} \
128
namespace { \
129
ers::IssueRegistrator<namespace_name::class_name> namespace_name##_##class_name##_instance; \
130
}
131
132
#define ERS_DECLARE_ISSUE_BASE_HPP( namespace_name, class_name, base_class_name, message, base_attributes, attributes ) \
133
__ERS_DECLARE_ISSUE_BASE__( namespace_name, class_name, base_class_name, ERS_EMPTY message, ERS_EMPTY base_attributes, ERS_EMPTY attributes )
134
135
#define ERS_DEFINE_ISSUE_BASE_CXX( namespace_name, class_name, base_class_name, message, base_attributes, attributes ) \
136
__ERS_DEFINE_ISSUE_BASE__( ERS_EMPTY, namespace_name, class_name, base_class_name, ERS_EMPTY message, ERS_EMPTY base_attributes, ERS_EMPTY attributes )
137
138
#define ERS_DECLARE_ISSUE_HPP( namespace_name, class_name, message, attributes ) \
139
ERS_DECLARE_ISSUE_BASE_HPP( namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, ERS_EMPTY attributes )
140
141
#define ERS_DEFINE_ISSUE_CXX( namespace_name, class_name, message, attributes ) \
142
ERS_DEFINE_ISSUE_BASE_CXX( namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, ERS_EMPTY attributes )
143
144
#define ERS_DECLARE_ISSUE_BASE( namespace_name, class_name, base_class_name, message, base_attributes, attributes ) \
145
__ERS_DECLARE_ISSUE_BASE__( namespace_name, class_name, base_class_name, message, base_attributes, attributes ) \
146
__ERS_DEFINE_ISSUE_BASE__( inline, namespace_name, class_name, base_class_name, message, base_attributes, attributes )
147
148
#define ERS_DECLARE_ISSUE( namespace_name, class_name, message, attributes ) \
149
__ERS_DECLARE_ISSUE_BASE__( namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, attributes ) \
150
__ERS_DEFINE_ISSUE_BASE__( inline, namespace_name, class_name, ers::Issue, ERS_EMPTY message, ERS_EMPTY, attributes )
151
152
#endif
Generated on Sat Jun 28 2025 for DUNE-DAQ by
1.12.0