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

#include <LBitset.h>

Compact way of storing and managing conditions or states. 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
}

Public Member Functions

 LBitset (Flag flags=0)
 Constructor for LBitset. More...
 
void add (Flag flags)
 Add new flags to the bitfield. More...
 
void remove (Flag flags)
 Remove flags from the bitfield. More...
 
bool check (Flag flags) const
 Check if at least one flag exists. More...
 
bool checkAll (Flag flags) const
 Check if all specified flags exist. More...
 
Flag get () const
 Get the current set of flags. More...
 
void set (Flag flags)
 Set new flags in the bitfield. More...
 
void setFlag (Flag flag, bool enable)
 Set or unset a specific flag in the bitfield. More...
 

Constructor & Destructor Documentation

◆ LBitset()

LBitset ( Flag  flags = 0)
inline

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()

void add ( Flag  flags)
inline

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()

void remove ( Flag  flags)
inline

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()

bool check ( Flag  flags) const
inline

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()

bool checkAll ( Flag  flags) const
inline

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()

Flag get ( ) const
inline

Get the current set of flags.

Retrieves the current set of flags stored in the bitfield.

Returns
The current set of flags

◆ set()

void set ( Flag  flags)
inline

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()

void setFlag ( Flag  flag,
bool  enable 
)
inline

Set or unset a specific flag in the bitfield.

Modifies the specified flag 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