OnixS C++ ICE Binary Order Entry Handler 1.0.0
API Documentation
Loading...
Searching...
No Matches
Bits.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 <OnixS/ICE/BOE/ABI.h>
25
26#include <type_traits>
27
29
30
31namespace details {
32 struct BitsetImplTag{};
33 std::false_type isBitsetImpl(BitsetImplTag, ...);
34}
35
37
38template <typename T, typename = void> struct isBitset : std::false_type {};
39
40template<typename T>
42<
43 T
44 , typename details::make_void<decltype(T::None)>::type
45>
46: std::integral_constant
47<
48 bool,
49 isScopedEnum<T>::value
50 && toUnderlying(T::None) == 0
51 && std::is_same<
52 decltype(isBitsetImpl(std::declval<details::BitsetImplTag>(), std::declval<cleanType<T>>()))
53 , std::true_type>::value
54>
55{};
56
57template <typename T>
58constexpr typename std::enable_if<isBitset<T>::value, T>::type
59 operator| (T lhs, T rhs) noexcept
60{
61 return static_cast<T>(toUnderlying(lhs) | toUnderlying(rhs));
62}
63
64template <typename T>
65constexpr typename std::enable_if<isBitset<T>::value, T>::type
66 operator& (T lhs, T rhs) noexcept
67{
68 return static_cast<T>(toUnderlying(lhs) & toUnderlying(rhs));
69}
70
71template <typename T>
72constexpr typename std::enable_if<isBitset<T>::value, T>::type
73operator^ (T lhs, T rhs) noexcept
74{
75 return static_cast<T>(toUnderlying(lhs) ^ toUnderlying(rhs));
76}
77
78template <typename T>
79constexpr typename std::enable_if<isBitset<T>::value, T>::type
80 operator~ (T t) noexcept
81{
82 return static_cast<T>(~toUnderlying(t));
83}
84
85template <typename T>
86constexpr typename std::enable_if<isBitset<T>::value, T&>::type
87 operator|= (T& a, T b) noexcept
88{
89 return a = (a | b);
90}
91
92template <typename T>
93constexpr typename std::enable_if<isBitset<T>::value, T&>::type
94operator^= (T& a, T b) noexcept
95{
96 return a = (a ^ b);
97}
98
99template <typename T>
100constexpr typename std::enable_if<isBitset<T>::value, T&>::type
101 operator&=(T& a, T b) noexcept
102{
103 return a = (a & b);
104}
105
106template <typename T>
107constexpr bool hasFlag(T value, T flag, typename std::enable_if<isBitset<T>::value, void*>::type = nullptr) noexcept
108{
109 return (value & flag) != T::None;
110}
111
112#define ONIXS_ICEBOE_DEFINE_SET(set) \
113 std::true_type isBitsetImpl(ONIXS_ICEBOE_MESSAGING_NAMESPACE::details::BitsetImplTag, set)
114
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:102
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_END
Definition ABI.h:106
std::false_type isBitsetImpl(BitsetImplTag,...)
constexpr std::enable_if< isBitset< T >::value, T & >::type operator&=(T &a, T b) noexcept
Definition Bits.h:101
constexpr bool hasFlag(T value, T flag, typename std::enable_if< isBitset< T >::value, void * >::type=nullptr) noexcept
Definition Bits.h:107