From 8b75b5cbfbb53e0bfa51c63dc96ade69617cd1db Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 29 Jan 2009 02:24:25 -0400 Subject: Revised the way that parsing flags get passed around. --- src/flags.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'src/flags.h') diff --git a/src/flags.h b/src/flags.h index 297d5b9f..eb42311c 100644 --- a/src/flags.h +++ b/src/flags.h @@ -32,7 +32,7 @@ #ifndef _FLAGS_H #define _FLAGS_H -template +template class supports_flags { public: @@ -42,7 +42,7 @@ protected: flags_t _flags; public: - supports_flags() : _flags(0) { + supports_flags() : _flags(static_cast(0)) { TRACE_CTOR(supports_flags, ""); } supports_flags(const supports_flags& arg) : _flags(arg._flags) { @@ -66,13 +66,60 @@ public: _flags = arg; } void clear_flags() { - _flags = 0; + _flags = static_cast(0); } void add_flags(const flags_t arg) { - _flags |= arg; + _flags = static_cast(static_cast(_flags) | static_cast(arg)); } void drop_flags(const flags_t arg) { - _flags &= ~arg; + _flags = static_cast(static_cast(_flags) & static_cast(~arg)); + } +}; + +template +class basic_flags_t : public supports_flags +{ +public: + basic_flags_t() { + TRACE_CTOR(basic_flags_t, ""); + } + basic_flags_t(const T& bits) { + TRACE_CTOR(basic_flags_t, "const T&"); + set_flags(bits); + } + basic_flags_t(const U& bits) { + TRACE_CTOR(basic_flags_t, "const U&"); + set_flags(static_cast(bits)); + } + ~basic_flags_t() throw() { + TRACE_DTOR(basic_flags_t); + } + + basic_flags_t& operator=(const basic_flags_t& other) { + set_flags(other.flags()); + return *this; + } + basic_flags_t& operator=(const T& bits) { + set_flags(bits); + return *this; + } + + operator T() const { + return supports_flags::flags(); + } + operator U() const { + return supports_flags::flags(); + } + + basic_flags_t plus_flags(const T& arg) const { + basic_flags_t temp(*this); + temp.add_flags(arg); + return temp; + } + basic_flags_t minus_flags(const T& arg) const { + basic_flags_t temp(*this); + temp.drop_flags(arg); + return temp; } }; -- cgit v1.2.3