StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
bitmask.txx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte.
5 *
6 * StormByte is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22// Out-of-line implementation of StormByte::Bitmask, included by bitmask.hxx.
23// See bitmask.hxx for documentation of each member.
24
25namespace StormByte {
26 template<typename Derived, Type::UnsignedEnum E>
27 constexpr bool Bitmask<Derived, E>::operator==(const Bitmask& other) const noexcept {
28 return m_value == other.m_value;
29 }
30
31 template<typename Derived, Type::UnsignedEnum E>
32 constexpr bool Bitmask<Derived, E>::operator!=(const Bitmask& other) const noexcept {
33 return m_value != other.m_value;
34 }
35
36 template<typename Derived, Type::UnsignedEnum E>
37 constexpr Derived Bitmask<Derived, E>::operator|(const Bitmask& other) const noexcept {
38 return Derived(m_value | other.m_value);
39 }
40
41 template<typename Derived, Type::UnsignedEnum E>
42 constexpr Derived Bitmask<Derived, E>::operator&(const Bitmask& other) const noexcept {
43 return Derived(m_value & other.m_value);
44 }
45
46 template<typename Derived, Type::UnsignedEnum E>
47 constexpr Derived Bitmask<Derived, E>::operator^(const Bitmask& other) const noexcept {
48 return Derived(m_value ^ other.m_value);
49 }
50
51 template<typename Derived, Type::UnsignedEnum E>
52 constexpr Derived Bitmask<Derived, E>::operator~() const noexcept {
53 return Derived(~m_value);
54 }
55
56 template<typename Derived, Type::UnsignedEnum E>
57 constexpr Bitmask<Derived, E>& Bitmask<Derived, E>::operator|=(const Bitmask& other) noexcept {
58 m_value = m_value | other.m_value;
59 return *this;
60 }
61
62 template<typename Derived, Type::UnsignedEnum E>
63 constexpr Bitmask<Derived, E>& Bitmask<Derived, E>::operator&=(const Bitmask& other) noexcept {
64 m_value = m_value & other.m_value;
65 return *this;
66 }
67
68 template<typename Derived, Type::UnsignedEnum E>
69 constexpr Bitmask<Derived, E>& Bitmask<Derived, E>::operator^=(const Bitmask& other) noexcept {
70 m_value = m_value ^ other.m_value;
71 return *this;
72 }
73
74 template<typename Derived, Type::UnsignedEnum E>
75 constexpr void Bitmask<Derived, E>::Add(E value) noexcept {
76 m_value = m_value | value;
77 }
78
79 template<typename Derived, Type::UnsignedEnum E>
80 constexpr void Bitmask<Derived, E>::Remove(E value) noexcept {
81 m_value = m_value & ~value;
82 }
83
84 template<typename Derived, Type::UnsignedEnum E>
85 constexpr E Bitmask<Derived, E>::Value() const noexcept {
86 return m_value;
87 }
88
89 template<typename Derived, Type::UnsignedEnum E>
90 constexpr bool Bitmask<Derived, E>::Has(E value) const noexcept {
91 return (m_value & value) == value;
92 }
93
94 template<typename Derived, Type::UnsignedEnum E>
95 constexpr bool Bitmask<Derived, E>::Has(const Bitmask& other) const noexcept {
96 return Has(other.m_value);
97 }
98
99 template<typename Derived, Type::UnsignedEnum E>
100 constexpr bool Bitmask<Derived, E>::HasAny(E value) const noexcept {
101 return (m_value & value) != static_cast<E>(0);
102 }
103
104 template<typename Derived, Type::UnsignedEnum E>
105 constexpr bool Bitmask<Derived, E>::HasAny(const Bitmask& other) const noexcept {
106 return HasAny(other.m_value);
107 }
108
109 template<typename Derived, Type::UnsignedEnum E>
110 constexpr bool Bitmask<Derived, E>::HasNone(E value) const noexcept {
111 return (m_value & value) == static_cast<E>(0);
112 }
113
114 template<typename Derived, Type::UnsignedEnum E>
115 constexpr bool Bitmask<Derived, E>::HasNone(const Bitmask& other) const noexcept {
116 return HasNone(other.m_value);
117 }
118}