[C++11] Replace BEInt.set() with operator=

This commit is contained in:
Behdad Esfahbod 2019-03-29 17:57:24 -07:00
parent 0aa59b1de3
commit 9a5b15dc1e
2 changed files with 15 additions and 8 deletions

View File

@ -682,7 +682,11 @@ template <typename Type>
struct BEInt<Type, 1> struct BEInt<Type, 1>
{ {
public: public:
void set (Type V) { v = V; } BEInt<Type, 1>& operator = (Type V)
{
v = V;
return *this;
}
operator Type () const { return v; } operator Type () const { return v; }
private: uint8_t v; private: uint8_t v;
}; };
@ -690,10 +694,11 @@ template <typename Type>
struct BEInt<Type, 2> struct BEInt<Type, 2>
{ {
public: public:
void set (Type V) BEInt<Type, 2>& operator = (Type V)
{ {
v[0] = (V >> 8) & 0xFF; v[0] = (V >> 8) & 0xFF;
v[1] = (V ) & 0xFF; v[1] = (V ) & 0xFF;
return *this;
} }
operator Type () const operator Type () const
{ {
@ -718,11 +723,12 @@ template <typename Type>
struct BEInt<Type, 3> struct BEInt<Type, 3>
{ {
public: public:
void set (Type V) BEInt<Type, 3>& operator = (Type V)
{ {
v[0] = (V >> 16) & 0xFF; v[0] = (V >> 16) & 0xFF;
v[1] = (V >> 8) & 0xFF; v[1] = (V >> 8) & 0xFF;
v[2] = (V ) & 0xFF; v[2] = (V ) & 0xFF;
return *this;
} }
operator Type () const operator Type () const
{ {
@ -737,12 +743,13 @@ struct BEInt<Type, 4>
{ {
public: public:
typedef Type type; typedef Type type;
void set (Type V) BEInt<Type, 4>& operator = (Type V)
{ {
v[0] = (V >> 24) & 0xFF; v[0] = (V >> 24) & 0xFF;
v[1] = (V >> 16) & 0xFF; v[1] = (V >> 16) & 0xFF;
v[2] = (V >> 8) & 0xFF; v[2] = (V >> 8) & 0xFF;
v[3] = (V ) & 0xFF; v[3] = (V ) & 0xFF;
return *this;
} }
operator Type () const operator Type () const
{ {

View File

@ -59,8 +59,8 @@ struct IntType
typedef Type type; typedef Type type;
typedef typename hb_signedness_int (hb_is_signed (Type)) wide_type; typedef typename hb_signedness_int (hb_is_signed (Type)) wide_type;
IntType<Type, Size>& operator = (wide_type i) { v.set (i); return *this; } IntType<Type, Size>& operator = (wide_type i) { v = i; return *this; }
void set (wide_type i) { v.set (i); } void set (wide_type i) { v = i; }
operator wide_type () const { return v; } operator wide_type () const { return v; }
bool operator == (const IntType<Type,Size> &o) const { return (Type) v == (Type) o.v; } bool operator == (const IntType<Type,Size> &o) const { return (Type) v == (Type) o.v; }
bool operator != (const IntType<Type,Size> &o) const { return !(*this == o); } bool operator != (const IntType<Type,Size> &o) const { return !(*this == o); }
@ -109,7 +109,7 @@ struct F2DOT14 : HBINT16
{ {
// 16384 means 1<<14 // 16384 means 1<<14
float to_float () const { return ((int32_t) v) / 16384.f; } float to_float () const { return ((int32_t) v) / 16384.f; }
void set_float (float f) { v.set (round (f * 16384.f)); } void set_float (float f) { v = round (f * 16384.f); }
public: public:
DEFINE_SIZE_STATIC (2); DEFINE_SIZE_STATIC (2);
}; };
@ -119,7 +119,7 @@ struct Fixed : HBINT32
{ {
// 65536 means 1<<16 // 65536 means 1<<16
float to_float () const { return ((int32_t) v) / 65536.f; } float to_float () const { return ((int32_t) v) / 65536.f; }
void set_float (float f) { v.set (round (f * 65536.f)); } void set_float (float f) { v = round (f * 65536.f); }
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_STATIC (4);
}; };