.. _program_listing_file__tmp_ws_src_ecl_core_ecl_utilities_include_ecl_utilities_flags.hpp: Program Listing for File flags.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_utilities/include/ecl/utilities/flags.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_UTILITIES_FLAGS_HPP_ #define ECL_UTILITIES_FLAGS_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Classes *****************************************************************************/ enum Bits { Bit0 = 0x0000, Bit1 = 0x0001, Bit2 = 0x0002, Bit3 = 0x0004, Bit4 = 0x0008, Bit5 = 0x0010, Bit6 = 0x0020, Bit7 = 0x0040, Bit8 = 0x0080, Bit9 = 0x0100, Bit10 = 0x0200, Bit11 = 0x0400, Bit12 = 0x0800, Bit13 = 0x1000, Bit14 = 0x2000, Bit15 = 0x4000, Bit16 = 0x8000, }; template class Flags { public: /********************* ** C&D **********************/ Flags() : value(0) {}; Flags(const Flags & other) : value(other.value) {}; Flags(Enum flag) : value(flag) {}; ~Flags() { } ; /********************* ** Utility **********************/ void clear() { value = 0; } bool testFlag(Enum flag) const { if ((value & flag) != 0) { return true; } else { if ( ( flag == 0 ) && ( value == 0 ) ) { return true; } else { return false; } } } ; /********************* ** Type compatibility **********************/ operator int() const { return value; } ; /****************************************** ** Return new instance *******************************************/ Flags operator&(int mask) const { Flags f; f.value = value & mask; return f; } ; Flags operator&(Enum flag) const { Flags f; f.value = value & flag; return f; } ; Flags operator|(Flags other) const { Flags f; f.value = value | other.value; return f; } ; Flags operator|(Enum flag) const { Flags f; f.value = value | flag; return f; } ; Flags operator^(Flags other) const { Flags f; f.value = value ^ other.value; return f; } ; Flags operator^(Enum flag) const { Flags f; f.value = value ^ flag; return f; } ; Flags operator~() const { Flags f; f.value = ~value; return f; } ; /****************************************** ** Update current instance *******************************************/ Flags & operator=(const Flags & other) { value = other.value; return *this; } ; Flags & operator=(const Enum & flag) { value = static_cast(flag); return *this; } ; Flags & operator&=(int mask) { value &= mask; return *this; } ; Flags & operator|=(Flags other) { value |= other; return *this; } ; Flags & operator|=(Enum flag) { value |= flag; return *this; } ; Flags & operator^=(Flags other) { value ^= other; return *this; } ; Flags & operator^=(Enum flag) { value ^= flag; return *this; } ; /********************* ** Helper Methods **********************/ friend inline Flags operator|(Enum flag, Flags flags) { return flags | flag; } private: int value; }; } // namespace ecl #endif /* ECL_UTILITIES_FLAGS_HPP_ */