StormByte C++ Library 0.0.9999
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
Public Member Functions | Protected Attributes | List of all members
StormByte::Bitmask< Derived, E > Class Template Reference

Bitmask class template for managing enum class flags. More...

#include <bitmask.hxx>

Collaboration diagram for StormByte::Bitmask< Derived, E >:
Collaboration graph
[legend]

Public Member Functions

constexpr Bitmask () noexcept
 Default constructor initializes the bitmask to zero.
 
constexpr Bitmask (E value) noexcept
 Constructor initializes the bitmask with a specific enum value.
 
constexpr Bitmask (const Bitmask &other) noexcept=default
 Copy constructor.
 
constexpr Bitmask (Bitmask &&other) noexcept=default
 Move constructor.
 
virtual constexpr ~Bitmask () noexcept=default
 Destructor.
 
constexpr Bitmaskoperator= (const Bitmask &other) noexcept=default
 Copy assignment operator.
 
constexpr Bitmaskoperator= (Bitmask &&other) noexcept=default
 Move assignment operator.
 
constexpr bool operator== (const Bitmask &other) const noexcept
 Equality operator.
 
constexpr bool operator!= (const Bitmask &other) const noexcept
 Inequality operator.
 
constexpr Derived operator| (const Bitmask &other) const noexcept
 Bitwise OR operator.
 
constexpr Derived operator& (const Bitmask &other) const noexcept
 Bitwise AND operator.
 
constexpr Derived operator^ (const Bitmask &other) const noexcept
 Bitwise XOR operator.
 
constexpr Derived operator~ () const noexcept
 Bitwise NOT operator.
 
constexpr Bitmaskoperator|= (const Bitmask &other) noexcept
 Bitwise OR assignment operator.
 
constexpr Bitmaskoperator&= (const Bitmask &other) noexcept
 Bitwise AND assignment operator.
 
constexpr Bitmaskoperator^= (const Bitmask &other) noexcept
 Bitwise XOR assignment operator.
 
constexpr void Add (E value) noexcept
 Add a flag to the bitmask.
 
constexpr void Remove (E value) noexcept
 Remove a flag from the bitmask.
 
constexpr E Value () const noexcept
 Get the current value of the bitmask.
 
constexpr bool Has (E value) const noexcept
 Check if the bitmask has a specific flag set.
 
constexpr bool Has (const Bitmask &other) const noexcept
 Check if the bitmask has all flags set from another bitmask.
 
constexpr bool HasAny (E value) const noexcept
 Check if any of the specified flags are set in the bitmask.
 
constexpr bool HasAny (const Bitmask &other) const noexcept
 Check if any of the flags from another bitmask are set in this bitmask.
 
constexpr bool HasNone (E value) const noexcept
 Check if none of the specified flags are set in the bitmask.
 
constexpr bool HasNone (const Bitmask &other) const noexcept
 Check if none of the flags from another bitmask are set in this bitmask.
 

Protected Attributes

m_value
 

Detailed Description

template<typename Derived, Type::UnsignedEnum E>
class StormByte::Bitmask< Derived, E >

Bitmask class template for managing enum class flags.

Template Parameters
DerivedThe derived class type.
EThe enumeration type representing the flags.

This class provides bitwise operations for enum class types, allowing easy manipulation of flag combinations.

Example usage:

enum class MyFlags : uint8_t {
FlagA = 0x01,
FlagB = 0x02,
FlagC = 0x04
};
class MyBitmask : public Bitmask<MyBitmask, MyFlags> {
public:
using Bitmask<MyBitmask, MyFlags>::Bitmask;
};
MyBitmask mask(MyFlags::FlagA);
mask |= MyBitmask(MyFlags::FlagB);
if (mask.Has(MyFlags::FlagA)) { ... }
Bitmask class template for managing enum class flags.
Definition bitmask.hxx:95

Constructor & Destructor Documentation

◆ Bitmask() [1/3]

template<typename Derived , Type::UnsignedEnum E>
constexpr StormByte::Bitmask< Derived, E >::Bitmask ( value)
inlineconstexprnoexcept

Constructor initializes the bitmask with a specific enum value.

Parameters
valueThe initial enum value for the bitmask.

◆ Bitmask() [2/3]

template<typename Derived , Type::UnsignedEnum E>
constexpr StormByte::Bitmask< Derived, E >::Bitmask ( const Bitmask< Derived, E > &  other)
constexprdefaultnoexcept

Copy constructor.

Parameters
otherThe other Bitmask to copy from.

◆ Bitmask() [3/3]

template<typename Derived , Type::UnsignedEnum E>
constexpr StormByte::Bitmask< Derived, E >::Bitmask ( Bitmask< Derived, E > &&  other)
constexprdefaultnoexcept

Move constructor.

Parameters
otherThe other Bitmask to move from.

Member Function Documentation

◆ Add()

template<typename Derived , Type::UnsignedEnum E>
constexpr void StormByte::Bitmask< Derived, E >::Add ( value)
inlineconstexprnoexcept

Add a flag to the bitmask.

Parameters
valueThe enum value to add.

