h5geo 0.4.0
C++17 and python API to work with geo-data (seismic, wells, maps, other in process) based on HDF5. Aimed at geoscientists and developers.
Loading...
Searching...
No Matches
h5enum_operators.h
1#ifndef H5ENUM_OPERATORS_H
2#define H5ENUM_OPERATORS_H
3
4#ifndef H5GT_USE_EIGEN
5#define H5GT_USE_EIGEN // should be defined before including h5gt
6#endif
7
8#include <type_traits>
9
10#define ENABLE_BITMASK_OPERATORS(x) \
11 template<> \
12 struct EnableBitMaskOperators<x>{ \
13 static const bool enable = true;}; \
14
15namespace h5geo
16{
17template<typename Enum>
19 static const bool enable = false;
20};
21
22template<typename Enum>
23typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
24operator |(Enum lhs, Enum rhs)
25{
26 using underlying = typename std::underlying_type<Enum>::type;
27 return static_cast<Enum> (
28 static_cast<underlying>(lhs) |
29 static_cast<underlying>(rhs)
30 );
31}
32
33template<typename Enum>
34typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
35operator &(Enum lhs, Enum rhs)
36{
37 using underlying = typename std::underlying_type<Enum>::type;
38 return static_cast<Enum> (
39 static_cast<underlying>(lhs) &
40 static_cast<underlying>(rhs)
41 );
42}
43
44template<typename Enum>
45typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
46operator ^(Enum lhs, Enum rhs)
47{
48 using underlying = typename std::underlying_type<Enum>::type;
49 return static_cast<Enum> (
50 static_cast<underlying>(lhs) ^
51 static_cast<underlying>(rhs)
52 );
53}
54
55template<typename Enum>
56typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
57operator ~(Enum rhs)
58{
59 using underlying = typename std::underlying_type<Enum>::type;
60 return static_cast<Enum> (
61 ~static_cast<underlying>(rhs)
62 );
63}
64
65template<typename Enum>
66typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
67operator |=(Enum &lhs, Enum rhs)
68{
69 using underlying = typename std::underlying_type<Enum>::type;
70 lhs = static_cast<Enum> (
71 static_cast<underlying>(lhs) |
72 static_cast<underlying>(rhs)
73 );
74 return lhs;
75}
76
77template<typename Enum>
78typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
79operator &=(Enum &lhs, Enum rhs)
80{
81 using underlying = typename std::underlying_type<Enum>::type;
82 lhs = static_cast<Enum> (
83 static_cast<underlying>(lhs) &
84 static_cast<underlying>(rhs)
85 );
86 return lhs;
87}
88
89template<typename Enum>
90typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
91operator ^=(Enum &lhs, Enum rhs)
92{
93 using underlying = typename std::underlying_type<Enum>::type;
94 lhs = static_cast<Enum> (
95 static_cast<underlying>(lhs) ^
96 static_cast<underlying>(rhs)
97 );
98 return lhs;
99}
100
101}
102
103
104#endif // H5ENUM_OPERATORS_H
Basic namespace.
Definition h5base.h:29
Definition h5enum_operators.h:18