123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- class UInt24
- {
- public:
- UInt24()
- : m_value(0u)
- {
- }
- UInt24(const UInt24 &other)
- : m_value(other.m_value)
- {
- }
- UInt24(const auto &other)
- : m_value(mask(other))
- {
- }
- UInt24 & operator=(const UInt24 &other)
- {
- m_value = other.m_value;
- return *this;
- }
- UInt24 & operator=(const auto &other)
- {
- m_value = mask(other);
- return *this;
- }
- operator unsigned int() const
- {
- return m_value;
- }
- UInt24 operator++() // prefix-inc
- {
- m_value = mask(m_value + 1u);
- return *this;
- }
- UInt24 operator++(int) // postfix-inc
- {
- UInt24 old(*this);
- ++(*this);
- return old;
- }
- UInt24 operator--() // prefix-dec
- {
- m_value = mask(m_value - 1u);
- return *this;
- }
- UInt24 operator--(int) // postfix-dec
- {
- UInt24 old(*this);
- --(*this);
- return old;
- }
- UInt24 & operator+=(const UInt24 &other)
- {
- m_value = mask(m_value + other.m_value);
- return *this;
- }
- UInt24 & operator+=(const auto &other)
- {
- m_value = mask(m_value + mask(other));
- return *this;
- }
- UInt24 & operator-=(const UInt24 &other)
- {
- m_value = mask(m_value - other.m_value);
- return *this;
- }
- UInt24 & operator-=(const auto &other)
- {
- m_value = mask(m_value - mask(other));
- return *this;
- }
- UInt24 operator&(const UInt24 &other) const
- {
- return UInt24(m_value & other.m_value);
- }
- UInt24 operator&(const auto &other) const
- {
- return UInt24(m_value & mask(other));
- }
- UInt24 operator|(const UInt24 &other) const
- {
- return UInt24(m_value | other.m_value);
- }
- UInt24 operator|(const auto &other) const
- {
- return UInt24(m_value | mask(other));
- }
- UInt24 operator^(const UInt24 &other) const
- {
- return UInt24(m_value ^ other.m_value);
- }
- UInt24 operator^(const auto &other) const
- {
- return UInt24(m_value ^ mask(other));
- }
- const UInt24 operator+(const UInt24 &other) const
- {
- return UInt24(m_value + other.m_value);
- }
- const UInt24 operator+(const auto &other) const
- {
- return UInt24(m_value + mask(other));
- }
- const UInt24 operator-(const UInt24 &other) const
- {
- return UInt24(m_value - other.m_value);
- }
- const UInt24 operator-(const auto &other) const
- {
- return UInt24(m_value - mask(other));
- }
- const UInt24 operator*(const UInt24 &other) const
- {
- return UInt24(m_value * other.m_value);
- }
- const UInt24 operator*(const auto &other) const
- {
- return UInt24(m_value * mask(other));
- }
- const UInt24 operator/(const UInt24 &other) const
- {
- return UInt24(m_value / other.m_value);
- }
- const UInt24 operator/(const auto &other) const
- {
- return UInt24(m_value / mask(other));
- }
- bool operator<(const UInt24 &other) const
- {
- return m_value < other.m_value;
- }
- bool operator<(const auto &other) const
- {
- return m_value < mask(other);
- }
- bool operator==(const UInt24 &other) const
- {
- return m_value == other.m_value;
- }
- bool operator==(const auto &other) const
- {
- return m_value == mask(other);
- }
- bool operator!=(const UInt24 &other) const
- {
- return m_value != other.m_value;
- }
- bool operator!=(const auto &other) const
- {
- return m_value != mask(other);
- }
- bool operator>(const UInt24 &other) const
- {
- return m_value > other.m_value;
- }
- bool operator>(const auto &other) const
- {
- return m_value > mask(other);
- }
- protected:
- unsigned int mask(const auto &value) const
- {
- return static_cast<unsigned int>(value) & 0x00FFFFFFu;
- }
- protected:
- unsigned int m_value;
- };
- class Int24
- {
- public:
- Int24()
- : m_value(0)
- {
- }
- Int24(const Int24 &other)
- : m_value(other.m_value)
- {
- }
- Int24(const auto &other)
- : m_value(extend(other))
- {
- }
- Int24 & operator=(const Int24 &other)
- {
- m_value = other.m_value;
- return *this;
- }
- Int24 & operator=(const auto &other)
- {
- m_value = extend(other);
- return *this;
- }
- operator int() const
- {
- return m_value;
- }
- Int24 operator++() // prefix-inc
- {
- m_value = extend(m_value + 1);
- return *this;
- }
- Int24 operator++(int) // postfix-inc
- {
- Int24 old(*this);
- ++(*this);
- return old;
- }
- Int24 operator--() // prefix-dec
- {
- m_value = extend(m_value - 1);
- return *this;
- }
- Int24 operator--(int) // postfix-dec
- {
- Int24 old(*this);
- --(*this);
- return old;
- }
- Int24 & operator+=(const Int24 &other)
- {
- m_value = extend(m_value + other.m_value);
- return *this;
- }
- Int24 & operator+=(const auto &other)
- {
- m_value = extend(m_value + extend(other));
- return *this;
- }
- Int24 & operator-=(const Int24 &other)
- {
- m_value = extend(m_value - other.m_value);
- return *this;
- }
- Int24 & operator-=(const auto &other)
- {
- m_value = extend(m_value - extend(other));
- return *this;
- }
- Int24 operator&(const Int24 &other) const
- {
- return Int24(m_value & other.m_value);
- }
- Int24 operator&(const auto &other) const
- {
- return Int24(m_value & extend(other));
- }
- Int24 operator|(const Int24 &other) const
- {
- return Int24(m_value | other.m_value);
- }
- Int24 operator|(const auto &other) const
- {
- return Int24(m_value | extend(other));
- }
- Int24 operator^(const Int24 &other) const
- {
- return Int24(m_value ^ other.m_value);
- }
- Int24 operator^(const auto &other) const
- {
- return Int24(m_value ^ extend(other));
- }
- const Int24 operator+(const Int24 &other) const
- {
- return Int24(m_value + other.m_value);
- }
- const Int24 operator+(const auto &other) const
- {
- return Int24(m_value + extend(other));
- }
- const Int24 operator-(const Int24 &other) const
- {
- return Int24(m_value - other.m_value);
- }
- const Int24 operator-(const auto &other) const
- {
- return Int24(m_value - extend(other));
- }
- const Int24 operator*(const Int24 &other) const
- {
- return Int24(m_value * other.m_value);
- }
- const Int24 operator*(const auto &other) const
- {
- return Int24(m_value * extend(other));
- }
- const Int24 operator/(const Int24 &other) const
- {
- return Int24(m_value / other.m_value);
- }
- const Int24 operator/(const auto &other) const
- {
- return Int24(m_value / extend(other));
- }
- bool operator<(const Int24 &other) const
- {
- return m_value < other.m_value;
- }
- bool operator<(const auto &other) const
- {
- return m_value < extend(other);
- }
- bool operator==(const Int24 &other) const
- {
- return m_value == other.m_value;
- }
- bool operator==(const auto &other) const
- {
- return m_value == extend(other);
- }
- bool operator!=(const Int24 &other) const
- {
- return m_value != other.m_value;
- }
- bool operator!=(const auto &other) const
- {
- return m_value != extend(other);
- }
- bool operator>(const Int24 &other) const
- {
- return m_value > other.m_value;
- }
- bool operator>(const auto &other) const
- {
- return m_value > extend(other);
- }
- protected:
- int extend(const auto &value) const
- {
- unsigned int v = static_cast<unsigned int>(value) & 0x00FFFFFFu;
- if (v & (1u << 23))
- v |= 0xFF000000u;
- return static_cast<int>(v);
- }
- protected:
- int m_value;
- };
|