Skip to content

Commit

Permalink
xrCore/_flags.h formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 11, 2017
1 parent b83da98 commit be5c51c
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/xrCore/_flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,57 @@
template <class T>
struct _flags
{
public:
typedef T TYPE;
typedef _flags<T> Self;
typedef Self& SelfRef;
typedef const Self& SelfCRef;
using TYPE = T;
using Self =_flags<T>;
using SelfRef = Self&;
using SelfCRef = const Self&;

public:
T flags;

TYPE get() const throw() { return flags; }

SelfRef zero() throw()
{
flags = T(0);
return *this;
}

SelfRef one() throw()
{
flags = T(-1);
return *this;
}

SelfRef invert() throw()
{
flags = ~flags;
return *this;
}

SelfRef invert(const Self& f) throw()
{
flags = ~f.flags;
return *this;
}

SelfRef invert(const T mask) throw()
{
flags ^= mask;
return *this;
}

SelfRef assign(const Self& f) throw()
{
flags = f.flags;
return *this;
}

SelfRef assign(const T mask) throw()
{
flags = mask;
return *this;
}

SelfRef set(const T mask, bool value) throw()
{
if (value)
Expand All @@ -59,40 +65,46 @@ struct _flags
flags &= ~mask;
return *this;
}

bool is(const T mask) const throw() { return mask == (flags & mask); }
bool is_any(const T mask) const throw() { return !!(flags & mask); }
bool test(const T mask) const throw() { return !!(flags & mask); }

SelfRef or (const T mask) throw()
{
flags |= mask;
return *this;
}

SelfRef or (const Self& f, const T mask) throw()
{
flags = f.flags | mask;
return *this;
}

SelfRef and (const T mask) throw()
{
flags &= mask;
return *this;
}

SelfRef and (const Self& f, const T mask) throw()
{
flags = f.flags & mask;
return *this;
}

bool equal(const Self& f) const throw() { return flags == f.flags; }
bool equal(const Self& f, const T mask) const throw() { return (flags & mask) == (f.flags & mask); }
};

typedef _flags<u8> Flags8;
typedef _flags<u8> flags8;
typedef _flags<u16> Flags16;
typedef _flags<u16> flags16;
typedef _flags<u32> Flags32;
typedef _flags<u32> flags32;
typedef _flags<u64> Flags64;
typedef _flags<u64> flags64;
using Flags8 = _flags<u8>;
using flags8 = _flags<u8>;
using Flags16 = _flags<u16>;
using flags16 = _flags<u16>;
using Flags32 = _flags<u32>;
using flags32 = _flags<u32>;
using Flags64 = _flags<u64>;
using flags64 = _flags<u64>;

#endif //__FLAGS_H__

0 comments on commit be5c51c

Please sign in to comment.