RetroArch
be_val.h
Go to the documentation of this file.
1 #pragma once
2 #include <ostream>
3 #include <type_traits>
4 #include "utils.h"
5 
6 template<typename Type>
7 class be_val
8 {
9 public:
10  static_assert(!std::is_array<Type>::value, "be_val invalid type: array");
11  static_assert(!std::is_pointer<Type>::value, "be_val invalid type: pointer");
12  static_assert(sizeof(Type) == 1 || sizeof(Type) == 2 || sizeof(Type) == 4 || sizeof(Type) == 8, "be_val invalid type size");
13 
15  {
16  }
17 
19  {
20  *this = value;
21  }
22 
23  Type value() const
24  {
25  return byte_swap(mValue);
26  }
27 
28  operator Type() const
29  {
30  return value();
31  }
32 
34  operator =(const Other &rhs)
35  {
36  mValue = byte_swap(static_cast<Type>(rhs));
37  return *this;
38  }
39 
40  be_val &operator++() { *this = value() + 1; return *this; }
41  be_val &operator--() { *this = value() - 1; return *this; }
42  be_val operator--(int) { auto old = *this; *this = value() - 1; return old; }
43  be_val operator++(int) { auto old = *this; *this = value() + 1; return old; }
44 
45  template<typename Other> bool operator == (const Other &rhs) const { return value() == static_cast<Type>(rhs); }
46  template<typename Other> bool operator != (const Other &rhs) const { return value() != static_cast<Type>(rhs); }
47  template<typename Other> bool operator >= (const Other &rhs) const { return value() >= static_cast<Type>(rhs); }
48  template<typename Other> bool operator <= (const Other &rhs) const { return value() <= static_cast<Type>(rhs); }
49  template<typename Other> bool operator > (const Other &rhs) const { return value() > static_cast<Type>(rhs); }
50  template<typename Other> bool operator < (const Other &rhs) const { return value() < static_cast<Type>(rhs); }
51 
52  template<typename Other> be_val &operator+=(const Other &rhs) { *this = static_cast<Type>(value() + rhs); return *this; }
53  template<typename Other> be_val &operator-=(const Other &rhs) { *this = static_cast<Type>(value() - rhs); return *this; }
54  template<typename Other> be_val &operator*=(const Other &rhs) { *this = static_cast<Type>(value() * rhs); return *this; }
55  template<typename Other> be_val &operator/=(const Other &rhs) { *this = static_cast<Type>(value() / rhs); return *this; }
56  template<typename Other> be_val &operator%=(const Other &rhs) { *this = static_cast<Type>(value() % rhs); return *this; }
57  template<typename Other> be_val &operator|=(const Other &rhs) { *this = static_cast<Type>(value() | rhs); return *this; }
58  template<typename Other> be_val &operator&=(const Other &rhs) { *this = static_cast<Type>(value() & rhs); return *this; }
59  template<typename Other> be_val &operator^=(const Other &rhs) { *this = static_cast<Type>(value() ^ rhs); return *this; }
60 
61  template<typename Other> Type operator+(const Other &rhs) const { return static_cast<Type>(value() + rhs); }
62  template<typename Other> Type operator-(const Other &rhs) const { return static_cast<Type>(value() - rhs); }
63  template<typename Other> Type operator*(const Other &rhs) const { return static_cast<Type>(value() * rhs); }
64  template<typename Other> Type operator/(const Other &rhs) const { return static_cast<Type>(value() / rhs); }
65  template<typename Other> Type operator%(const Other &rhs) const { return static_cast<Type>(value() % rhs); }
66  template<typename Other> Type operator|(const Other &rhs) const { return static_cast<Type>(value() | rhs); }
67  template<typename Other> Type operator&(const Other &rhs) const { return static_cast<Type>(value() & rhs); }
68  template<typename Other> Type operator^(const Other &rhs) const { return static_cast<Type>(value() ^ rhs); }
69 
70 protected:
72 };
Type operator-(const Other &rhs) const
Definition: be_val.h:62
be_val & operator-=(const Other &rhs)
Definition: be_val.h:53
be_val & operator--()
Definition: be_val.h:41
Type operator/(const Other &rhs) const
Definition: be_val.h:64
bool operator==(const Other &rhs) const
Definition: be_val.h:45
Type operator+(const Other &rhs) const
Definition: be_val.h:61
bool operator!=(const Other &rhs) const
Definition: be_val.h:46
bool operator>(const Other &rhs) const
Definition: be_val.h:49
be_val(Type value)
Definition: be_val.h:18
Type mValue
Definition: be_val.h:71
be_val & operator^=(const Other &rhs)
Definition: be_val.h:59
be_val & operator/=(const Other &rhs)
Definition: be_val.h:55
be_val & operator++()
Definition: be_val.h:40
Type operator*(const Other &rhs) const
Definition: be_val.h:63
Definition: be_val.h:7
be_val operator++(int)
Definition: be_val.h:43
bool operator>=(const Other &rhs) const
Definition: be_val.h:47
be_val operator--(int)
Definition: be_val.h:42
be_val & operator+=(const Other &rhs)
Definition: be_val.h:52
std::enable_if_t< std::is_assignable< Type &, Other >::value, be_val & > operator=(const Other &rhs)
Definition: be_val.h:34
be_val & operator*=(const Other &rhs)
Definition: be_val.h:54
Type operator%(const Other &rhs) const
Definition: be_val.h:65
bool operator<=(const Other &rhs) const
Definition: be_val.h:48
Type byte_swap(Type src)
Definition: utils.h:97
be_val & operator&=(const Other &rhs)
Definition: be_val.h:58
Type value() const
Definition: be_val.h:23
Type operator &(const Other &rhs) const
Definition: be_val.h:67
Type operator|(const Other &rhs) const
Definition: be_val.h:66
GLsizei const GLfloat * value
Definition: glext.h:6709
bool operator<(const Other &rhs) const
Definition: be_val.h:50
be_val & operator%=(const Other &rhs)
Definition: be_val.h:56
Type
Type of JSON value.
Definition: rapidjson.h:603
Type operator^(const Other &rhs) const
Definition: be_val.h:68
be_val()
Definition: be_val.h:14
be_val & operator|=(const Other &rhs)
Definition: be_val.h:57