1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* This file is part of the source code of the software program
* Vampire. It is protected by applicable
* copyright laws.
*
* This source code is distributed under the licence found here
* https://vprover.github.io/license.html
* and in the source directory
*/
/**
* @file Reflection.hpp
* Defines class Reflection.
*/
#ifndef __Reflection__
#define __Reflection__
#include <initializer_list>
///@addtogroup Reflection
///@{
#define DEFAULT_CONSTRUCTORS(Class) \
Class(Class const&) = default; \
Class(Class &&) = default; \
Class& operator=(Class const&) = default; \
Class& operator=(Class &&) = default; \
#define IMPL_COMPARISONS_FROM_TUPLE(Class) \
friend bool operator==(Class const& l, Class const& r) \
{ return l.asTuple() == r.asTuple(); } \
\
friend bool operator<(Class const& l, Class const& r) \
{ return l.asTuple() < r.asTuple(); } \
\
IMPL_COMPARISONS_FROM_LESS_AND_EQUALS(Class) \
#define __IMPL_COMPARISONS_FROM_COMPARE(Class, op, ...) \
friend bool operator op(Class const& l, Class const& r) { \
switch (DefaultComparator::compare(l,r)) { \
__VA_ARGS__ return true; \
default: return false; \
} \
} \
#define IMPL_EQ_FROM_COMPARE(Class) \
friend bool operator==(Class const& l, Class const& r) \
{ return DefaultComparator::compare(l,r) == Comparison::EQUAL; } \
\
friend bool operator!=(Class const& l, Class const& r) \
{ return !(l == r); } \
#define IMPL_COMPARISONS_FROM_COMPARE(Class) \
__IMPL_COMPARISONS_FROM_COMPARE(Class, > , case GREATER: ) \
__IMPL_COMPARISONS_FROM_COMPARE(Class, < , case LESS : ) \
__IMPL_COMPARISONS_FROM_COMPARE(Class, >=, case GREATER: case EQUAL: ) \
__IMPL_COMPARISONS_FROM_COMPARE(Class, <=, case LESS : case EQUAL: ) \
#define IMPL_COMPARISONS_FROM_LESS_AND_EQUALS(Class) \
friend bool operator> (Class const& l, Class const& r) { return r < l; } \
friend bool operator<=(Class const& l, Class const& r) { return l == r || l < r; } \
friend bool operator>=(Class const& l, Class const& r) { return l == r || l > r; } \
friend bool operator!=(Class const& l, Class const& r) { return !(l == r); } \
#define IMPL_HASH_FROM_TUPLE(Class) \
unsigned defaultHash() const { return DefaultHash::hash(asTuple()); } \
unsigned defaultHash2() const { return DefaultHash2::hash(asTuple()); } \
//The obvious way to define this macro would be
//#define DECL_ELEMENT_TYPE(T) typedef T _ElementType
//but the preprocessor understands for example
//M(std::pair<A,B>)
//as an instantiation of macro M with two arguments --
//pair<A is first and B> second.
/**
* Declare type returned by an iterator
*
* To be used inside a public block of a class declaration
*
* There is no need to use this macro in a descendant of the
* @b IteratorCore class, as this class already contains this
* declaration.
*
* Although the macro formally takes variable number of arguments, it
* should be used only with a single argument. The variable number
* of formal arguments is to allow for the use of template types,
* such as std::pair<int,int>, since the preprocessor considers every
* comma as an argument separator.
*/
#define DECL_ELEMENT_TYPE(...) typedef __VA_ARGS__ _ElementType
/**
* Type of elements in the iterator/collection @b __VA_ARGS__
* This functions is variadic as the argument might be generic, hence contain commas
*
* The class @b __VA_ARGS__ must have its element type declared by the
* @b DECL_ELEMENT_TYPE macro in order for this macro to be applicable
* (Except for cases that are handled by a partial specialization
* of the @b Lib::ElementTypeInfo template class.)
*
* @see DECL_ELEMENT_TYPE, Lib::ElementTypeInfo
*/
#define ELEMENT_TYPE(...) typename Lib::ElementTypeInfo<__VA_ARGS__>::Type
/**
* Type of elements of the current class
*
* The current class must have its element type declared by the
* @b DECL_ELEMENT_TYPE macro in order for this macro to be applicable
*
* @see DECL_ELEMENT_TYPE
*/
#define OWN_ELEMENT_TYPE _ElementType
/**
* Declare the iterator type for a container class
*
* To be used inside a public block of declaration of a container class.
*
* An iterator type is a class with a constructor that takes (a reference
* to) an instance of the container class, and then provides functions
* @b hasNext() and @b next() to iterate through elements of the
* container.
*
* Although the macro formally takes variable number of arguments, it
* should be used only with a single argument. The variable number
* of formal arguments is to allow for the use of template types,
* such as std::pair<int,int>, since the preprocessor considers every
* comma as an argument separator.
*/
#define DECL_ITERATOR_TYPE(...) typedef __VA_ARGS__ _IteratorType
/**
* Return iterator type of the container class @b Cl
*
* An iterator type is a class with a constructor that takes (a reference
* to) an instance of the container class, and then provides functions
* @b hasNext() and @b next() to iterate through elements of the
* container.
*
* The class @b Cl must have its iterator type declared by the
* @b DECL_ITERATOR_TYPE macro in order for this macro to be applicable.
* (Except for cases that are handled by a partial specialization
* of the @b Lib::IteratorTypeInfo template class.)
*
* @see DECL_ITERATOR_TYPE, Lib::IteratorTypeInfo
*/
#define ITERATOR_TYPE(Cl) typename Lib::IteratorTypeInfo<Cl>::Type
/**
* Iterator type of the current container class
*
* An iterator type is a class with a constructor that takes (a reference
* to) an instance of the container class, and then provides functions
* @b hasNext() and @b next() to iterate through elements of the
* container.
*
* The current class must have its iterator type declared by the
* @b DECL_ITERATOR_TYPE macro in order for this macro to be applicable
*
* @see DECL_ITERATOR_TYPE
*/
#define OWN_ITERATOR_TYPE _IteratorType
namespace Lib {
/**
* A helper class that is used by the @b ELEMENT_TYPE macro to obtain
* element types in iterator and container types
*
* The default implementation uses the @b _ElementType typedef which
* is being declared by the @b DECL_ELEMENT_TYPE macro inside a class.
*
* If the use of the @b DECL_ELEMENT_TYPE macro is not suitable for some
* type, the same effect can be achieved by a partial specialization of
* this class that contains a typedef of the appropriate element type
* to a new type @b Type. An example of this can be @b ElementTypeInfo<T[]>
* which is this kin of specialisation for arrays.
*
* @see ELEMENT_TYPE, DECL_ELEMENT_TYPE
*/
template<typename T>
struct ElementTypeInfo
{
typedef typename T::_ElementType Type;
};
/**
* ElementTypeInfo for arrays.
*
* @see ElementTypeInfo
*/
template<typename T>
struct ElementTypeInfo<T[]>
{
typedef T Type;
};
/**
* ElementTypeInfo for pointers
*
* @see ElementTypeInfo
*/
template<typename T>
struct ElementTypeInfo<T*>
{
typedef T Type;
};
template<class C>
struct ElementTypeInfo<std::initializer_list<C>> {
using Type = C;
};
/**
* A helper class that is used by the @b ITERATOR_TYPE macro to obtain
* iterator types for container classes
*
* The default implementation uses the @b _IteratorType typedef which
* is being declared by the @b DECL_ITERATOR_TYPE macro inside a class.
*
* If the use of the @b DECL_ITERATOR_TYPE macro is not suitable for some
* type, the same effect can be achieved by a partial specialization of
* this class that contains a typedef of the appropriate element type
* to a new type @b Type. An example of this can be @b IteratorTypeInfo<List<T>*>
* in the List.hpp file which is this kind of specialisation for lists.
*
* @see ITERATOR_TYPE, DECL_ITERATOR_TYPE
*/
template<typename T>
struct IteratorTypeInfo
{
typedef typename T::_IteratorType Type;
};
/**
* IteratorTypeInfo for const types
*
* @see IteratorTypeInfo
*/
template<typename T>
struct IteratorTypeInfo<T const>
{
typedef typename IteratorTypeInfo<T>::Type Type;
};
};
///@}�
#endif /* __Reflection__ */