1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Minor changes to the LongInt type.

This commit is contained in:
Sandu Liviu Catalin 2016-05-23 18:45:21 +03:00
parent c135d4293e
commit 250407feda
2 changed files with 24 additions and 11 deletions

View File

@ -3,8 +3,9 @@
#include "Library/Random.hpp" #include "Library/Random.hpp"
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include <stdio.h> #include <cstdio>
#include <stdlib.h> #include <cerrno>
#include <cstdlib>
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
namespace SqMod { namespace SqMod {
@ -12,8 +13,14 @@ namespace SqMod {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LongInt< Int64 >::LongInt(CSStr text) : m_Data(0), m_Text() LongInt< Int64 >::LongInt(CSStr text) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); } { m_Data = strtoll(text, NULL, 10); }
LongInt< Int64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text() LongInt< Int64 >::LongInt(CSStr text, SQInteger fall) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); } {
m_Data = strtoll(text, NULL, 10);
if (errno == ERANGE)
{
m_Data = ConvTo< Type >::From(fall);
}
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LongInt< Int64 > & LongInt< Int64 >::operator = (CSStr text) 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() LongInt< Uint64 >::LongInt(CSStr text) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); } { m_Data = strtoll(text, NULL, 10); }
LongInt< Uint64 >::LongInt(CSStr text, Object & /* null */) : m_Data(0), m_Text() LongInt< Uint64 >::LongInt(CSStr text, SQInteger fall) : m_Data(0), m_Text()
{ m_Data = strtoll(text, NULL, 10); } {
m_Data = strtoull(text, NULL, 10);
if (errno == ERANGE)
{
m_Data = ConvTo< Type >::From(fall);
}
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text) LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text)
{ {
m_Data = strtoll(text, NULL, 10); m_Data = strtoull(text, NULL, 10);
return *this; return *this;
} }
@ -74,7 +87,7 @@ void Register_Numeric(HSQUIRRELVM vm)
/* Constructors */ /* Constructors */
.Ctor() .Ctor()
.Ctor< SLongInt::Type >() .Ctor< SLongInt::Type >()
.template Ctor< CCStr, Object & >() .template Ctor< CCStr, SQInteger >()
/* Properties */ /* Properties */
.Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr) .Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr)
.Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum) .Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum)
@ -110,7 +123,7 @@ void Register_Numeric(HSQUIRRELVM vm)
/* Constructors */ /* Constructors */
.Ctor() .Ctor()
.Ctor< ULongInt::Type >() .Ctor< ULongInt::Type >()
.Ctor< CCStr, Object & >() .Ctor< CCStr, SQInteger >()
/* Properties */ /* Properties */
.Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr) .Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr)
.Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum) .Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum)

View File

@ -37,7 +37,7 @@ public:
* *
*/ */
LongInt(CSStr text); LongInt(CSStr text);
LongInt(CSStr text, Object & /* null */); LongInt(CSStr text, SQInteger fall);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* *
@ -296,7 +296,7 @@ public:
* *
*/ */
LongInt(CSStr text); LongInt(CSStr text);
LongInt(CSStr text, Object & /* null */); LongInt(CSStr text, SQInteger fall);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* *