LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
bitflags.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <type_traits>
12
13namespace LC::Util
14{
15 template<typename T>
17 {
18 static_assert (std::is_enum_v<T>, "The instantiating type should be a enumeration");
19
20 using St_t = std::underlying_type_t<T>;
21 St_t Storage_ = 0;
22 public:
23 BitFlags () = default;
24
25 explicit (false) BitFlags (T t)
26 : Storage_ { static_cast<St_t> (t) }
27 {
28 }
29
30 explicit operator bool () const
31 {
32 return Storage_;
33 }
34
36 {
37 Storage_ &= other.Storage_;
38 return *this;
39 }
40
42 {
43 Storage_ |= other.Storage_;
44 return *this;
45 }
46
48 {
49 left &= right;
50 return left;
51 }
52
54 {
55 left |= right;
56 return left;
57 }
58 };
59}
60
61#define DECLARE_BIT_FLAGS(F) \
62 inline LC::Util::BitFlags<F> operator& (F left, F right) \
63 { \
64 return LC::Util::BitFlags<F> { left } & right; \
65 } \
66 inline LC::Util::BitFlags<F> operator| (F left, F right) \
67 { \
68 return LC::Util::BitFlags<F> { left } | right; \
69 }
BitFlags & operator|=(BitFlags other)
Definition: bitflags.h:41
friend BitFlags operator|(BitFlags left, BitFlags right)
Definition: bitflags.h:53
BitFlags & operator&=(BitFlags other)
Definition: bitflags.h:35
friend BitFlags operator&(BitFlags left, BitFlags right)
Definition: bitflags.h:47