first commit
This commit is contained in:
60
include/platform/memory/bit_field.h
Normal file
60
include/platform/memory/bit_field.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NBITFIELD__
|
||||
#define __NBITFIELD__
|
||||
|
||||
|
||||
#include "ntypes.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
class BitField
|
||||
{
|
||||
uint v;
|
||||
|
||||
public:
|
||||
|
||||
BitField &operator &= (uint b) { v &= b; return *this; }
|
||||
BitField &operator |= (uint b) { v |= b; return *this; }
|
||||
BitField &operator = (uint b) { v = b; return *this; }
|
||||
|
||||
BitField &operator &= (const BitField &b) { v &= b.v; return *this; }
|
||||
BitField &operator |= (const BitField &b) { v |= b.v; return *this; }
|
||||
BitField &operator = (const BitField &b) { v = b.v; return *this; }
|
||||
|
||||
bool operator == (const BitField &b) const { return v == b.v; }
|
||||
bool operator != (const BitField &b) const { return v != b.v; }
|
||||
|
||||
inline uint Get() const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
inline uint Set(uint b)
|
||||
{
|
||||
v |= b;
|
||||
return v;
|
||||
}
|
||||
inline uint Remove(uint b)
|
||||
{
|
||||
v &= ~b;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline uint Raise(uint b, bool raise = true)
|
||||
{
|
||||
return raise ? Set(b) : Remove(b);
|
||||
}
|
||||
inline bool IsSet(uint b) const { return asbool(v & b); }
|
||||
|
||||
BitField() : v(0) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __NBITFIELD__
|
||||
Reference in New Issue
Block a user