From d449247b5e8ddf0b4c4f214fab9457ee1a2a2bbc Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 25 Aug 2016 00:19:53 +0300 Subject: [PATCH] Update the LongInt type to use the new dynamic dispatching system for metamethods. --- source/Library/Numeric/LongInt.cpp | 53 +-- source/Library/Numeric/LongInt.hpp | 693 +++++++++++++++++++++++++++-- 2 files changed, 691 insertions(+), 55 deletions(-) diff --git a/source/Library/Numeric/LongInt.cpp b/source/Library/Numeric/LongInt.cpp index 66c07f29..00b9f732 100644 --- a/source/Library/Numeric/LongInt.cpp +++ b/source/Library/Numeric/LongInt.cpp @@ -2,6 +2,7 @@ #include "Library/Numeric/LongInt.hpp" #include "Library/Numeric/Random.hpp" #include "Base/Shared.hpp" +#include "Base/DynArg.hpp" // ------------------------------------------------------------------------------------------------ #include @@ -20,20 +21,17 @@ SQInteger LongInt< Int64 >::Typename(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -LongInt< Int64 >::LongInt(CSStr text) : m_Data(0), m_Text() +LongInt< Int64 >::LongInt(CSStr text) + : m_Data(0), m_Text() { m_Data = std::strtoll(text, nullptr, 10); } // ------------------------------------------------------------------------------------------------ -LongInt< Int64 >::LongInt(CSStr text, SQInteger fall) : m_Data(0), m_Text() +LongInt< Int64 >::LongInt(CSStr text, Uint32 base) + : m_Data(0), m_Text() { - m_Data = std::strtoll(text, nullptr, 10); - // Simple, check for conversion errors - if (errno == ERANGE) - { - m_Data = ConvTo< Type >::From(fall); - } + m_Data = std::strtoll(text, nullptr, base); } // ------------------------------------------------------------------------------------------------ @@ -81,20 +79,17 @@ SQInteger LongInt< Uint64 >::Typename(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -LongInt< Uint64 >::LongInt(CSStr text) : m_Data(0), m_Text() +LongInt< Uint64 >::LongInt(CSStr text) + : m_Data(0), m_Text() { - m_Data = std::strtoll(text, nullptr, 10); + m_Data = std::strtoull(text, nullptr, 10); } // ------------------------------------------------------------------------------------------------ -LongInt< Uint64 >::LongInt(CSStr text, SQInteger fall) : m_Data(0), m_Text() +LongInt< Uint64 >::LongInt(CSStr text, Uint32 base) + : m_Data(0), m_Text() { - m_Data = std::strtoull(text, nullptr, 10); - // Simple, check for conversion errors - if (errno == ERANGE) - { - m_Data = ConvTo< Type >::From(fall); - } + m_Data = std::strtoull(text, nullptr, base); } // ------------------------------------------------------------------------------------------------ @@ -147,7 +142,7 @@ void Register_LongInt(HSQUIRRELVM vm) // Core Meta-methods .Func(_SC("_tostring"), &SLongInt::ToString) .SquirrelFunc(_SC("_typename"), &SLongInt::Typename) - .Func(_SC("_cmp"), &SLongInt::Cmp) + .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >) // Core Functions .Func(_SC("tointeger"), &SLongInt::ToSqInteger) .Func(_SC("tofloat"), &SLongInt::ToSqFloat) @@ -155,11 +150,11 @@ void Register_LongInt(HSQUIRRELVM vm) .Func(_SC("tobool"), &SLongInt::ToSqBool) .Func(_SC("tochar"), &SLongInt::ToSqChar) // Meta-methods - .Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_add"), &SLongInt::operator +) - .Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_sub"), &SLongInt::operator -) - .Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_mul"), &SLongInt::operator *) - .Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_div"), &SLongInt::operator /) - .Func< SLongInt (SLongInt::*)(const SLongInt &) const >(_SC("_modulo"), &SLongInt::operator %) + .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >) + .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >) + .SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >) + .SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >) + .SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >) .Func< SLongInt (SLongInt::*)(void) const >(_SC("_unm"), &SLongInt::operator -) // Functions .Func(_SC("GetStr"), &SLongInt::GetCStr) @@ -183,7 +178,7 @@ void Register_LongInt(HSQUIRRELVM vm) // Core Meta-methods .Func(_SC("_tostring"), &ULongInt::ToString) .SquirrelFunc(_SC("_typename"), &ULongInt::Typename) - .Func(_SC("_cmp"), &ULongInt::Cmp) + .SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >) // Core Functions .Func(_SC("tointeger"), &ULongInt::ToSqInteger) .Func(_SC("tofloat"), &ULongInt::ToSqFloat) @@ -191,11 +186,11 @@ void Register_LongInt(HSQUIRRELVM vm) .Func(_SC("tobool"), &ULongInt::ToSqBool) .Func(_SC("tochar"), &ULongInt::ToSqChar) // Meta-methods - .Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_add"), &ULongInt::operator +) - .Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_sub"), &ULongInt::operator -) - .Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_mul"), &ULongInt::operator *) - .Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_div"), &ULongInt::operator /) - .Func< ULongInt (ULongInt::*)(const ULongInt &) const >(_SC("_modulo"), &ULongInt::operator %) + .SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >) + .SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >) + .SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >) + .SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >) + .SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >) .Func< ULongInt (ULongInt::*)(void) const >(_SC("_unm"), &ULongInt::operator -) // Functions .Func(_SC("GetStr"), &ULongInt::GetCStr) diff --git a/source/Library/Numeric/LongInt.hpp b/source/Library/Numeric/LongInt.hpp index 9e617a21..0025b4e6 100644 --- a/source/Library/Numeric/LongInt.hpp +++ b/source/Library/Numeric/LongInt.hpp @@ -40,7 +40,7 @@ public: /* -------------------------------------------------------------------------------------------- * Explicit value constructor. */ - LongInt(Type n) + explicit LongInt(Type n) : m_Data(n), m_Text() { /* ... */ @@ -49,12 +49,12 @@ public: /* -------------------------------------------------------------------------------------------- * String encoded constructor. */ - LongInt(CSStr text); + explicit LongInt(CSStr text); /* -------------------------------------------------------------------------------------------- - * String encoded with fall back value constructor. + * String encoded with explicit base constructor. */ - LongInt(CSStr text, SQInteger fall); + LongInt(CSStr text, Uint32 base); /* -------------------------------------------------------------------------------------------- * Copy constructor. @@ -155,41 +155,241 @@ public: /* -------------------------------------------------------------------------------------------- * Adition operator. */ - LongInt< Type > operator + (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator + (const LongInt< U > & o) const { - return LongInt< Type >(m_Data + o.m_Data); + return LongInt< Type >(m_Data + ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Subtraction operator. */ - LongInt< Type > operator - (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator - (const LongInt< U > & o) const { - return LongInt< Type >(m_Data - o.m_Data); + return LongInt< Type >(m_Data - ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Multiplication operator. */ - LongInt< Type > operator * (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator * (const LongInt< U > & o) const { - return LongInt< Type >(m_Data * o.m_Data); + return LongInt< Type >(m_Data * ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Division operator. */ - LongInt< Type > operator / (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator / (const LongInt< U > & o) const { - return LongInt< Type >(m_Data / o.m_Data); + return LongInt< Type >(m_Data / ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Modulus operator. */ - LongInt< Type > operator % (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator % (const LongInt< U > & o) const { - return LongInt< Type >(m_Data % o.m_Data); + return LongInt< Type >(m_Data % ConvTo< Type >::From(o.GetNum())); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (SQInteger s) const + { + return LongInt< Type >(m_Data + ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (SQInteger s) const + { + return LongInt< Type >(m_Data - ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (SQInteger s) const + { + return LongInt< Type >(m_Data * ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (SQInteger s) const + { + return LongInt< Type >(m_Data / ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (SQInteger s) const + { + return LongInt< Type >(m_Data % ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (SQFloat s) const + { + return LongInt< Type >(m_Data + ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (SQFloat s) const + { + return LongInt< Type >(m_Data - ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (SQFloat s) const + { + return LongInt< Type >(m_Data * ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (SQFloat s) const + { + return LongInt< Type >(m_Data / ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (SQFloat s) const + { + return LongInt< Type >(m_Data % ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (bool s) const + { + return LongInt< Type >(m_Data + static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (bool s) const + { + return LongInt< Type >(m_Data - static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (bool s) const + { + return LongInt< Type >(m_Data * static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (bool s) const + { + return LongInt< Type >(m_Data / static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (bool s) const + { + return LongInt< Type >(m_Data % static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (std::nullptr_t) const + { + return LongInt< Type >(m_Data + static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (std::nullptr_t) const + { + return LongInt< Type >(m_Data - static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (std::nullptr_t) const + { + return LongInt< Type >(m_Data * static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (std::nullptr_t) const + { + return LongInt< Type >(static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (std::nullptr_t) const + { + return LongInt< Type >(static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (CSStr str) const + { + return LongInt< Type >(m_Data + ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (CSStr str) const + { + return LongInt< Type >(m_Data - ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (CSStr str) const + { + return LongInt< Type >(m_Data * ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (CSStr str) const + { + return LongInt< Type >(m_Data / ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (CSStr str) const + { + return LongInt< Type >(m_Data % ConvTo< Type >::From(str)); } /* -------------------------------------------------------------------------------------------- @@ -219,6 +419,109 @@ public: } } + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with another one. + */ + Int32 Cmp(const LongInt< Uint64 > & o) const; + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(SQInteger s) const + { + if (m_Data == static_cast< Type >(s)) + { + return 0; + } + else if (m_Data > static_cast< Type >(s)) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(SQFloat s) const + { + if (m_Data == static_cast< Type >(s)) + { + return 0; + } + else if (m_Data > static_cast< Type >(s)) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(bool s) const + { + if (m_Data == static_cast< Type >(s)) + { + return 0; + } + else if (m_Data > static_cast< Type >(s)) + { + return 1; + } + else + { + return -1; + } + } + + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(std::nullptr_t) const + { + if (m_Data == static_cast< Type >(0)) + { + return 0; + } + else if (m_Data > static_cast< Type >(0)) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(CSStr str) const + { + const Type v = ConvTo< Type >::From(str); + + if (m_Data == v) + { + return 0; + } + else if (m_Data > v) + { + return 1; + } + else + { + return -1; + } + } + /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string. */ @@ -367,9 +670,9 @@ public: LongInt(CSStr text); /* -------------------------------------------------------------------------------------------- - * String encoded with fall back value constructor. + * String encoded with explicit base constructor. */ - LongInt(CSStr text, SQInteger fall); + LongInt(CSStr text, Uint32 base); /* -------------------------------------------------------------------------------------------- * Copy constructor. @@ -470,41 +773,241 @@ public: /* -------------------------------------------------------------------------------------------- * Adition operator. */ - LongInt< Type > operator + (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator + (const LongInt< U > & o) const { - return LongInt< Type >(m_Data + o.m_Data); + return LongInt< Type >(m_Data + ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Subtraction operator. */ - LongInt< Type > operator - (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator - (const LongInt< U > & o) const { - return LongInt< Type >(m_Data - o.m_Data); + return LongInt< Type >(m_Data - ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Multiplication operator. */ - LongInt< Type > operator * (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator * (const LongInt< U > & o) const { - return LongInt< Type >(m_Data * o.m_Data); + return LongInt< Type >(m_Data * ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Division operator. */ - LongInt< Type > operator / (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator / (const LongInt< U > & o) const { - return LongInt< Type >(m_Data / o.m_Data); + return LongInt< Type >(m_Data / ConvTo< Type >::From(o.GetNum())); } /* -------------------------------------------------------------------------------------------- * Modulus operator. */ - LongInt< Type > operator % (const LongInt< Type > & o) const + template < typename U > LongInt< Type > operator % (const LongInt< U > & o) const { - return LongInt< Type >(m_Data % o.m_Data); + return LongInt< Type >(m_Data % ConvTo< Type >::From(o.GetNum())); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (SQInteger s) const + { + return LongInt< Type >(m_Data + ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (SQInteger s) const + { + return LongInt< Type >(m_Data - ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (SQInteger s) const + { + return LongInt< Type >(m_Data * ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (SQInteger s) const + { + return LongInt< Type >(m_Data / ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (SQInteger s) const + { + return LongInt< Type >(m_Data % ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (SQFloat s) const + { + return LongInt< Type >(m_Data + ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (SQFloat s) const + { + return LongInt< Type >(m_Data - ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (SQFloat s) const + { + return LongInt< Type >(m_Data * ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (SQFloat s) const + { + return LongInt< Type >(m_Data / ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (SQFloat s) const + { + return LongInt< Type >(m_Data % ConvTo< Type >::From(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (bool s) const + { + return LongInt< Type >(m_Data + static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (bool s) const + { + return LongInt< Type >(m_Data - static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (bool s) const + { + return LongInt< Type >(m_Data * static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (bool s) const + { + return LongInt< Type >(m_Data / static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (bool s) const + { + return LongInt< Type >(m_Data % static_cast< Type >(s)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (std::nullptr_t) const + { + return LongInt< Type >(m_Data + static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (std::nullptr_t) const + { + return LongInt< Type >(m_Data - static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (std::nullptr_t) const + { + return LongInt< Type >(m_Data * static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (std::nullptr_t) const + { + return LongInt< Type >(static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (std::nullptr_t) const + { + return LongInt< Type >(static_cast< Type >(0)); + } + + /* -------------------------------------------------------------------------------------------- + * Adition operator. + */ + LongInt< Type > operator + (CSStr str) const + { + return LongInt< Type >(m_Data + ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Subtraction operator. + */ + LongInt< Type > operator - (CSStr str) const + { + return LongInt< Type >(m_Data - ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Multiplication operator. + */ + LongInt< Type > operator * (CSStr str) const + { + return LongInt< Type >(m_Data * ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Division operator. + */ + LongInt< Type > operator / (CSStr str) const + { + return LongInt< Type >(m_Data / ConvTo< Type >::From(str)); + } + + /* -------------------------------------------------------------------------------------------- + * Modulus operator. + */ + LongInt< Type > operator % (CSStr str) const + { + return LongInt< Type >(m_Data % ConvTo< Type >::From(str)); } /* -------------------------------------------------------------------------------------------- @@ -534,6 +1037,125 @@ public: } } + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with another one. + */ + Int32 Cmp(const LongInt< Int64 > & o) const + { + const Type v = ConvTo< Type >::From(o.GetNum()); + + if (m_Data == v) + { + return 0; + } + else if (m_Data > v) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(SQInteger s) const + { + if (m_Data == static_cast< Type >(s)) + { + return 0; + } + else if (m_Data > static_cast< Type >(s)) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(SQFloat s) const + { + if (m_Data == static_cast< Type >(s)) + { + return 0; + } + else if (m_Data > static_cast< Type >(s)) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(bool s) const + { + if (m_Data == static_cast< Type >(s)) + { + return 0; + } + else if (m_Data > static_cast< Type >(s)) + { + return 1; + } + else + { + return -1; + } + } + + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(std::nullptr_t) const + { + if (m_Data == static_cast< Type >(0)) + { + return 0; + } + else if (m_Data > static_cast< Type >(0)) + { + return 1; + } + else + { + return -1; + } + } + + /* -------------------------------------------------------------------------------------------- + * Used by the script engine to compare an instance of this type with a scalar value. + */ + Int32 Cmp(CSStr str) const + { + const Type v = ConvTo< Type >::From(str); + + if (m_Data == v) + { + return 0; + } + else if (m_Data > v) + { + return 1; + } + else + { + return -1; + } + } + /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string. */ @@ -640,6 +1262,25 @@ public: } }; +// ------------------------------------------------------------------------------------------------ +inline Int32 LongInt< Int64 >::Cmp(const LongInt< Uint64 > & o) const +{ + const Type v = ConvTo< Type >::From(o.GetNum()); + + if (m_Data == v) + { + return 0; + } + else if (m_Data > v) + { + return 1; + } + else + { + return -1; + } +} + // ------------------------------------------------------------------------------------------------ typedef LongInt< Int64 > SLongInt; typedef LongInt< Uint64 > ULongInt;