Browse Source

64bit integer variant

Rokas Kupstys 9 years ago
parent
commit
f90dde08fe
1 changed files with 55 additions and 1 deletions
  1. 55 1
      Source/Urho3D/Core/Variant.h

+ 55 - 1
Source/Urho3D/Core/Variant.h

@@ -62,6 +62,7 @@ enum VariantType
     VAR_STRINGVECTOR,
     VAR_RECT,
     VAR_INTVECTOR3,
+    VAR_INT64,
     MAX_VAR_TYPES
 };
 
@@ -214,6 +215,13 @@ public:
         *this = value;
     }
 
+    /// Construct from 64 bit integer.
+    Variant(long long int value) :
+        type_(VAR_NONE)
+    {
+        *this = value;
+    }
+
     /// Construct from unsigned integer.
     Variant(unsigned value) :
         type_(VAR_NONE)
@@ -468,6 +476,22 @@ public:
         return *this;
     }
 
+    /// Assign from 64 bit integer.
+    Variant& operator =(long long int rhs)
+    {
+        SetType(VAR_INT64);
+        *reinterpret_cast<long long int*>(&value_) = rhs;
+        return *this;
+    }
+
+    /// Assign from unsigned 64 bit integer.
+    Variant& operator =(unsigned long long int rhs)
+    {
+        SetType(VAR_INT64);
+        *reinterpret_cast<long long int*>(&value_) = (long long int)rhs;
+        return *this;
+    }
+
     /// Assign from an unsigned integer.
     Variant& operator =(unsigned rhs)
     {
@@ -951,11 +975,41 @@ public:
             return 0;
     }
 
+    /// Return 64 bit int or zero on type mismatch. Floats and doubles are converted.
+    long long int GetInt64() const
+    {
+        if (type_ == VAR_INT64)
+            return *(reinterpret_cast<const long long int*>(&value_));
+        else if (type_ == VAR_INT)
+            return value_.int_;
+        else if (type_ == VAR_FLOAT)
+            return (long long int)value_.float_;
+        else if (type_ == VAR_DOUBLE)
+            return (long long int)*reinterpret_cast<const double*>(&value_);
+        else
+            return 0;
+    }
+
+    /// Return unsigned 64 bit int or zero on type mismatch. Floats and doubles are converted.
+    unsigned long long int GetUInt64() const
+    {
+        if (type_ == VAR_INT64)
+            return *(reinterpret_cast<const unsigned long long int*>(&value_));
+        else if (type_ == VAR_INT)
+            return static_cast<unsigned long long int>(value_.int_);
+        else if (type_ == VAR_FLOAT)
+            return (unsigned long long int)value_.float_;
+        else if (type_ == VAR_DOUBLE)
+            return (unsigned long long int)*reinterpret_cast<const double*>(&value_);
+        else
+            return 0;
+    }
+
     /// Return unsigned int or zero on type mismatch. Floats and doubles are converted.
     unsigned GetUInt() const
     {
         if (type_ == VAR_INT)
-            return value_.int_;
+            return (unsigned)value_.int_;
         else if (type_ == VAR_FLOAT)
             return (unsigned)value_.float_;
         else if (type_ == VAR_DOUBLE)