Skip to content

Commit

Permalink
xrCore/_flags.h - pragma once, make possible to compile stand-alone, …
Browse files Browse the repository at this point in the history
…remove pointless IC macro.
  • Loading branch information
tamlin-mike authored and Xottab-DUTY committed Aug 5, 2017
1 parent e095aaa commit 7d29e2f
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/xrCore/_flags.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#ifndef __FLAGS_H__
#define __FLAGS_H__
#include "_types.h"

template <class T>
struct _flags
Expand All @@ -13,75 +15,75 @@ struct _flags
public:
T flags;

IC TYPE get() const { return flags; }
IC SelfRef zero()
TYPE get() const { return flags; }
SelfRef zero()
{
flags = T(0);
return *this;
}
IC SelfRef one()
SelfRef one()
{
flags = T(-1);
return *this;
}
IC SelfRef invert()
SelfRef invert()
{
flags = ~flags;
return *this;
}
IC SelfRef invert(const Self& f)
SelfRef invert(const Self& f)
{
flags = ~f.flags;
return *this;
}
IC SelfRef invert(const T mask)
SelfRef invert(const T mask)
{
flags ^= mask;
return *this;
}
IC SelfRef assign(const Self& f)
SelfRef assign(const Self& f)
{
flags = f.flags;
return *this;
}
IC SelfRef assign(const T mask)
SelfRef assign(const T mask)
{
flags = mask;
return *this;
}
IC SelfRef set(const T mask, BOOL value)
SelfRef set(const T mask, BOOL value)
{
if (value)
flags |= mask;
else
flags &= ~mask;
return *this;
}
IC BOOL is(const T mask) const { return mask == (flags & mask); }
IC BOOL is_any(const T mask) const { return BOOL(!!(flags & mask)); }
IC BOOL test(const T mask) const { return BOOL(!!(flags & mask)); }
IC SelfRef or (const T mask)
BOOL is(const T mask) const { return mask == (flags & mask); }
BOOL is_any(const T mask) const { return BOOL(!!(flags & mask)); }
BOOL test(const T mask) const { return BOOL(!!(flags & mask)); }
SelfRef or (const T mask)
{
flags |= mask;
return *this;
}
IC SelfRef or (const Self& f, const T mask)
SelfRef or (const Self& f, const T mask)
{
flags = f.flags | mask;
return *this;
}
IC SelfRef and (const T mask)
SelfRef and (const T mask)
{
flags &= mask;
return *this;
}
IC SelfRef and (const Self& f, const T mask)
SelfRef and (const Self& f, const T mask)
{
flags = f.flags & mask;
return *this;
}
IC BOOL equal(const Self& f) const { return flags == f.flags; }
IC BOOL equal(const Self& f, const T mask) const { return (flags & mask) == (f.flags & mask); }
BOOL equal(const Self& f) const { return flags == f.flags; }
BOOL equal(const Self& f, const T mask) const { return (flags & mask) == (f.flags & mask); }
};

typedef _flags<u8> Flags8;
Expand Down

0 comments on commit 7d29e2f

Please sign in to comment.