Louvre  v2.13.0-1
C++ library for Wayland compositors
Public Member Functions | List of all members
LBitset< T > Class Template Reference

Compact way of storing and managing conditions or states. More...

Public Member Functions

constexpr LBitset (Flag flags=0) noexcept
 Constructor for LBitset. More...
 
constexpr void add (Flag flags) noexcept
 Add new flags to the bitfield. More...
 
constexpr void remove (Flag flags) noexcept
 Remove flags from the bitfield. More...
 
constexpr bool check (Flag flags) const noexcept
 Check if at least one flag exists. More...
 
constexpr bool checkAll (Flag flags) const noexcept
 Check if all specified flags exist. More...
 
constexpr Flag get () const noexcept
 Gets the current set of flags. More...
 
constexpr void set (Flag flags) noexcept
 Set new flags in the bitfield. More...
 
constexpr void setFlag (Flag flag, bool enable) noexcept
 Set or unset a specific flag in the bitfield. More...
 
constexpr LBitset< T > & operator|= (T flags) noexcept
 Performs a bitwise OR operation with another LBitset. More...
 
constexpr LBitset< T > & operator&= (T flags) noexcept
 Performs a bitwise AND operation with another LBitset. More...
 
constexpr LBitset< T > & operator^= (T flags) noexcept
 Performs a bitwise XOR operation with another LBitset. More...
 

Detailed Description

template<class T>
class Louvre::LBitset< T >

Compact way of storing and managing conditions or states.

The LBitset class template is similar to std::bitset in that it enables the compact storage of a set of conditions or states using bits.
Unlike std::bitset, LBitset functions are designed to modify and retrieve bit states using flags rather than indices, which are ideally defined within an enum.

It is widely used in the private API of Louvre classes to optimize memory usage.

Example usage:

enum MyFlags
{
FlagA = 1 << 0,
FlagB = 1 << 1,
FlagC = 1 << 2
};
LBitset<MyFlags> myFlags;
myFlags.add(MyFlags::FlagA | MyFlags::FlagC);
if (myFlags.check(MyFlags::FlagC))
{
// do something
}

Constructor & Destructor Documentation

◆ LBitset()

constexpr LBitset ( Flag  flags = 0)
inlineconstexprnoexcept

Constructor for LBitset.

Initializes the bitset with the specified initial flags. If no flags are provided, the bitset is constructed empty without any flags.

Parameters
flagsInitial flags to set (default is 0)

Member Function Documentation

◆ add()

constexpr void add ( Flag  flags)
inlineconstexprnoexcept

Add new flags to the bitfield.

Sets the specified flags by combining them with the existing flags using the bitwise OR operator '|'.

Parameters
flagsThe flag or combination of flags to be added

◆ remove()

constexpr void remove ( Flag  flags)
inlineconstexprnoexcept

Remove flags from the bitfield.

Clears the specified flags by performing a bitwise AND operation with the complement of the provided flags.

Parameters
flagsThe flag or combination of flags to be removed

◆ check()

constexpr bool check ( Flag  flags) const
inlineconstexprnoexcept

Check if at least one flag exists.

Checks if at least one of the specified flags is set in the bitfield.

Parameters
flagsThe flag or combination of flags to be checked
Returns
true if at least one flag is set, otherwise false

◆ checkAll()

constexpr bool checkAll ( Flag  flags) const
inlineconstexprnoexcept

Check if all specified flags exist.

Checks if all of the specified flags are set in the bitfield.

Parameters
flagsThe flag or combination of flags to be checked
Returns
true if all specified flags are set, otherwise false

◆ get()

constexpr Flag get ( ) const
inlineconstexprnoexcept

Gets the current set of flags.

Retrieves the current set of flags stored in the bitfield.

Returns
The current set of flags

◆ set()

constexpr void set ( Flag  flags)
inlineconstexprnoexcept

Set new flags in the bitfield.

Replaces the current set of flags in the bitfield with the specified flags.

Parameters
flagsThe new flag or combination of flags to be set

◆ setFlag()

constexpr void setFlag ( Flag  flag,
bool  enable 
)
inlineconstexprnoexcept

Set or unset a specific flag in the bitfield.

Modifies the specified flag (or flags) in the bitfield. If enable is true, the flag is set, otherwise, it is removed.

Parameters
flagThe flag to be set or unset
enableIf true, set the flag, if false, remove the flag

◆ operator|=()

constexpr LBitset<T>& operator|= ( flags)
inlineconstexprnoexcept

Performs a bitwise OR operation with another LBitset.

Parameters
flagsThe LBitset containing flags to perform the operation with.
Returns
A reference to the modified LBitset after the operation.

◆ operator&=()

constexpr LBitset<T>& operator&= ( flags)
inlineconstexprnoexcept

Performs a bitwise AND operation with another LBitset.

Parameters
flagsThe LBitset containing flags to perform the operation with.
Returns
A reference to the modified LBitset after the operation.

◆ operator^=()

constexpr LBitset<T>& operator^= ( flags)
inlineconstexprnoexcept

Performs a bitwise XOR operation with another LBitset.

Parameters
flagsThe LBitset containing flags to perform the operation with.
Returns
A reference to the modified LBitset after the operation.