Browse Source

Variant: add c32 (char32_t) type support

1vanK 3 years ago
parent
commit
4f6d448e35

+ 2 - 0
Source/Urho3D/AngelScript/Generated_Classes.cpp

@@ -2922,6 +2922,8 @@ static void Register_Variant(asIScriptEngine* engine)
 {
     // Variant::Variant(VariantType type, const char* value)
     // Error: type "const char*" can not automatically bind
+    // Variant::Variant(c32 value)
+    // Not registered because have @nobind mark
     // Variant::Variant(const VariantVector& value)
     // Error: type "const VariantVector&" can not automatically bind
     // Variant::Variant(const char* type, const char* value)

+ 11 - 0
Source/Urho3D/AngelScript/Generated_Members.h

@@ -5623,6 +5623,8 @@ template <class T> void RegisterMembers_Variant(asIScriptEngine* engine, const c
     // Only operator == is needed
     // bool Variant::operator !=(unsigned rhs) const
     // Only operator == is needed
+    // bool Variant::operator !=(c32 rhs) const
+    // Only operator == is needed
     // bool Variant::operator !=(long long rhs) const
     // Only operator == is needed
     // bool Variant::operator !=(unsigned long long rhs) const
@@ -5677,12 +5679,16 @@ template <class T> void RegisterMembers_Variant(asIScriptEngine* engine, const c
     // Only operator == is needed
     // bool Variant::operator !=(const Matrix4& rhs) const
     // Only operator == is needed
+    // Variant& Variant::operator =(c32 rhs)
+    // Not registered because have @nobind mark
     // Variant& Variant::operator =(const char* rhs)
     // Error: type "const char*" can not automatically bind
     // Variant& Variant::operator =(void* rhs)
     // Error: type "void*" can not automatically bind
     // Variant& Variant::operator =(const VariantVector& rhs)
     // Error: type "const VariantVector&" can not automatically bind
+    // bool Variant::operator ==(c32 rhs) const
+    // Not registered because have @nobind mark
     // bool Variant::operator ==(void* rhs) const
     // Error: type "void*" can not automatically bind
     // bool Variant::operator ==(const VariantVector& rhs) const
@@ -5707,6 +5713,9 @@ template <class T> void RegisterMembers_Variant(asIScriptEngine* engine, const c
     // const Vector<unsigned char>& Variant::GetBuffer() const
     engine->RegisterObjectMethod(className, "Array<uint8>@ GetBuffer() const", AS_FUNCTION_OBJFIRST(Variant_constspVectorlesunsignedspchargreamp_GetBuffer_void_template<Variant>), AS_CALL_CDECL_OBJFIRST);
 
+    // c32 Variant::GetC32() const
+    engine->RegisterObjectMethod(className, "c32 GetC32() const", AS_METHODPR(T, GetC32, () const, c32), AS_CALL_THISCALL);
+
     // const Color& Variant::GetColor() const
     engine->RegisterObjectMethod(className, "const Color& GetColor() const", AS_METHODPR(T, GetColor, () const, const Color&), AS_CALL_THISCALL);
 
@@ -5987,6 +5996,8 @@ template <class T> void RegisterMembers_Variant(asIScriptEngine* engine, const c
     // Not registered because template
     // template <> unsigned Variant::Get() const
     // Not registered because template
+    // template <> c32 Variant::Get() const
+    // Not registered because template
     // template <> long long Variant::Get() const
     // Not registered because template
     // template <> unsigned long long Variant::Get() const

+ 5 - 0
Source/Urho3D/Core/Variant.cpp

@@ -737,6 +737,11 @@ template <> unsigned Variant::Get<unsigned>() const
     return GetUInt();
 }
 
+template <> c32 Variant::Get<c32>() const
+{
+    return GetC32();
+}
+
 template <> long long Variant::Get<long long>() const
 {
     return GetInt64();

+ 42 - 4
Source/Urho3D/Core/Variant.h

@@ -334,19 +334,28 @@ public:
     /// Construct from unsigned integer.
     Variant(unsigned value)             // NOLINT(google-explicit-constructor)
     {
-        *this = (int)value;
+        *this = value;
+    }
+
+    // c32 not bound because in AngelScript c32 just alias for u32 and c32 conflicts with u32
+
+    /// Construct from Unicode code point.
+    /// @nobind
+    Variant(c32 value)                  // NOLINT(google-explicit-constructor)
+    {
+        *this = value;
     }
 
     /// Construct from unsigned integer.
     Variant(unsigned long long value)   // NOLINT(google-explicit-constructor)
     {
-        *this = (long long)value;
+        *this = value;
     }
 
     /// Construct from a string hash (convert to integer).
     Variant(const StringHash& value)    // NOLINT(google-explicit-constructor)
     {
-        *this = (int)value.Value();
+        *this = value;
     }
 
     /// Construct from a bool.
@@ -589,6 +598,15 @@ public:
         return *this;
     }
 
+    /// Assign from an Unicode code point.
+    /// @nobind
+    Variant& operator =(c32 rhs)
+    {
+        SetType(VAR_INT);
+        value_.int_ = (int)rhs;
+        return *this;
+    }
+
     /// Assign from a StringHash (convert to integer).
     Variant& operator =(const StringHash& rhs)
     {
@@ -817,6 +835,10 @@ public:
     /// Test for equality with an unsigned integer. To return true, both the type and value must match.
     bool operator ==(unsigned rhs) const { return type_ == VAR_INT ? value_.int_ == static_cast<int>(rhs) : false; }
 
+    /// Test for equality with an Unicode code point. To return true, both the type and value must match.
+    /// @nobind
+    bool operator ==(c32 rhs) const { return type_ == VAR_INT ? value_.int_ == static_cast<int>(rhs) : false; }
+
     /// Test for equality with an 64 bit integer. To return true, both the type and value must match.
     bool operator ==(long long rhs) const { return type_ == VAR_INT64 ? value_.int64_ == rhs : false; }
 
@@ -939,7 +961,7 @@ public:
     }
 
     /// Test for equality with a StringHash. To return true, both the type and value must match.
-    bool operator ==(const StringHash& rhs) const { return type_ == VAR_INT ? static_cast<unsigned>(value_.int_) == rhs.Value() : false; }
+    bool operator ==(const StringHash& rhs) const { return type_ == VAR_INT ? static_cast<hash32>(value_.int_) == rhs.Value() : false; }
 
     /// Test for equality with a RefCounted pointer. To return true, both the type and value must match, with the exception that void pointer is also allowed.
     bool operator ==(RefCounted* rhs) const
@@ -979,6 +1001,9 @@ public:
     /// Test for inequality with an unsigned integer.
     bool operator !=(unsigned rhs) const { return !(*this == rhs); }
 
+    /// Test for inequality with an Unicode code point.
+    bool operator !=(c32 rhs) const { return !(*this == rhs); }
+
     /// Test for inequality with an 64 bit integer.
     bool operator !=(long long rhs) const { return !(*this == rhs); }
 
@@ -1131,6 +1156,15 @@ public:
             return 0;
     }
 
+    /// Return Unicode code point or zero on type mismatch.
+    c32 GetC32() const
+    {
+        if (type_ == VAR_INT)
+            return static_cast<c32>(value_.int_);
+        else
+            return 0;
+    }
+
     /// Return StringHash or zero on type mismatch.
     StringHash GetStringHash() const { return StringHash(GetUInt()); }
 
@@ -1406,6 +1440,8 @@ template <> inline VariantType GetVariantType<int>() { return VAR_INT; }
 
 template <> inline VariantType GetVariantType<unsigned>() { return VAR_INT; }
 
+template <> inline VariantType GetVariantType<c32>() { return VAR_INT; }
+
 template <> inline VariantType GetVariantType<long long>() { return VAR_INT64; }
 
 template <> inline VariantType GetVariantType<unsigned long long>() { return VAR_INT64; }
@@ -1461,6 +1497,8 @@ template <> URHO3D_API int Variant::Get<int>() const;
 
 template <> URHO3D_API unsigned Variant::Get<unsigned>() const;
 
+template <> URHO3D_API c32 Variant::Get<c32>() const;
+
 template <> URHO3D_API long long Variant::Get<long long>() const;
 
 template <> URHO3D_API unsigned long long Variant::Get<unsigned long long>() const;