cog/Frameworks/OpenMPT.old/OpenMPT/common/FlagSet.h

416 lines
19 KiB
C
Raw Normal View History

2018-02-19 04:25:43 +00:00
/*
* FlagSet.h
* ---------
* Purpose: A flexible and typesafe flag set class.
* Notes : Originally based on http://stackoverflow.com/questions/4226960/type-safer-bitflags-in-c .
* Rewritten to be standard-conforming.
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
2019-01-24 02:16:37 +00:00
#include "BuildSettings.h"
2018-02-19 04:25:43 +00:00
#include <string>
OPENMPT_NAMESPACE_BEGIN
// Be aware of the required size when specializing this.
// We cannot assert the minimum size because some compilers always allocate an 'int',
// even for enums that would fit in smaller integral types.
template <typename Tenum>
struct enum_traits
{
2020-09-22 04:54:24 +00:00
using store_type = typename std::make_unsigned<Tenum>::type;
2018-02-19 04:25:43 +00:00
};
// Type-safe wrapper around an enum, that can represent all enum values and bitwise compositions thereof.
// Conversions to and from plain integers as well as conversions to the base enum are always explicit.
template <typename enum_t>
2019-01-24 02:16:37 +00:00
// cppcheck-suppress copyCtorAndEqOperator
2018-02-19 04:25:43 +00:00
class enum_value_type
{
public:
2020-09-22 04:54:24 +00:00
using enum_type = enum_t;
using value_type = enum_value_type;
using store_type = typename enum_traits<enum_t>::store_type;
2018-02-19 04:25:43 +00:00
private:
store_type bits;
public:
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN enum_value_type() noexcept : bits(0) { }
MPT_CONSTEXPR11_FUN enum_value_type(const enum_value_type &x) noexcept : bits(x.bits) { }
MPT_CONSTEXPR11_FUN enum_value_type(enum_type x) noexcept : bits(static_cast<store_type>(x)) { }
2018-02-19 04:25:43 +00:00
private:
2019-01-24 02:16:37 +00:00
explicit MPT_CONSTEXPR11_FUN enum_value_type(store_type x) noexcept : bits(x) { } // private in order to prevent accidental conversions. use from_bits.
MPT_CONSTEXPR11_FUN operator store_type () const noexcept { return bits; } // private in order to prevent accidental conversions. use as_bits.
2018-02-19 04:25:43 +00:00
public:
2019-01-24 02:16:37 +00:00
static MPT_CONSTEXPR11_FUN enum_value_type from_bits(store_type bits) noexcept { return value_type(bits); }
MPT_CONSTEXPR11_FUN enum_type as_enum() const noexcept { return static_cast<enum_t>(bits); }
MPT_CONSTEXPR11_FUN store_type as_bits() const noexcept { return bits; }
2018-02-19 04:25:43 +00:00
public:
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN operator bool () const noexcept { return bits != store_type(); }
MPT_CONSTEXPR11_FUN bool operator ! () const noexcept { return bits == store_type(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN const enum_value_type operator ~ () const noexcept { return enum_value_type(~bits); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (enum_value_type a, enum_value_type b) noexcept { return a.bits == b.bits; }
friend MPT_CONSTEXPR11_FUN bool operator != (enum_value_type a, enum_value_type b) noexcept { return a.bits != b.bits; }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (enum_value_type a, enum_t b) noexcept { return a == enum_value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (enum_value_type a, enum_t b) noexcept { return a != enum_value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (enum_t a, enum_value_type b) noexcept { return enum_value_type(a) == b; }
friend MPT_CONSTEXPR11_FUN bool operator != (enum_t a, enum_value_type b) noexcept { return enum_value_type(a) != b; }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const enum_value_type operator | (enum_value_type a, enum_value_type b) noexcept { return enum_value_type(a.bits | b.bits); }
friend MPT_CONSTEXPR11_FUN const enum_value_type operator & (enum_value_type a, enum_value_type b) noexcept { return enum_value_type(a.bits & b.bits); }
friend MPT_CONSTEXPR11_FUN const enum_value_type operator ^ (enum_value_type a, enum_value_type b) noexcept { return enum_value_type(a.bits ^ b.bits); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const enum_value_type operator | (enum_value_type a, enum_t b) noexcept { return a | enum_value_type(b); }
friend MPT_CONSTEXPR11_FUN const enum_value_type operator & (enum_value_type a, enum_t b) noexcept { return a & enum_value_type(b); }
friend MPT_CONSTEXPR11_FUN const enum_value_type operator ^ (enum_value_type a, enum_t b) noexcept { return a ^ enum_value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const enum_value_type operator | (enum_t a, enum_value_type b) noexcept { return enum_value_type(a) | b; }
friend MPT_CONSTEXPR11_FUN const enum_value_type operator & (enum_t a, enum_value_type b) noexcept { return enum_value_type(a) & b; }
friend MPT_CONSTEXPR11_FUN const enum_value_type operator ^ (enum_t a, enum_value_type b) noexcept { return enum_value_type(a) ^ b; }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN enum_value_type &operator |= (enum_value_type b) noexcept { *this = *this | b; return *this; }
MPT_CONSTEXPR14_FUN enum_value_type &operator &= (enum_value_type b) noexcept { *this = *this & b; return *this; }
MPT_CONSTEXPR14_FUN enum_value_type &operator ^= (enum_value_type b) noexcept { *this = *this ^ b; return *this; }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN enum_value_type &operator |= (enum_t b) noexcept { *this = *this | b; return *this; }
MPT_CONSTEXPR14_FUN enum_value_type &operator &= (enum_t b) noexcept { *this = *this & b; return *this; }
MPT_CONSTEXPR14_FUN enum_value_type &operator ^= (enum_t b) noexcept { *this = *this ^ b; return *this; }
2018-02-19 04:25:43 +00:00
};
// Type-safe enum wrapper that allows type-safe bitwise testing.
template <typename enum_t>
class Enum
{
public:
2020-09-22 04:54:24 +00:00
using self_type = Enum;
using enum_type = enum_t;
using value_type = enum_value_type<enum_t>;
using store_type = typename value_type::store_type;
2018-02-19 04:25:43 +00:00
private:
enum_type value;
public:
2019-01-24 02:16:37 +00:00
explicit MPT_CONSTEXPR11_FUN Enum(enum_type val) noexcept : value(val) { }
MPT_CONSTEXPR11_FUN operator enum_type () const noexcept { return value; }
MPT_CONSTEXPR14_FUN Enum &operator = (enum_type val) noexcept { value = val; return *this; }
2018-02-19 04:25:43 +00:00
public:
MPT_CONSTEXPR11_FUN const value_type operator ~ () const { return ~value_type(value); }
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, self_type b) noexcept { return value_type(a) == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, self_type b) noexcept { return value_type(a) != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, value_type b) noexcept { return value_type(a) == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, value_type b) noexcept { return value_type(a) != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (value_type a, self_type b) noexcept { return value_type(a) == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (value_type a, self_type b) noexcept { return value_type(a) != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, enum_type b) noexcept { return value_type(a) == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, enum_type b) noexcept { return value_type(a) != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (enum_type a, self_type b) noexcept { return value_type(a) == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (enum_type a, self_type b) noexcept { return value_type(a) != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, self_type b) noexcept { return value_type(a) | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, self_type b) noexcept { return value_type(a) & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, self_type b) noexcept { return value_type(a) ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, value_type b) noexcept { return value_type(a) | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, value_type b) noexcept { return value_type(a) & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, value_type b) noexcept { return value_type(a) ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (value_type a, self_type b) noexcept { return value_type(a) | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (value_type a, self_type b) noexcept { return value_type(a) & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (value_type a, self_type b) noexcept { return value_type(a) ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, enum_type b) noexcept { return value_type(a) | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, enum_type b) noexcept { return value_type(a) & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, enum_type b) noexcept { return value_type(a) ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (enum_type a, self_type b) noexcept { return value_type(a) | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (enum_type a, self_type b) noexcept { return value_type(a) & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (enum_type a, self_type b) noexcept { return value_type(a) ^ value_type(b); }
2018-02-19 04:25:43 +00:00
};
template <typename enum_t, typename store_t = typename enum_value_type<enum_t>::store_type >
2019-01-24 02:16:37 +00:00
// cppcheck-suppress copyCtorAndEqOperator
2018-02-19 04:25:43 +00:00
class FlagSet
{
public:
2020-09-22 04:54:24 +00:00
using self_type = FlagSet;
using enum_type = enum_t;
using value_type = enum_value_type<enum_t>;
using store_type = store_t;
2018-02-19 04:25:43 +00:00
private:
// support truncated store_type ... :
store_type bits_;
2019-01-24 02:16:37 +00:00
static MPT_CONSTEXPR11_FUN store_type store_from_value(value_type bits) noexcept { return static_cast<store_type>(bits.as_bits()); }
static MPT_CONSTEXPR11_FUN value_type value_from_store(store_type bits) noexcept { return value_type::from_bits(static_cast<typename value_type::store_type>(bits)); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet & store(value_type bits) noexcept { bits_ = store_from_value(bits); return *this; }
MPT_CONSTEXPR11_FUN value_type load() const noexcept { return value_from_store(bits_); }
2018-02-19 04:25:43 +00:00
public:
// Default constructor (no flags set)
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN FlagSet() noexcept : bits_(store_from_value(value_type()))
{
}
// Copy constructor
MPT_CONSTEXPR11_FUN FlagSet(const FlagSet &flags) noexcept
: bits_(flags.bits_)
2018-02-19 04:25:43 +00:00
{
}
// Value constructor
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN FlagSet(value_type flags) noexcept : bits_(store_from_value(value_type(flags)))
2018-02-19 04:25:43 +00:00
{
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN FlagSet(enum_type flag) noexcept : bits_(store_from_value(value_type(flag)))
2018-02-19 04:25:43 +00:00
{
}
2019-01-24 02:16:37 +00:00
explicit MPT_CONSTEXPR11_FUN FlagSet(store_type flags) noexcept : bits_(store_from_value(value_type::from_bits(flags)))
2018-02-19 04:25:43 +00:00
{
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN explicit operator bool () const noexcept
2018-02-19 04:25:43 +00:00
{
return load();
}
2020-09-22 04:54:24 +00:00
MPT_CONSTEXPR11_FUN explicit operator store_type () const noexcept
2018-02-19 04:25:43 +00:00
{
return load().as_bits();
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN value_type value() const noexcept
2018-02-19 04:25:43 +00:00
{
return load();
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN operator value_type () const noexcept
2018-02-19 04:25:43 +00:00
{
return load();
}
// Test if one or more flags are set. Returns true if at least one of the given flags is set.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN bool operator[] (value_type flags) const noexcept
2018-02-19 04:25:43 +00:00
{
return test(flags);
}
// String representation of flag set
2019-01-24 02:16:37 +00:00
std::string to_string() const noexcept
2018-02-19 04:25:43 +00:00
{
std::string str(size_bits(), '0');
for(size_t x = 0; x < size_bits(); ++x)
{
str[size_bits() - x - 1] = (load() & (1 << x) ? '1' : '0');
}
return str;
}
// Set one or more flags.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &set(value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(load() | flags);
}
// Set or clear one or more flags.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &set(value_type flags, bool val) noexcept
2018-02-19 04:25:43 +00:00
{
return store((val ? (load() | flags) : (load() & ~flags)));
}
// Clear or flags.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &reset() noexcept
2018-02-19 04:25:43 +00:00
{
return store(value_type());
}
// Clear one or more flags.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &reset(value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(load() & ~flags);
}
// Toggle all flags.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &flip() noexcept
2018-02-19 04:25:43 +00:00
{
return store(~load());
}
// Toggle one or more flags.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &flip(value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(load() ^ flags);
}
// Returns the size of the flag set in bytes
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN std::size_t size() const noexcept
2018-02-19 04:25:43 +00:00
{
return sizeof(store_type);
}
// Returns the size of the flag set in bits
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN std::size_t size_bits() const noexcept
2018-02-19 04:25:43 +00:00
{
return size() * 8;
}
// Test if one or more flags are set. Returns true if at least one of the given flags is set.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN bool test(value_type flags) const noexcept
2018-02-19 04:25:43 +00:00
{
return (load() & flags);
}
// Test if all specified flags are set.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN bool test_all(value_type flags) const noexcept
2018-02-19 04:25:43 +00:00
{
return (load() & flags) == flags;
}
// Test if any but the specified flags are set.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN bool test_any_except(value_type flags) const noexcept
2018-02-19 04:25:43 +00:00
{
return (load() & ~flags);
}
// Test if any flag is set.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN bool any() const noexcept
2018-02-19 04:25:43 +00:00
{
return load();
}
// Test if no flags are set.
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN bool none() const noexcept
2018-02-19 04:25:43 +00:00
{
return !load();
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN store_type GetRaw() const noexcept
2018-02-19 04:25:43 +00:00
{
return bits_;
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet & SetRaw(store_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
bits_ = flags;
return *this;
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &operator = (value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(flags);
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &operator = (enum_type flag) noexcept
2018-02-19 04:25:43 +00:00
{
return store(flag);
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &operator = (FlagSet flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(flags.load());
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &operator &= (value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(load() & flags);
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &operator |= (value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(load() | flags);
}
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR14_FUN FlagSet &operator ^= (value_type flags) noexcept
2018-02-19 04:25:43 +00:00
{
return store(load() ^ flags);
}
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, self_type b) noexcept { return a.load() == b.load(); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, self_type b) noexcept { return a.load() != b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, value_type b) noexcept { return a.load() == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, value_type b) noexcept { return a.load() != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (value_type a, self_type b) noexcept { return value_type(a) == b.load(); }
friend MPT_CONSTEXPR11_FUN bool operator != (value_type a, self_type b) noexcept { return value_type(a) != b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, enum_type b) noexcept { return a.load() == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, enum_type b) noexcept { return a.load() != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (enum_type a, self_type b) noexcept { return value_type(a) == b.load(); }
friend MPT_CONSTEXPR11_FUN bool operator != (enum_type a, self_type b) noexcept { return value_type(a) != b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (self_type a, Enum<enum_type> b) noexcept { return a.load() == value_type(b); }
friend MPT_CONSTEXPR11_FUN bool operator != (self_type a, Enum<enum_type> b) noexcept { return a.load() != value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN bool operator == (Enum<enum_type> a, self_type b) noexcept { return value_type(a) == b.load(); }
friend MPT_CONSTEXPR11_FUN bool operator != (Enum<enum_type> a, self_type b) noexcept { return value_type(a) != b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, self_type b) noexcept { return a.load() | b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, self_type b) noexcept { return a.load() & b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, self_type b) noexcept { return a.load() ^ b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, value_type b) noexcept { return a.load() | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, value_type b) noexcept { return a.load() & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, value_type b) noexcept { return a.load() ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (value_type a, self_type b) noexcept { return value_type(a) | b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (value_type a, self_type b) noexcept { return value_type(a) & b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (value_type a, self_type b) noexcept { return value_type(a) ^ b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, enum_type b) noexcept { return a.load() | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, enum_type b) noexcept { return a.load() & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, enum_type b) noexcept { return a.load() ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (enum_type a, self_type b) noexcept { return value_type(a) | b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (enum_type a, self_type b) noexcept { return value_type(a) & b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (enum_type a, self_type b) noexcept { return value_type(a) ^ b.load(); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (self_type a, Enum<enum_type> b) noexcept { return a.load() | value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (self_type a, Enum<enum_type> b) noexcept { return a.load() & value_type(b); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (self_type a, Enum<enum_type> b) noexcept { return a.load() ^ value_type(b); }
2018-02-19 04:25:43 +00:00
2019-01-24 02:16:37 +00:00
friend MPT_CONSTEXPR11_FUN const value_type operator | (Enum<enum_type> a, self_type b) noexcept { return value_type(a) | b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator & (Enum<enum_type> a, self_type b) noexcept { return value_type(a) & b.load(); }
friend MPT_CONSTEXPR11_FUN const value_type operator ^ (Enum<enum_type> a, self_type b) noexcept { return value_type(a) ^ b.load(); }
2018-02-19 04:25:43 +00:00
};
// Declare typesafe logical operators for enum_t
#define MPT_DECLARE_ENUM(enum_t) \
2019-01-24 02:16:37 +00:00
MPT_CONSTEXPR11_FUN enum_value_type<enum_t> operator | (enum_t a, enum_t b) noexcept { return enum_value_type<enum_t>(a) | enum_value_type<enum_t>(b); } \
MPT_CONSTEXPR11_FUN enum_value_type<enum_t> operator & (enum_t a, enum_t b) noexcept { return enum_value_type<enum_t>(a) & enum_value_type<enum_t>(b); } \
MPT_CONSTEXPR11_FUN enum_value_type<enum_t> operator ^ (enum_t a, enum_t b) noexcept { return enum_value_type<enum_t>(a) ^ enum_value_type<enum_t>(b); } \
MPT_CONSTEXPR11_FUN enum_value_type<enum_t> operator ~ (enum_t a) noexcept { return ~enum_value_type<enum_t>(a); } \
2018-02-19 04:25:43 +00:00
/**/
// backwards compatibility
#define DECLARE_FLAGSET MPT_DECLARE_ENUM
OPENMPT_NAMESPACE_END