OnixS C++ Euronext Optiq MDG Handler 1.3.3
API documentation
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
23#include <cassert>
24
26
27#ifdef ONIXS_EURONEXT_OPTIQMDG_HAS_TYPE_TRAITS
28# include <type_traits>
29#endif
30
32
33#ifdef ONIXS_EURONEXT_OPTIQMDG_HAS_TYPE_TRAITS
34
36template <bool B, class T = void>
37using EnableIf = std::enable_if<B, T>;
38
40template <typename Base, typename Derived>
41using IsBaseOf = std::is_base_of<Base, Derived>;
42
44template <class T>
45using IsSigned = std::is_signed<T>;
46
47#define CHECK_TYPE_INTEGRAL(Type) \
48 static_assert( \
49 std::is_integral<Type>::value, \
50 #Type " must be an integral type, consider adding MemberTraits" \
51 );
52#else
53
55template <bool B, class T = void>
56struct EnableIf
57{
58 typedef T type;
59};
60
62template <class T>
63struct EnableIf<false, T> {};
64
66template<typename Base, typename Derived>
67struct IsBaseOf
68{
69 enum { value = __is_base_of(Base, Derived)};
70};
71
73template<typename T>
74struct IsSigned
75{
76 enum { value = (!(static_cast<T>(-1) > static_cast<T>(0))) };
77};
78
79#define CHECK_TYPE_INTEGRAL(Type)
80
81#endif
82
84namespace details {
85
87 template <class T, class U>
88 struct IsSameSignedness
89 {
90 enum { value = (static_cast<bool>(IsSigned<T>::value) == static_cast<bool>(IsSigned<U>::value)) };
91 };
92
94 template<typename T>
95 struct HasMemberTraits
96 {
97 template<typename U> struct SFINAE {};
98 template<typename U> static char test(SFINAE<struct U::MemberTraits>*);
99 template<typename U> static int test(...);
100 enum { value = sizeof(test<T>(ONIXS_EURONEXT_OPTIQMDG_NULLPTR)) == sizeof(char) };
101 };
102
104 template<typename T>
105 struct HasValueStaticMember
106 {
107 template<typename U, typename U::Value (*)()> struct SFINAE {};
108 template<typename U> static char test(SFINAE<U, &U::value>*);
109 template<typename U> static int test(...);
110 enum { value = sizeof(test<T>(ONIXS_EURONEXT_OPTIQMDG_NULLPTR)) == sizeof(char) };
111 };
112
114 template<typename T>
115 struct HasSerializeMember
116 {
117 template<typename U, void (U::*)(void*) const ONIXS_EURONEXT_OPTIQMDG_NOTHROW> struct SFINAE {};
118 template<typename U> static char test(SFINAE<U, &U::serialize>*);
119 template<typename U> static int test(...);
120 enum { value = sizeof(test<T>(ONIXS_EURONEXT_OPTIQMDG_NULLPTR)) == sizeof(char) };
121 };
122
124 template<typename T>
125 struct HasBitsMember
126 {
127 template<typename U> struct SFINAE {};
128 template<typename U> static char test(SFINAE<typename U::Bits>*);
129 template<typename U> static int test(...);
130 enum { value = sizeof(test<T>(ONIXS_EURONEXT_OPTIQMDG_NULLPTR)) == sizeof(char) };
131 };
132}
133
135template <typename Set, typename NullValue>
136typename EnableIf<details::HasBitsMember<Set>::value, bool>::type
137operator != (NullValue null, Set set) ONIXS_EURONEXT_OPTIQMDG_NOTHROW
138{
139 ONIXS_EURONEXT_OPTIQMDG_STATIC_ASSERT((sizeof(typename Set::Bits) == sizeof(typename NullValue::Value)));
140 ONIXS_EURONEXT_OPTIQMDG_STATIC_ASSERT((details::IsSameSignedness<typename Set::Bits, typename NullValue::Value>::value));
141
142 return set.bits() != null;
143}
144
146template <class To, class From>
148inline
149typename EnableIf<details::IsSameSignedness<To, From>::value, To>::type
150 numericCast(From from) ONIXS_EURONEXT_OPTIQMDG_NOTHROW
151{
152 const To to =
153 static_cast<To>(from);
154
155 assert(static_cast<From>(to) == from);
156
157 return to;
158}
159
161template <class To, class From>
163inline
164typename EnableIf<!details::IsSameSignedness<To, From>::value, To>::type
165 numericCast(From from) ONIXS_EURONEXT_OPTIQMDG_NOTHROW
166{
167 const To to =
168 static_cast<To>(from);
169
170 assert(static_cast<From>(to) == from);
171
172 // The sign is lost during the conversion
173 assert((to > static_cast<To>(0)) == (from > static_cast<From>(0)));
174
175 return to;
176}
177
#define ONIXS_EURONEXT_OPTIQMDG_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:146
#define ONIXS_EURONEXT_OPTIQMDG_MESSAGING_NAMESPACE_END
Definition ABI.h:151
#define ONIXS_EURONEXT_OPTIQMDG_NOTHROW
Definition Compiler.h:186
#define ONIXS_EURONEXT_OPTIQMDG_NULLPTR
Definition Compiler.h:192
#define ONIXS_EURONEXT_OPTIQMDG_PURE
Definition Compiler.h:199