◆ Has() [1/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::Has ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Check if the bitmask has all flags set from another bitmask.

Parameters
otherThe other Bitmask to check against.
Returns
True if all flags are set, false otherwise.

◆ Has() [2/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::Has ( value) const
inlineconstexprnoexcept

Check if the bitmask has a specific flag set.

Parameters
valueThe enum value to check.
Returns
True if the flag is set, false otherwise.

◆ HasAny() [1/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::HasAny ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Check if any of the flags from another bitmask are set in this bitmask.

Parameters
otherThe other Bitmask to check against.
Returns
True if any of the flags are set, false otherwise.

◆ HasAny() [2/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::HasAny ( value) const
inlineconstexprnoexcept

Check if any of the specified flags are set in the bitmask.

Parameters
valueThe enum value(s) to check.
Returns
True if any of the flags are set, false otherwise.

◆ HasNone() [1/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::HasNone ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Check if none of the flags from another bitmask are set in this bitmask.

Parameters
otherThe other Bitmask to check against.
Returns
True if none of the flags are set, false otherwise.

◆ HasNone() [2/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::HasNone ( value) const
inlineconstexprnoexcept

Check if none of the specified flags are set in the bitmask.

Parameters
valueThe enum value(s) to check.
Returns
True if none of the flags are set, false otherwise.

◆ operator!=()

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::operator!= ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Inequality operator.

Parameters
otherThe other Bitmask to compare with.
Returns
True if the bitmasks are not equal, false otherwise.

◆ operator&()

template<typename Derived , Type::UnsignedEnum E>
constexpr Derived StormByte::Bitmask< Derived, E >::operator& ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Bitwise AND operator.

Parameters
otherThe other Bitmask to combine with.
Returns
A new Bitmask representing the result of the bitwise AND operation.

◆ operator&=()

template<typename Derived , Type::UnsignedEnum E>
constexpr Bitmask & StormByte::Bitmask< Derived, E >::operator&= ( const Bitmask< Derived, E > &  other)
inlineconstexprnoexcept

Bitwise AND assignment operator.

Parameters
otherThe other Bitmask to combine with.
Returns
Reference to this Bitmask after the operation.

◆ operator=() [1/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr Bitmask & StormByte::Bitmask< Derived, E >::operator= ( Bitmask< Derived, E > &&  other)
constexprdefaultnoexcept

Move assignment operator.

Parameters
otherThe other Bitmask to move from.
Returns
Reference to this Bitmask.

◆ operator=() [2/2]

template<typename Derived , Type::UnsignedEnum E>
constexpr Bitmask & StormByte::Bitmask< Derived, E >::operator= ( const Bitmask< Derived, E > &  other)
constexprdefaultnoexcept

Copy assignment operator.

Parameters
otherThe other Bitmask to copy from.
Returns
Reference to this Bitmask.

◆ operator==()

template<typename Derived , Type::UnsignedEnum E>
constexpr bool StormByte::Bitmask< Derived, E >::operator== ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Equality operator.

Parameters
otherThe other Bitmask to compare with.
Returns
True if the bitmasks are equal, false otherwise.

◆ operator^()

template<typename Derived , Type::UnsignedEnum E>
constexpr Derived StormByte::Bitmask< Derived, E >::operator^ ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Bitwise XOR operator.

Parameters
otherThe other Bitmask to combine with.
Returns
A new Bitmask representing the result of the bitwise XOR operation.

◆ operator^=()

template<typename Derived , Type::UnsignedEnum E>
constexpr Bitmask & StormByte::Bitmask< Derived, E >::operator^= ( const Bitmask< Derived, E > &  other)
inlineconstexprnoexcept

Bitwise XOR assignment operator.

Parameters
otherThe other Bitmask to combine with.
Returns
Reference to this Bitmask after the operation.

◆ operator|()

template<typename Derived , Type::UnsignedEnum E>
constexpr Derived StormByte::Bitmask< Derived, E >::operator| ( const Bitmask< Derived, E > &  other) const
inlineconstexprnoexcept

Bitwise OR operator.

Parameters
otherThe other Bitmask to combine with.
Returns
A new Bitmask representing the result of the bitwise OR operation.

◆ operator|=()

template<typename Derived , Type::UnsignedEnum E>
constexpr Bitmask & StormByte::Bitmask< Derived, E >::operator|= ( const Bitmask< Derived, E > &  other)
inlineconstexprnoexcept

Bitwise OR assignment operator.

Parameters
otherThe other Bitmask to combine with.
Returns
Reference to this Bitmask after the operation.

◆ operator~()

template<typename Derived , Type::UnsignedEnum E>
constexpr Derived StormByte::Bitmask< Derived, E >::operator~ ( ) const
inlineconstexprnoexcept

Bitwise NOT operator.

Returns
A new Bitmask representing the result of the bitwise NOT operation.

◆ Remove()

template<typename Derived , Type::UnsignedEnum E>
constexpr void StormByte::Bitmask< Derived, E >::Remove ( value)
inlineconstexprnoexcept

Remove a flag from the bitmask.

Parameters
valueThe enum value to remove.

◆ Value()

template<typename Derived , Type::UnsignedEnum E>
constexpr E StormByte::Bitmask< Derived, E >::Value ( ) const
inlineconstexprnoexcept

Get the current value of the bitmask.

Returns
The current enum value of the bitmask.

The documentation for this class was generated from the following file: