From 250407feda0e837f9fc9bf759a04d76868031e06 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 23 May 2016 18:45:21 +0300 Subject: [PATCH] Minor changes to the LongInt type. --- source/Library/Numeric.cpp | 31 ++++++++++++++++++++++--------- source/Library/Numeric.hpp | 4 ++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/source/Library/Numeric.cpp b/source/Library/Numeric.cpp index 2c6efc8a..e42f0e4e 100644 --- a/source/Library/Numeric.cpp +++ b/source/Library/Numeric.cpp @@ -3,8 +3,9 @@ #include "Library/Random.hpp" // ------------------------------------------------------------------------------------------------ -#include -#include +#include +#include +#include // ------------------------------------------------------------------------------------------------ namespace SqMod { @@ -12,8 +13,14 @@ namespace SqMod { // ------------------------------------------------------------------------------------------------ LongInt< Int64 >::LongInt(CSStr text) : m_Data(0), m_Text() { m_Data = strtoll(text, NULL, 10); } -LongInt< Int64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text() -{ m_Data = strtoll(text, NULL, 10); } +LongInt< Int64 >::LongInt(CSStr text, SQInteger fall) : m_Data(0), m_Text() +{ + m_Data = strtoll(text, NULL, 10); + if (errno == ERANGE) + { + m_Data = ConvTo< Type >::From(fall); + } +} // ------------------------------------------------------------------------------------------------ LongInt< Int64 > & LongInt< Int64 >::operator = (CSStr text) @@ -41,13 +48,19 @@ void LongInt< Int64 >::Random(Type m, Type n) { m_Data = GetRandomInt64(m, n); } // ------------------------------------------------------------------------------------------------ LongInt< Uint64 >::LongInt(CSStr text) : m_Data(0), m_Text() { m_Data = strtoll(text, NULL, 10); } -LongInt< Uint64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text() -{ m_Data = strtoll(text, NULL, 10); } +LongInt< Uint64 >::LongInt(CSStr text, SQInteger fall) : m_Data(0), m_Text() +{ + m_Data = strtoull(text, NULL, 10); + if (errno == ERANGE) + { + m_Data = ConvTo< Type >::From(fall); + } +} // ------------------------------------------------------------------------------------------------ LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text) { - m_Data = strtoll(text, NULL, 10); + m_Data = strtoull(text, NULL, 10); return *this; } @@ -74,7 +87,7 @@ void Register_Numeric(HSQUIRRELVM vm) /* Constructors */ .Ctor() .Ctor< SLongInt::Type >() - .template Ctor< CCStr, Object & >() + .template Ctor< CCStr, SQInteger >() /* Properties */ .Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr) .Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum) @@ -110,7 +123,7 @@ void Register_Numeric(HSQUIRRELVM vm) /* Constructors */ .Ctor() .Ctor< ULongInt::Type >() - .Ctor< CCStr, Object & >() + .Ctor< CCStr, SQInteger >() /* Properties */ .Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr) .Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum) diff --git a/source/Library/Numeric.hpp b/source/Library/Numeric.hpp index abb3130e..f3286b61 100644 --- a/source/Library/Numeric.hpp +++ b/source/Library/Numeric.hpp @@ -37,7 +37,7 @@ public: * */ LongInt(CSStr text); - LongInt(CSStr text, Object & /* null */); + LongInt(CSStr text, SQInteger fall); /* -------------------------------------------------------------------------------------------- * @@ -296,7 +296,7 @@ public: * */ LongInt(CSStr text); - LongInt(CSStr text, Object & /* null */); + LongInt(CSStr text, SQInteger fall); /* -------------------------------------------------------------------------------------------- *