59 lines
957 B
C
59 lines
957 B
C
|
#pragma once
|
||
|
#include <luna/Check.h>
|
||
|
|
||
|
template <typename T> class Bitset
|
||
|
{
|
||
|
public:
|
||
|
Bitset() : m_value()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
Bitset(T value) : m_value(value)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
Bitset(const Bitset<T>& other) : m_value(other.m_value)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
Bitset<T>& operator=(T value)
|
||
|
{
|
||
|
m_value = value;
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Bitset<T>& operator=(const Bitset<T>& other)
|
||
|
{
|
||
|
if (&other == this) return *this;
|
||
|
m_value = other.m_value;
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
T value() const
|
||
|
{
|
||
|
return m_value;
|
||
|
}
|
||
|
|
||
|
void set(int index, bool b)
|
||
|
{
|
||
|
check((usize)index < (sizeof(T) * 8));
|
||
|
if (b) m_value |= (((T)1) << index);
|
||
|
else
|
||
|
m_value &= ~(((T)1) << index);
|
||
|
}
|
||
|
|
||
|
bool get(int index)
|
||
|
{
|
||
|
check((usize)index < (sizeof(T) * 8));
|
||
|
return m_value & (((T)1) << index);
|
||
|
}
|
||
|
|
||
|
void clear()
|
||
|
{
|
||
|
m_value = 0;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
T m_value;
|
||
|
};
|