mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-08-06 08:01:47 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
@@ -1,44 +1,42 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Numeric/LongInt.hpp"
|
||||
#include "Library/Numeric/Long.hpp"
|
||||
#include "Library/Numeric/Random.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/DynArg.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cstdio>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMODE_DECL_TYPENAME(TypenameS, _SC("SLongInt"))
|
||||
SQMODE_DECL_TYPENAME(TypenameU, _SC("ULongInt"))
|
||||
SQMOD_DECL_TYPENAME(TypenameS, _SC("SLongInt"))
|
||||
SQMOD_DECL_TYPENAME(TypenameU, _SC("ULongInt"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Int64 >::LongInt(CSStr text)
|
||||
LongInt< int64_t >::LongInt(const SQChar * text)
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
m_Data = std::strtoll(text, nullptr, 10);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Int64 >::LongInt(CSStr text, Uint32 base)
|
||||
LongInt< int64_t >::LongInt(const SQChar * text, uint32_t base)
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
m_Data = std::strtoll(text, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Int64 > & LongInt< Int64 >::operator = (CSStr text)
|
||||
LongInt< int64_t > & LongInt< int64_t >::operator = (const SQChar * text)
|
||||
{
|
||||
m_Data = std::strtoll(text, nullptr, 10);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr LongInt< Int64 >::ToString()
|
||||
const SQChar * LongInt< int64_t >::ToString()
|
||||
{
|
||||
if (std::snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
|
||||
{
|
||||
@@ -49,46 +47,46 @@ CSStr LongInt< Int64 >::ToString()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Int64 >::Random()
|
||||
void LongInt< int64_t >::Random()
|
||||
{
|
||||
m_Data = GetRandomInt64();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Int64 >::Random(Type n)
|
||||
void LongInt< int64_t >::Random(Type n)
|
||||
{
|
||||
m_Data = GetRandomInt64(n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Int64 >::Random(Type m, Type n)
|
||||
void LongInt< int64_t >::Random(Type m, Type n)
|
||||
{
|
||||
m_Data = GetRandomInt64(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Uint64 >::LongInt(CSStr text)
|
||||
LongInt< uint64_t >::LongInt(const SQChar * text)
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
m_Data = std::strtoull(text, nullptr, 10);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Uint64 >::LongInt(CSStr text, Uint32 base)
|
||||
LongInt< uint64_t >::LongInt(const SQChar * text, uint32_t base)
|
||||
: m_Data(0), m_Text()
|
||||
{
|
||||
m_Data = std::strtoull(text, nullptr, base);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LongInt< Uint64 > & LongInt< Uint64 >::operator = (CSStr text)
|
||||
LongInt< uint64_t > & LongInt< uint64_t >::operator = (const SQChar * text)
|
||||
{
|
||||
m_Data = std::strtoull(text, nullptr, 10);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
CSStr LongInt< Uint64 >::ToString()
|
||||
const SQChar * LongInt< uint64_t >::ToString()
|
||||
{
|
||||
if (std::snprintf(m_Text, sizeof(m_Text), "%llu", m_Data) < 0)
|
||||
{
|
||||
@@ -99,25 +97,25 @@ CSStr LongInt< Uint64 >::ToString()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Uint64 >::Random()
|
||||
void LongInt< uint64_t >::Random()
|
||||
{
|
||||
m_Data = GetRandomUint64();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Uint64 >::Random(Type n)
|
||||
void LongInt< uint64_t >::Random(Type n)
|
||||
{
|
||||
m_Data = GetRandomUint64(n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void LongInt< Uint64 >::Random(Type m, Type n)
|
||||
void LongInt< uint64_t >::Random(Type m, Type n)
|
||||
{
|
||||
m_Data = GetRandomUint64(m, n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
// Identify which type must be extracted
|
||||
switch (sq_gettype(vm, idx))
|
||||
@@ -126,23 +124,23 @@ Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return static_cast< Int64 >(val);
|
||||
} break;
|
||||
return static_cast< int64_t >(val);
|
||||
}
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< Int64 >::From(val);
|
||||
} break;
|
||||
return ConvTo< int64_t >::From(val);
|
||||
}
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return static_cast< Int64 >(val);
|
||||
} break;
|
||||
return static_cast< int64_t >(val);
|
||||
}
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
const SQChar * val = nullptr;
|
||||
// Attempt to retrieve and convert the string
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
||||
{
|
||||
@@ -154,8 +152,8 @@ Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return static_cast< Int64 >(sq_getsize(vm, idx));
|
||||
} break;
|
||||
return static_cast< int64_t >(sq_getsize(vm, idx));
|
||||
}
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Attempt to treat the value as a signed long instance
|
||||
@@ -170,15 +168,15 @@ Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
// Attempt to treat the value as a unsigned long instance
|
||||
try
|
||||
{
|
||||
return ConvTo< Int64 >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
|
||||
return ConvTo< int64_t >::From(Var< const ULongInt & >(vm, idx).value.GetNum());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fall back
|
||||
return static_cast< Int64 >(sq_getsize(vm, idx));
|
||||
} break;
|
||||
return static_cast< int64_t >(sq_getsize(vm, idx));
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
@@ -186,7 +184,7 @@ Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
// Identify which type must be extracted
|
||||
switch (sq_gettype(vm, idx))
|
||||
@@ -195,23 +193,23 @@ Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
SQInteger val;
|
||||
sq_getinteger(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
return ConvTo< uint64_t >::From(val);
|
||||
}
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat val;
|
||||
sq_getfloat(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
return ConvTo< uint64_t >::From(val);
|
||||
}
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool val;
|
||||
sq_getbool(vm, idx, &val);
|
||||
return ConvTo< Uint64 >::From(val);
|
||||
} break;
|
||||
return ConvTo< uint64_t >::From(val);
|
||||
}
|
||||
case OT_STRING:
|
||||
{
|
||||
CSStr val = nullptr;
|
||||
const SQChar * val = nullptr;
|
||||
// Attempt to retrieve and convert the string
|
||||
if (SQ_SUCCEEDED(sq_getstring(vm, idx, &val)) && val != nullptr && *val != '\0')
|
||||
{
|
||||
@@ -223,14 +221,14 @@ Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
case OT_CLASS:
|
||||
case OT_USERDATA:
|
||||
{
|
||||
return ConvTo< Uint64 >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
return ConvTo< uint64_t >::From(sq_getsize(vm, idx));
|
||||
}
|
||||
case OT_INSTANCE:
|
||||
{
|
||||
// Attempt to treat the value as a signed long instance
|
||||
try
|
||||
{
|
||||
return ConvTo< Uint64 >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
|
||||
return ConvTo< uint64_t >::From(Var< const SLongInt & >(vm, idx).value.GetNum());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -246,8 +244,8 @@ Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx)
|
||||
// Just ignore it...
|
||||
}
|
||||
// Attempt to get the size of the instance as a fall back
|
||||
return ConvTo< Uint64 >::From(sq_getsize(vm, idx));
|
||||
} break;
|
||||
return ConvTo< uint64_t >::From(sq_getsize(vm, idx));
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
// Default to 0
|
||||
@@ -262,14 +260,14 @@ const SLongInt & GetSLongInt()
|
||||
return l;
|
||||
}
|
||||
|
||||
const SLongInt & GetSLongInt(Int64 n)
|
||||
const SLongInt & GetSLongInt(int64_t n)
|
||||
{
|
||||
static SLongInt l;
|
||||
l.SetNum(n);
|
||||
return l;
|
||||
}
|
||||
|
||||
const SLongInt & GetSLongInt(CSStr s)
|
||||
const SLongInt & GetSLongInt(const SQChar * s)
|
||||
{
|
||||
static SLongInt l;
|
||||
l = s;
|
||||
@@ -283,14 +281,14 @@ const ULongInt & GetULongInt()
|
||||
return l;
|
||||
}
|
||||
|
||||
const ULongInt & GetULongInt(Uint64 n)
|
||||
const ULongInt & GetULongInt(uint64_t n)
|
||||
{
|
||||
static ULongInt l;
|
||||
l.SetNum(n);
|
||||
return l;
|
||||
}
|
||||
|
||||
const ULongInt & GetULongInt(CSStr s)
|
||||
const ULongInt & GetULongInt(const SQChar * s)
|
||||
{
|
||||
static ULongInt l;
|
||||
l = s;
|
||||
@@ -305,12 +303,12 @@ void Register_LongInt(HSQUIRRELVM vm)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SLongInt::Type >()
|
||||
.template Ctor< CCStr, SQInteger >()
|
||||
.template Ctor< const char *, SQInteger >()
|
||||
// Properties
|
||||
.Prop(_SC("Str"), &SLongInt::GetCStr, &SLongInt::SetStr)
|
||||
.Prop(_SC("Num"), &SLongInt::GetSNum, &SLongInt::SetNum)
|
||||
// Core Meta-methods
|
||||
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, SLongInt, ULongInt >)
|
||||
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, SLongInt, ULongInt >)
|
||||
.SquirrelFunc(_SC("_typename"), &TypenameS::Fn)
|
||||
.Func(_SC("_tostring"), &SLongInt::ToString)
|
||||
// Core Functions
|
||||
@@ -320,11 +318,11 @@ void Register_LongInt(HSQUIRRELVM vm)
|
||||
.Func(_SC("tobool"), &SLongInt::ToSqBool)
|
||||
.Func(_SC("tochar"), &SLongInt::ToSqChar)
|
||||
// Meta-methods
|
||||
.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 >)
|
||||
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, SLongInt, ULongInt >)
|
||||
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, SLongInt, ULongInt >)
|
||||
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, SLongInt, ULongInt >)
|
||||
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, SLongInt, ULongInt >)
|
||||
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< SLongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, SLongInt, ULongInt >)
|
||||
.Func< SLongInt (SLongInt::*)(void) const >(_SC("_unm"), &SLongInt::operator -)
|
||||
// Functions
|
||||
.Func(_SC("GetStr"), &SLongInt::GetCStr)
|
||||
@@ -342,12 +340,12 @@ void Register_LongInt(HSQUIRRELVM vm)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< ULongInt::Type >()
|
||||
.Ctor< CCStr, SQInteger >()
|
||||
.Ctor< const char *, SQInteger >()
|
||||
// Properties
|
||||
.Prop(_SC("Str"), &ULongInt::GetCStr, &ULongInt::SetStr)
|
||||
.Prop(_SC("Num"), &ULongInt::GetSNum, &ULongInt::SetNum)
|
||||
// Core Meta-methods
|
||||
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, CSStr, ULongInt, SLongInt >)
|
||||
.SquirrelFunc(_SC("cmp"), &SqDynArgFwd< SqDynArgCmpFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, ULongInt, SLongInt >)
|
||||
.SquirrelFunc(_SC("_typename"), &TypenameU::Fn)
|
||||
.Func(_SC("_tostring"), &ULongInt::ToString)
|
||||
// Core Functions
|
||||
@@ -357,11 +355,11 @@ void Register_LongInt(HSQUIRRELVM vm)
|
||||
.Func(_SC("tobool"), &ULongInt::ToSqBool)
|
||||
.Func(_SC("tochar"), &ULongInt::ToSqChar)
|
||||
// Meta-methods
|
||||
.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 >)
|
||||
.SquirrelFunc(_SC("_add"), &SqDynArgFwd< SqDynArgAddFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, ULongInt, SLongInt >)
|
||||
.SquirrelFunc(_SC("_sub"), &SqDynArgFwd< SqDynArgSubFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, ULongInt, SLongInt >)
|
||||
.SquirrelFunc(_SC("_mul"), &SqDynArgFwd< SqDynArgMulFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, ULongInt, SLongInt >)
|
||||
.SquirrelFunc(_SC("_div"), &SqDynArgFwd< SqDynArgDivFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, ULongInt, SLongInt >)
|
||||
.SquirrelFunc(_SC("_modulo"), &SqDynArgFwd< SqDynArgModFn< ULongInt >, SQInteger, SQFloat, bool, std::nullptr_t, const SQChar *, ULongInt, SLongInt >)
|
||||
.Func< ULongInt (ULongInt::*)(void) const >(_SC("_unm"), &ULongInt::operator -)
|
||||
// Functions
|
||||
.Func(_SC("GetStr"), &ULongInt::GetCStr)
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
@@ -12,18 +12,18 @@ template < typename T > class LongInt;
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Specialization of the Long int class for signed integers.
|
||||
*/
|
||||
template <> class LongInt< Int64 >
|
||||
template <> class LongInt< int64_t >
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Int64 Type; // The specialized type.
|
||||
typedef int64_t Type; // The specialized type.
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Type m_Data; // The assigned value.
|
||||
SQChar m_Text[32]; // String representation of the value.
|
||||
SQChar m_Text[24]; // String representation of the value.
|
||||
|
||||
public:
|
||||
|
||||
@@ -48,12 +48,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String encoded constructor.
|
||||
*/
|
||||
explicit LongInt(CSStr text);
|
||||
explicit LongInt(const SQChar * text);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String encoded with explicit base constructor.
|
||||
*/
|
||||
LongInt(CSStr text, Uint32 base);
|
||||
LongInt(const SQChar * text, uint32_t base);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
@@ -67,15 +67,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~LongInt()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
~LongInt() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
LongInt & operator = (const LongInt< Type > & o)
|
||||
LongInt & operator = (const LongInt< Type > & o) // NOLINT(bugprone-unhandled-self-assignment)
|
||||
{
|
||||
m_Data = o.m_Data;
|
||||
return *this;
|
||||
@@ -93,7 +90,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assignment operator.
|
||||
*/
|
||||
LongInt< Type > & operator = (CSStr text);
|
||||
LongInt< Type > & operator = (const SQChar * text);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality comparison operator.
|
||||
@@ -146,13 +143,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to the specialized type.
|
||||
*/
|
||||
operator Type () const
|
||||
operator Type () const // NOLINT(google-explicit-constructor)
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
template < typename U > LongInt< Type > operator + (const LongInt< U > & o) const
|
||||
{
|
||||
@@ -192,7 +189,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (SQInteger s) const
|
||||
{
|
||||
@@ -232,7 +229,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (SQFloat s) const
|
||||
{
|
||||
@@ -272,7 +269,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (bool s) const
|
||||
{
|
||||
@@ -312,7 +309,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (std::nullptr_t) const
|
||||
{
|
||||
@@ -352,9 +349,9 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (CSStr str) const
|
||||
LongInt< Type > operator + (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data + ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -362,7 +359,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Subtraction operator.
|
||||
*/
|
||||
LongInt< Type > operator - (CSStr str) const
|
||||
LongInt< Type > operator - (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data - ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -370,7 +367,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Multiplication operator.
|
||||
*/
|
||||
LongInt< Type > operator * (CSStr str) const
|
||||
LongInt< Type > operator * (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data * ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -378,7 +375,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Division operator.
|
||||
*/
|
||||
LongInt< Type > operator / (CSStr str) const
|
||||
LongInt< Type > operator / (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data / ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -386,13 +383,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modulus operator.
|
||||
*/
|
||||
LongInt< Type > operator % (CSStr str) const
|
||||
LongInt< Type > operator % (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data % ConvTo< Type >::From(str));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Unarry minus operator.
|
||||
* Unary minus operator.
|
||||
*/
|
||||
LongInt< Type > operator - () const
|
||||
{
|
||||
@@ -402,7 +399,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const LongInt< Type > & o) const
|
||||
SQMOD_NODISCARD int32_t Cmp(const LongInt< Type > & o) const
|
||||
{
|
||||
if (m_Data == o.m_Data)
|
||||
{
|
||||
@@ -421,12 +418,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with another one.
|
||||
*/
|
||||
Int32 Cmp(const LongInt< Uint64 > & o) const;
|
||||
SQMOD_NODISCARD int32_t Cmp(const LongInt< uint64_t > & o) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(SQInteger s) const
|
||||
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(s))
|
||||
{
|
||||
@@ -445,7 +442,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(SQFloat s) const
|
||||
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(s))
|
||||
{
|
||||
@@ -464,7 +461,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(bool s) const
|
||||
SQMOD_NODISCARD int32_t Cmp(bool s) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(s))
|
||||
{
|
||||
@@ -484,7 +481,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(std::nullptr_t) const
|
||||
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(0))
|
||||
{
|
||||
@@ -503,7 +500,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(CSStr str) const
|
||||
SQMOD_NODISCARD int32_t Cmp(const SQChar * str) const
|
||||
{
|
||||
const Type v = ConvTo< Type >::From(str);
|
||||
|
||||
@@ -524,7 +521,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
CSStr ToString();
|
||||
const SQChar * ToString();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign an integer value.
|
||||
@@ -537,7 +534,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an the specialized value.
|
||||
*/
|
||||
Type GetNum() const
|
||||
SQMOD_NODISCARD Type GetNum() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
@@ -545,7 +542,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an a Squirrel integer value.
|
||||
*/
|
||||
SQInteger GetSNum() const
|
||||
SQMOD_NODISCARD SQInteger GetSNum() const
|
||||
{
|
||||
return ClampL< Type, SQInteger >(m_Data);
|
||||
}
|
||||
@@ -553,7 +550,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign a string value.
|
||||
*/
|
||||
void SetStr(CSStr text)
|
||||
void SetStr(const SQChar * text)
|
||||
{
|
||||
*this = text;
|
||||
}
|
||||
@@ -561,7 +558,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a string value.
|
||||
*/
|
||||
CSStr GetCStr()
|
||||
const SQChar * GetCStr()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
@@ -584,7 +581,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel integer.
|
||||
*/
|
||||
SQInteger ToSqInteger() const
|
||||
SQMOD_NODISCARD SQInteger ToSqInteger() const
|
||||
{
|
||||
return ClampL< Type, SQInteger >(m_Data);
|
||||
}
|
||||
@@ -592,15 +589,15 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel float.
|
||||
*/
|
||||
SQFloat ToSqFloat() const
|
||||
SQMOD_NODISCARD SQFloat ToSqFloat() const
|
||||
{
|
||||
return ClampL< Float64, SQFloat >(static_cast< Float64 >(m_Data));
|
||||
return ClampL< double, SQFloat >(static_cast< double >(m_Data));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel string.
|
||||
*/
|
||||
CSStr ToSqString()
|
||||
const SQChar * ToSqString()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
@@ -608,7 +605,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel boolean.
|
||||
*/
|
||||
bool ToSqBool() const
|
||||
SQMOD_NODISCARD bool ToSqBool() const
|
||||
{
|
||||
return (m_Data > 0);
|
||||
}
|
||||
@@ -616,7 +613,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel character.
|
||||
*/
|
||||
SQChar ToSqChar() const
|
||||
SQMOD_NODISCARD SQChar ToSqChar() const
|
||||
{
|
||||
return ClampL< Type, SQChar >(m_Data);
|
||||
}
|
||||
@@ -625,18 +622,18 @@ public:
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Specialization of the Long int class for unsigned integers.
|
||||
*/
|
||||
template <> class LongInt< Uint64 >
|
||||
template <> class LongInt< uint64_t >
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef Uint64 Type; // The specialized type.
|
||||
typedef uint64_t Type; // The specialized type.
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Type m_Data; // The assigned value.
|
||||
SQChar m_Text[32]; // String representation of the value.
|
||||
SQChar m_Text[24]; // String representation of the value.
|
||||
|
||||
public:
|
||||
|
||||
@@ -652,7 +649,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit value constructor.
|
||||
*/
|
||||
LongInt(Type n)
|
||||
explicit LongInt(Type n)
|
||||
: m_Data(n), m_Text()
|
||||
{
|
||||
/* ... */
|
||||
@@ -661,12 +658,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String encoded constructor.
|
||||
*/
|
||||
LongInt(CSStr text);
|
||||
explicit LongInt(const SQChar * text);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String encoded with explicit base constructor.
|
||||
*/
|
||||
LongInt(CSStr text, Uint32 base);
|
||||
LongInt(const SQChar * text, uint32_t base);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
@@ -680,15 +677,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~LongInt()
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
~LongInt() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
LongInt & operator = (const LongInt< Type > & o)
|
||||
LongInt & operator = (const LongInt< Type > & o) // NOLINT(bugprone-unhandled-self-assignment)
|
||||
{
|
||||
m_Data = o.m_Data;
|
||||
return *this;
|
||||
@@ -706,7 +700,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assignment operator.
|
||||
*/
|
||||
LongInt< Type > & operator = (CSStr text);
|
||||
LongInt< Type > & operator = (const SQChar * text);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Equality comparison operator.
|
||||
@@ -759,13 +753,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Implicit conversion to the specialized type.
|
||||
*/
|
||||
operator Type () const
|
||||
operator Type () const // NOLINT(google-explicit-constructor)
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
template < typename U > LongInt< Type > operator + (const LongInt< U > & o) const
|
||||
{
|
||||
@@ -805,7 +799,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (SQInteger s) const
|
||||
{
|
||||
@@ -845,7 +839,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (SQFloat s) const
|
||||
{
|
||||
@@ -885,7 +879,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (bool s) const
|
||||
{
|
||||
@@ -925,7 +919,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (std::nullptr_t) const
|
||||
{
|
||||
@@ -965,9 +959,9 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Adition operator.
|
||||
* Addition operator.
|
||||
*/
|
||||
LongInt< Type > operator + (CSStr str) const
|
||||
LongInt< Type > operator + (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data + ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -975,7 +969,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Subtraction operator.
|
||||
*/
|
||||
LongInt< Type > operator - (CSStr str) const
|
||||
LongInt< Type > operator - (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data - ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -983,7 +977,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Multiplication operator.
|
||||
*/
|
||||
LongInt< Type > operator * (CSStr str) const
|
||||
LongInt< Type > operator * (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data * ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -991,7 +985,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Division operator.
|
||||
*/
|
||||
LongInt< Type > operator / (CSStr str) const
|
||||
LongInt< Type > operator / (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data / ConvTo< Type >::From(str));
|
||||
}
|
||||
@@ -999,13 +993,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modulus operator.
|
||||
*/
|
||||
LongInt< Type > operator % (CSStr str) const
|
||||
LongInt< Type > operator % (const SQChar * str) const
|
||||
{
|
||||
return LongInt< Type >(m_Data % ConvTo< Type >::From(str));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Unarry minus operator.
|
||||
* Unary minus operator.
|
||||
*/
|
||||
LongInt< Type > operator - () const
|
||||
{
|
||||
@@ -1015,7 +1009,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare two instances of this type.
|
||||
*/
|
||||
Int32 Cmp(const LongInt< Type > & o) const
|
||||
SQMOD_NODISCARD int32_t Cmp(const LongInt< Type > & o) const
|
||||
{
|
||||
if (m_Data == o.m_Data)
|
||||
{
|
||||
@@ -1034,7 +1028,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with another one.
|
||||
*/
|
||||
Int32 Cmp(const LongInt< Int64 > & o) const
|
||||
SQMOD_NODISCARD int32_t Cmp(const LongInt< int64_t > & o) const
|
||||
{
|
||||
const Type v = ConvTo< Type >::From(o.GetNum());
|
||||
|
||||
@@ -1055,7 +1049,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(SQInteger s) const
|
||||
SQMOD_NODISCARD int32_t Cmp(SQInteger s) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(s))
|
||||
{
|
||||
@@ -1074,7 +1068,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(SQFloat s) const
|
||||
SQMOD_NODISCARD int32_t Cmp(SQFloat s) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(s))
|
||||
{
|
||||
@@ -1093,7 +1087,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(bool s) const
|
||||
SQMOD_NODISCARD int32_t Cmp(bool s) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(s))
|
||||
{
|
||||
@@ -1113,7 +1107,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(std::nullptr_t) const
|
||||
SQMOD_NODISCARD int32_t Cmp(std::nullptr_t) const
|
||||
{
|
||||
if (m_Data == static_cast< Type >(0))
|
||||
{
|
||||
@@ -1132,7 +1126,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to compare an instance of this type with a scalar value.
|
||||
*/
|
||||
Int32 Cmp(CSStr str) const
|
||||
SQMOD_NODISCARD int32_t Cmp(const SQChar * str) const
|
||||
{
|
||||
const Type v = ConvTo< Type >::From(str);
|
||||
|
||||
@@ -1153,7 +1147,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
CSStr ToString();
|
||||
const SQChar * ToString();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign an integer value.
|
||||
@@ -1166,7 +1160,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an the specialized value.
|
||||
*/
|
||||
Type GetNum() const
|
||||
SQMOD_NODISCARD Type GetNum() const
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
@@ -1174,7 +1168,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve an a Squirrel integer value.
|
||||
*/
|
||||
SQInteger GetSNum() const
|
||||
SQMOD_NODISCARD SQInteger GetSNum() const
|
||||
{
|
||||
return (SQInteger)(m_Data);
|
||||
}
|
||||
@@ -1182,7 +1176,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign a string value.
|
||||
*/
|
||||
void SetStr(CSStr text)
|
||||
void SetStr(const SQChar * text)
|
||||
{
|
||||
*this = text;
|
||||
}
|
||||
@@ -1190,7 +1184,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a string value.
|
||||
*/
|
||||
CSStr GetCStr()
|
||||
const SQChar * GetCStr()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
@@ -1213,7 +1207,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel integer.
|
||||
*/
|
||||
SQInteger ToSqInteger() const
|
||||
SQMOD_NODISCARD SQInteger ToSqInteger() const
|
||||
{
|
||||
return ClampL< Type, SQInteger >(m_Data);
|
||||
}
|
||||
@@ -1221,15 +1215,15 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel float.
|
||||
*/
|
||||
SQFloat ToSqFloat() const
|
||||
SQMOD_NODISCARD SQFloat ToSqFloat() const
|
||||
{
|
||||
return ClampL< Float64, SQFloat >(static_cast< Float64 >(m_Data));
|
||||
return ClampL< double, SQFloat >(static_cast< double >(m_Data));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel string.
|
||||
*/
|
||||
CSStr ToSqString()
|
||||
const SQChar * ToSqString()
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
@@ -1237,7 +1231,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel boolean.
|
||||
*/
|
||||
bool ToSqBool() const
|
||||
SQMOD_NODISCARD bool ToSqBool() const
|
||||
{
|
||||
return (m_Data > 0);
|
||||
}
|
||||
@@ -1245,14 +1239,14 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to convert the long integer to a squirrel character.
|
||||
*/
|
||||
SQChar ToSqChar() const
|
||||
SQMOD_NODISCARD SQChar ToSqChar() const
|
||||
{
|
||||
return ClampL< Type, SQChar >(m_Data);
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
inline Int32 LongInt< Int64 >::Cmp(const LongInt< Uint64 > & o) const
|
||||
inline int32_t LongInt< int64_t >::Cmp(const LongInt< uint64_t > & o) const
|
||||
{
|
||||
const Type v = ConvTo< Type >::From(o.GetNum());
|
||||
|
||||
@@ -1271,27 +1265,27 @@ inline Int32 LongInt< Int64 >::Cmp(const LongInt< Uint64 > & o) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
typedef LongInt< Int64 > SLongInt;
|
||||
typedef LongInt< Uint64 > ULongInt;
|
||||
typedef LongInt< int64_t > SLongInt;
|
||||
typedef LongInt< uint64_t > ULongInt;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to pop the value at the specified index on the stack as a signed long integer.
|
||||
*/
|
||||
Int64 PopStackSLong(HSQUIRRELVM vm, SQInteger idx);
|
||||
int64_t PopStackSLong(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to pop the value at the specified index on the stack as an unsigned long integer.
|
||||
*/
|
||||
Uint64 PopStackULong(HSQUIRRELVM vm, SQInteger idx);
|
||||
uint64_t PopStackULong(HSQUIRRELVM vm, SQInteger idx);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Get a persistent LongInt instance with the given values.
|
||||
*/
|
||||
const SLongInt & GetSLongInt();
|
||||
const SLongInt & GetSLongInt(Int64 n);
|
||||
const SLongInt & GetSLongInt(CSStr s);
|
||||
const SLongInt & GetSLongInt(int64_t n);
|
||||
const SLongInt & GetSLongInt(const SQChar * s);
|
||||
const ULongInt & GetULongInt();
|
||||
const ULongInt & GetULongInt(Uint64 n);
|
||||
const ULongInt & GetULongInt(CSStr s);
|
||||
const ULongInt & GetULongInt(uint64_t n);
|
||||
const ULongInt & GetULongInt(const SQChar * s);
|
||||
|
||||
} // Namespace:: SqMod
|
@@ -1,7 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Numeric/Math.hpp"
|
||||
#include "Library/Numeric/LongInt.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Library/Numeric/Long.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <cmath>
|
||||
@@ -61,12 +60,12 @@ static SQInteger SqRemainder(HSQUIRRELVM vm)
|
||||
}
|
||||
// Are we both arguments floats?
|
||||
if ((sq_gettype(vm, 2) == OT_FLOAT) && sq_gettype(vm, 3) == OT_FLOAT)
|
||||
{
|
||||
{ // NOLINT(bugprone-branch-clone)
|
||||
sq_pushfloat(vm, std::remainder(PopStackFloat(vm, 2), PopStackFloat(vm, 3)));
|
||||
}
|
||||
// Are we both arguments integers?
|
||||
else if ((sq_gettype(vm, 2) == OT_INTEGER) && sq_gettype(vm, 3) == OT_INTEGER)
|
||||
{
|
||||
{ // NOLINT(bugprone-branch-clone)
|
||||
sq_pushinteger(vm, std::remainder(PopStackInteger(vm, 2), PopStackInteger(vm, 3)));
|
||||
}
|
||||
// Is the first argument float?
|
||||
@@ -79,7 +78,7 @@ static SQInteger SqRemainder(HSQUIRRELVM vm)
|
||||
{
|
||||
sq_pushinteger(vm, std::remainder(PopStackInteger(vm, 2), PopStackInteger(vm, 3)));
|
||||
}
|
||||
// Default to both arhuments as float so we don't loos precision from the float one
|
||||
// Default to both arguments as float so we don't loos precision from the float one
|
||||
else
|
||||
{
|
||||
sq_pushfloat(vm, std::remainder(PopStackFloat(vm, 2), PopStackFloat(vm, 3)));
|
||||
@@ -189,10 +188,6 @@ static SQInteger SqNanL(HSQUIRRELVM vm)
|
||||
{
|
||||
Var< SLongInt * >::push(vm, new SLongInt(std::nanl(val.mPtr)));
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
return sq_throwerror(vm, e.what());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
return sq_throwerror(vm, e.what());
|
||||
@@ -694,10 +689,6 @@ static SQInteger SqRoundL(HSQUIRRELVM vm)
|
||||
Var< SLongInt * >::push(vm, new SLongInt(std::llround(PopStackInteger(vm, 2))));
|
||||
}
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
return sq_throwerror(vm, e.what());
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
return sq_throwerror(vm, e.what());
|
||||
@@ -733,7 +724,7 @@ static SQInteger SqFrexp(HSQUIRRELVM vm)
|
||||
return sq_throwerror(vm, "Wrong number of arguments");
|
||||
}
|
||||
// Where the exponent is retrieved
|
||||
Int32 expv = 0;
|
||||
int32_t expv = 0;
|
||||
// Fetch the arguments from the stack and perform the requested operation
|
||||
const SQFloat sigv = std::frexp(PopStackFloat(vm, 2), &expv);
|
||||
// Create a new table on the stack
|
||||
@@ -1075,9 +1066,9 @@ static SQInteger SqDigits1(HSQUIRRELVM vm)
|
||||
return sq_throwerror(vm, "Wrong number of arguments");
|
||||
}
|
||||
// Fetch the integer value from the stack
|
||||
Int64 n = std::llabs(PopStackSLong(vm, 2));
|
||||
int64_t n = std::llabs(PopStackSLong(vm, 2));
|
||||
// Start with 0 digits
|
||||
Uint8 d = 0;
|
||||
uint8_t d = 0;
|
||||
// Identify the number of digits
|
||||
while (n != 0)
|
||||
{
|
||||
@@ -1099,9 +1090,9 @@ static SQInteger SqDigits0(HSQUIRRELVM vm)
|
||||
return sq_throwerror(vm, "Wrong number of arguments");
|
||||
}
|
||||
// Fetch the integer value from the stack
|
||||
Int64 n = std::llabs(PopStackSLong(vm, 2));
|
||||
int64_t n = std::llabs(PopStackSLong(vm, 2));
|
||||
// Start with 0 digits
|
||||
Uint8 d = 0;
|
||||
uint8_t d = 0;
|
||||
// Identify the number of digits
|
||||
do
|
||||
{
|
||||
@@ -1115,14 +1106,14 @@ static SQInteger SqDigits0(HSQUIRRELVM vm)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQFloat SqIToF(Int64 sigv, Int64 expv, Int32 padn, bool negf)
|
||||
SQFloat SqIToF(int64_t sigv, int64_t expv, int32_t padn, bool negf)
|
||||
{
|
||||
// The number of characters to add before the exponent
|
||||
static CharT padb[64];
|
||||
CharT padb[64];
|
||||
// Make sure the pad number is positive
|
||||
padn = ClampMin(padn, 0);
|
||||
// Is the number of pad characters out of range?
|
||||
if (static_cast< Uint32 >(padn) >= sizeof(padb))
|
||||
if (static_cast< uint32_t >(padn) >= sizeof(padb))
|
||||
{
|
||||
STHROWF("Pad characters out of range: %d >= %d", padn, sizeof(padb));
|
||||
}
|
||||
@@ -1130,23 +1121,23 @@ SQFloat SqIToF(Int64 sigv, Int64 expv, Int32 padn, bool negf)
|
||||
std::memset(padb, '0', padn);
|
||||
// Add the null terminator
|
||||
padb[padn] = '\0';
|
||||
// The obtained string containing the floating point
|
||||
CSStr fstr = nullptr;
|
||||
// Generate the floating point value
|
||||
// Now transform the resulted string to a floating point value
|
||||
if (negf)
|
||||
{
|
||||
fstr = ToStrF("-%lld.%s%lld", sigv, padb, expv);
|
||||
#ifdef SQUSEDOUBLE
|
||||
return std::strtod(fmt::format("-{}.{}{}", sigv, padb, expv).c_str(), nullptr);
|
||||
#else
|
||||
return std::strtof(fmt::format("-{}.{}{}", sigv, padb, expv).c_str(), nullptr);
|
||||
#endif // SQUSEDOUBLE
|
||||
}
|
||||
else
|
||||
{
|
||||
fstr = ToStrF("%lld.%s%lld", sigv, padb, expv);
|
||||
}
|
||||
// Now transform the resulted string to a floating point value
|
||||
#ifdef SQUSEDOUBLE
|
||||
return std::strtod(fstr, nullptr);
|
||||
return std::strtod(fmt::format("{}.{}{}", sigv, padb, expv).c_str(), nullptr);
|
||||
#else
|
||||
return std::strtof(fstr, nullptr);
|
||||
return std::strtof(fmt::format("{}.{}{}", sigv, padb, expv).c_str(), nullptr);
|
||||
#endif // SQUSEDOUBLE
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
|
@@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "SqBase.hpp"
|
||||
#include "Core/Common.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@@ -1,13 +1,12 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Numeric/Random.hpp"
|
||||
#include "Base/Shared.hpp"
|
||||
#include "Base/Buffer.hpp"
|
||||
#include "Core/Common.hpp"
|
||||
#include "Core/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <cstdlib>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
@@ -21,52 +20,52 @@
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static std::unique_ptr< std::mt19937 > RG32_MT19937 =
|
||||
std::unique_ptr< std::mt19937 >(new std::mt19937(GenerateSeed()));
|
||||
static std::unique_ptr< std::mt19937 > RG32_MT19937 = // NOLINT(cert-err58-cpp)
|
||||
std::make_unique< std::mt19937 >(GenerateSeed());
|
||||
|
||||
static std::unique_ptr< std::mt19937_64 > RG64_MT19937 =
|
||||
std::unique_ptr< std::mt19937_64 >(new std::mt19937_64(GenerateSeed()));
|
||||
static std::unique_ptr< std::mt19937_64 > RG64_MT19937 = // NOLINT(cert-err58-cpp)
|
||||
std::make_unique< std::mt19937_64 >(GenerateSeed());
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static std::uniform_int_distribution< Int8 > Int8_Dist(std::numeric_limits< Int8 >::min(),
|
||||
std::numeric_limits< Int8 >::max());
|
||||
static std::uniform_int_distribution< Uint8 > Uint8_Dist(std::numeric_limits< Uint8 >::min(),
|
||||
std::numeric_limits< Uint8 >::max());
|
||||
static std::uniform_int_distribution< int8_t > Int8_Dist(std::numeric_limits< int8_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< int8_t >::max());
|
||||
static std::uniform_int_distribution< uint8_t > uint8_t_Dist(std::numeric_limits< uint8_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< uint8_t >::max());
|
||||
|
||||
static std::uniform_int_distribution< Int16 > Int16_Dist(std::numeric_limits< Int16 >::min(),
|
||||
std::numeric_limits< Int16 >::max());
|
||||
static std::uniform_int_distribution< Uint16 > Uint16_Dist(std::numeric_limits< Uint16 >::min(),
|
||||
std::numeric_limits< Uint16 >::max());
|
||||
static std::uniform_int_distribution< int16_t > Int16_Dist(std::numeric_limits< int16_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< int16_t >::max());
|
||||
static std::uniform_int_distribution< uint16_t > Uint16_Dist(std::numeric_limits< uint16_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< uint16_t >::max());
|
||||
|
||||
static std::uniform_int_distribution< Int32 > Int32_Dist(std::numeric_limits< Int32 >::min(),
|
||||
std::numeric_limits< Int32 >::max());
|
||||
static std::uniform_int_distribution< Uint32 > Uint32_Dist(std::numeric_limits< Uint32 >::min(),
|
||||
std::numeric_limits< Uint32 >::max());
|
||||
static std::uniform_int_distribution< int32_t > Int32_Dist(std::numeric_limits< int32_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< int32_t >::max());
|
||||
static std::uniform_int_distribution< uint32_t > Uint32_Dist(std::numeric_limits< uint32_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< uint32_t >::max());
|
||||
|
||||
static std::uniform_int_distribution< Int64 > Int64_Dist(std::numeric_limits< Int64 >::min(),
|
||||
std::numeric_limits< Int64 >::max());
|
||||
static std::uniform_int_distribution< Uint64 > Uint64_Dist(std::numeric_limits< Uint64 >::min(),
|
||||
std::numeric_limits< Uint64 >::max());
|
||||
static std::uniform_int_distribution< int64_t > Int64_Dist(std::numeric_limits< int64_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< int64_t >::max());
|
||||
static std::uniform_int_distribution< uint64_t > Uint64_Dist(std::numeric_limits< uint64_t >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< uint64_t >::max());
|
||||
|
||||
static std::uniform_real_distribution<Float32> Float32_Dist(std::numeric_limits< Float32 >::min(),
|
||||
std::numeric_limits< Float32 >::max());
|
||||
static std::uniform_real_distribution<Float64> Float64_Dist(std::numeric_limits< Float64 >::min(),
|
||||
std::numeric_limits< Float64 >::max());
|
||||
static std::uniform_real_distribution<float> Float32_Dist(std::numeric_limits< float >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< float >::max());
|
||||
static std::uniform_real_distribution<double> Float64_Dist(std::numeric_limits< double >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< double >::max());
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static std::uniform_int_distribution< String::value_type >
|
||||
String_Dist(std::numeric_limits< String::value_type >::min(),
|
||||
String_Dist(std::numeric_limits< String::value_type >::min(), // NOLINT(cert-err58-cpp)
|
||||
std::numeric_limits< String::value_type >::max());
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SizeT GenerateSeed()
|
||||
uint32_t GenerateSeed()
|
||||
{
|
||||
Ulong a = clock();
|
||||
Ulong b = time(NULL);
|
||||
unsigned long a = clock();
|
||||
unsigned long b = time(nullptr);
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
Ulong c = _getpid();
|
||||
unsigned long c = _getpid();
|
||||
#else
|
||||
Ulong c = getpid();
|
||||
unsigned long c = getpid();
|
||||
#endif
|
||||
// Mangle
|
||||
a=a-b; a=a-c; a=a^(c >> 13);
|
||||
@@ -83,9 +82,9 @@ SizeT GenerateSeed()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SizeT GenerateSeed2()
|
||||
size_t GenerateSeed2()
|
||||
{
|
||||
struct {
|
||||
struct { // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
std::clock_t c;
|
||||
std::time_t t;
|
||||
#ifdef SQMOD_OS_WINDOWS
|
||||
@@ -108,199 +107,199 @@ SizeT GenerateSeed2()
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReseedRandom()
|
||||
{
|
||||
RG32_MT19937.reset(new std::mt19937(GenerateSeed()));
|
||||
RG64_MT19937.reset(new std::mt19937_64(GenerateSeed()));
|
||||
RG32_MT19937 = std::make_unique<std::mt19937>(GenerateSeed());
|
||||
RG64_MT19937 = std::make_unique<std::mt19937_64>(GenerateSeed());
|
||||
}
|
||||
|
||||
void ReseedRandom(Uint32 n)
|
||||
void ReseedRandom(uint32_t n)
|
||||
{
|
||||
RG32_MT19937.reset(new std::mt19937(n));
|
||||
RG64_MT19937.reset(new std::mt19937_64(n));
|
||||
RG32_MT19937 = std::make_unique<std::mt19937>(n);
|
||||
RG64_MT19937 = std::make_unique<std::mt19937_64>(n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReseedRandom32()
|
||||
{
|
||||
RG32_MT19937.reset(new std::mt19937(GenerateSeed()));
|
||||
RG32_MT19937 = std::make_unique<std::mt19937>(GenerateSeed());
|
||||
}
|
||||
|
||||
void ReseedRandom32(Uint32 n)
|
||||
void ReseedRandom32(uint32_t n)
|
||||
{
|
||||
RG32_MT19937.reset(new std::mt19937(n));
|
||||
RG32_MT19937 = std::make_unique<std::mt19937>(n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReseedRandom64()
|
||||
{
|
||||
RG64_MT19937.reset(new std::mt19937_64(GenerateSeed()));
|
||||
RG64_MT19937 = std::make_unique<std::mt19937_64>(GenerateSeed());
|
||||
}
|
||||
|
||||
void ReseedRandom64(Uint32 n)
|
||||
void ReseedRandom64(uint32_t n)
|
||||
{
|
||||
RG64_MT19937.reset(new std::mt19937_64(n));
|
||||
RG64_MT19937 = std::make_unique<std::mt19937_64>(n);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int8 GetRandomInt8()
|
||||
int8_t GetRandomInt8()
|
||||
{
|
||||
return Int8_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Int8 GetRandomInt8(Int8 n)
|
||||
int8_t GetRandomInt8(int8_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int8 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< int8_t >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Int8 GetRandomInt8(Int8 m, Int8 n)
|
||||
int8_t GetRandomInt8(int8_t m, int8_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int8 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< int8_t >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint8 GetRandomUint8()
|
||||
uint8_t GetRandomUint8()
|
||||
{
|
||||
return Uint8_Dist(*RG32_MT19937);
|
||||
return uint8_t_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Uint8 GetRandomUint8(Uint8 n)
|
||||
uint8_t GetRandomUint8(uint8_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Uint8 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< uint8_t >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Uint8 GetRandomUint8(Uint8 m, Uint8 n)
|
||||
uint8_t GetRandomUint8(uint8_t m, uint8_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Uint8 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< uint8_t >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int16 GetRandomInt16()
|
||||
int16_t GetRandomInt16()
|
||||
{
|
||||
return Int16_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Int16 GetRandomInt16(Int16 n)
|
||||
int16_t GetRandomInt16(int16_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int16 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< int16_t >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Int16 GetRandomInt16(Int16 m, Int16 n)
|
||||
int16_t GetRandomInt16(int16_t m, int16_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int16 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< int16_t >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint16 GetRandomUint16()
|
||||
uint16_t GetRandomUint16()
|
||||
{
|
||||
return Uint16_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Uint16 GetRandomUint16(Uint16 n)
|
||||
uint16_t GetRandomUint16(uint16_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Uint16 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< uint16_t >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Uint16 GetRandomUint16(Uint16 m, Uint16 n)
|
||||
uint16_t GetRandomUint16(uint16_t m, uint16_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Uint16 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< uint16_t >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetRandomInt32()
|
||||
int32_t GetRandomInt32()
|
||||
{
|
||||
return Int32_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Int32 GetRandomInt32(Int32 n)
|
||||
int32_t GetRandomInt32(int32_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int32 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< int32_t >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Int32 GetRandomInt32(Int32 m, Int32 n)
|
||||
int32_t GetRandomInt32(int32_t m, int32_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int32 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< int32_t >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetRandomUint32()
|
||||
uint32_t GetRandomUint32()
|
||||
{
|
||||
return Int32_Dist(*RG32_MT19937);
|
||||
return Uint32_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Uint32 GetRandomUint32(Uint32 n)
|
||||
uint32_t GetRandomUint32(uint32_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int32 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< uint32_t >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Uint32 GetRandomUint32(Uint32 m, Uint32 n)
|
||||
uint32_t GetRandomUint32(uint32_t m, uint32_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int32 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_int_distribution< uint32_t >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 GetRandomInt64()
|
||||
int64_t GetRandomInt64()
|
||||
{
|
||||
return Int64_Dist(*RG64_MT19937);
|
||||
}
|
||||
|
||||
Int64 GetRandomInt64(Int64 n)
|
||||
int64_t GetRandomInt64(int64_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int64 >(0, n)(*RG64_MT19937);
|
||||
return std::uniform_int_distribution< int64_t >(0, n)(*RG64_MT19937);
|
||||
}
|
||||
|
||||
Int64 GetRandomInt64(Int64 m, Int64 n)
|
||||
int64_t GetRandomInt64(int64_t m, int64_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Int64 >(m, n)(*RG64_MT19937);
|
||||
return std::uniform_int_distribution< int64_t >(m, n)(*RG64_MT19937);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 GetRandomUint64()
|
||||
uint64_t GetRandomUint64()
|
||||
{
|
||||
return Uint64_Dist(*RG64_MT19937);
|
||||
}
|
||||
|
||||
Uint64 GetRandomUint64(Uint64 n)
|
||||
uint64_t GetRandomUint64(uint64_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Uint64 >(0, n)(*RG64_MT19937);
|
||||
return std::uniform_int_distribution< uint64_t >(0, n)(*RG64_MT19937);
|
||||
}
|
||||
|
||||
Uint64 GetRandomUint64(Uint64 m, Uint64 n)
|
||||
uint64_t GetRandomUint64(uint64_t m, uint64_t n)
|
||||
{
|
||||
return std::uniform_int_distribution< Uint64 >(m, n)(*RG64_MT19937);
|
||||
return std::uniform_int_distribution< uint64_t >(m, n)(*RG64_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetRandomFloat32()
|
||||
float GetRandomFloat32()
|
||||
{
|
||||
return Float32_Dist(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Float32 GetRandomFloat32(Float32 n)
|
||||
float GetRandomFloat32(float n)
|
||||
{
|
||||
return std::uniform_real_distribution< Float32 >(0, n)(*RG32_MT19937);
|
||||
return std::uniform_real_distribution< float >(0, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
Float32 GetRandomFloat32(Float32 m, Float32 n)
|
||||
float GetRandomFloat32(float m, float n)
|
||||
{
|
||||
return std::uniform_real_distribution< Float32 >(m, n)(*RG32_MT19937);
|
||||
return std::uniform_real_distribution< float >(m, n)(*RG32_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float64 GetRandomFloat64()
|
||||
double GetRandomFloat64()
|
||||
{
|
||||
return Float64_Dist(*RG64_MT19937);
|
||||
}
|
||||
|
||||
Float64 GetRandomFloat64(Float64 n)
|
||||
double GetRandomFloat64(double n)
|
||||
{
|
||||
return std::uniform_real_distribution< Float64 >(0, n)(*RG64_MT19937);
|
||||
return std::uniform_real_distribution< double >(0, n)(*RG64_MT19937);
|
||||
}
|
||||
|
||||
Float64 GetRandomFloat64(Float64 m, Float64 n)
|
||||
double GetRandomFloat64(double m, double n)
|
||||
{
|
||||
return std::uniform_real_distribution< Float64 >(m, n)(*RG64_MT19937);
|
||||
return std::uniform_real_distribution< double >(m, n)(*RG64_MT19937);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -353,7 +352,7 @@ bool GetRandomBool(SQFloat p)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static String RandomString(Int32 len)
|
||||
static String RandomString(int32_t len)
|
||||
{
|
||||
// Is there anything to generate?
|
||||
if (len <= 0)
|
||||
@@ -367,7 +366,7 @@ static String RandomString(Int32 len)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static String RandomString(Int32 len, SQChar n)
|
||||
static String RandomString(int32_t len, SQChar n)
|
||||
{
|
||||
// Is there anything to generate?
|
||||
if (len <= 0)
|
||||
@@ -381,7 +380,7 @@ static String RandomString(Int32 len, SQChar n)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static String RandomString(Int32 len, SQChar m, SQChar n)
|
||||
static String RandomString(int32_t len, SQChar m, SQChar n)
|
||||
{
|
||||
// Is there anything to generate?
|
||||
if (len <= 0)
|
||||
@@ -401,11 +400,11 @@ void Register_Random(HSQUIRRELVM vm)
|
||||
.Func(_SC("GenSeed"), &GenerateSeed)
|
||||
.Func(_SC("GenSeed2"), &GenerateSeed2)
|
||||
.Overload< void (*)(void) >(_SC("Reseed"), &ReseedRandom)
|
||||
.Overload< void (*)(Uint32) >(_SC("Reseed"), &ReseedRandom)
|
||||
.Overload< void (*)(uint32_t) >(_SC("Reseed"), &ReseedRandom)
|
||||
.Overload< void (*)(void) >(_SC("Reseed32"), &ReseedRandom32)
|
||||
.Overload< void (*)(Uint32) >(_SC("Reseed32"), &ReseedRandom32)
|
||||
.Overload< void (*)(uint32_t) >(_SC("Reseed32"), &ReseedRandom32)
|
||||
.Overload< void (*)(void) >(_SC("Reseed64"), &ReseedRandom64)
|
||||
.Overload< void (*)(Uint32) >(_SC("Reseed64"), &ReseedRandom64)
|
||||
.Overload< void (*)(uint32_t) >(_SC("Reseed64"), &ReseedRandom64)
|
||||
|
||||
#ifdef _SQ64
|
||||
.Overload< SQInteger (*)(void) >(_SC("Integer"), &GetRandomInt64)
|
||||
@@ -427,9 +426,9 @@ void Register_Random(HSQUIRRELVM vm)
|
||||
.Overload< SQFloat (*)(SQFloat, SQFloat) >(_SC("Float"), &GetRandomFloat32)
|
||||
#endif // SQUSEDOUBLE
|
||||
|
||||
.Overload< String (*)(Int32) >(_SC("String"), &RandomString)
|
||||
.Overload< String (*)(Int32, SQChar) >(_SC("String"), &RandomString)
|
||||
.Overload< String (*)(Int32, SQChar, SQChar) >(_SC("String"), &RandomString)
|
||||
.Overload< String (*)(int32_t) >(_SC("String"), &RandomString)
|
||||
.Overload< String (*)(int32_t, SQChar) >(_SC("String"), &RandomString)
|
||||
.Overload< String (*)(int32_t, SQChar, SQChar) >(_SC("String"), &RandomString)
|
||||
.Overload< bool (*)(void) >(_SC("Bool"), &GetRandomBool)
|
||||
.Overload< bool (*)(SQFloat) >(_SC("Bool"), &GetRandomBool)
|
||||
);
|
||||
|
@@ -9,61 +9,61 @@ namespace SqMod {
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Attempt to generate a moderately unique number to be used as a seed for random numbers.
|
||||
*/
|
||||
Uint32 GenerateSeed();
|
||||
uint32_t GenerateSeed();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReseedRandom();
|
||||
void ReseedRandom(Uint32 n);
|
||||
void ReseedRandom(uint32_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int8 GetRandomInt8();
|
||||
Int8 GetRandomInt8(Int8 n);
|
||||
Int8 GetRandomInt8(Int8 m, Int8 n);
|
||||
SQMOD_NODISCARD int8_t GetRandomInt8();
|
||||
SQMOD_NODISCARD int8_t GetRandomInt8(int8_t n);
|
||||
SQMOD_NODISCARD int8_t GetRandomInt8(int8_t m, int8_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint8 GetRandomUint8();
|
||||
Uint8 GetRandomUint8(Uint8 n);
|
||||
Uint8 GetRandomUint8(Uint8 m, Uint8 n);
|
||||
SQMOD_NODISCARD uint8_t GetRandomUint8();
|
||||
SQMOD_NODISCARD uint8_t GetRandomUint8(uint8_t n);
|
||||
SQMOD_NODISCARD uint8_t GetRandomUint8(uint8_t m, uint8_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int16 GetRandomInt16();
|
||||
Int16 GetRandomInt16(Int16 n);
|
||||
Int16 GetRandomInt16(Int16 m, Int16 n);
|
||||
SQMOD_NODISCARD int16_t GetRandomInt16();
|
||||
SQMOD_NODISCARD int16_t GetRandomInt16(int16_t n);
|
||||
SQMOD_NODISCARD int16_t GetRandomInt16(int16_t m, int16_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint16 GetRandomUint16();
|
||||
Uint16 GetRandomUint16(Uint16 n);
|
||||
Uint16 GetRandomUint16(Uint16 m, Uint16 n);
|
||||
SQMOD_NODISCARD uint16_t GetRandomUint16();
|
||||
SQMOD_NODISCARD uint16_t GetRandomUint16(uint16_t n);
|
||||
SQMOD_NODISCARD uint16_t GetRandomUint16(uint16_t m, uint16_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int32 GetRandomInt32();
|
||||
Int32 GetRandomInt32(Int32 n);
|
||||
Int32 GetRandomInt32(Int32 m, Int32 n);
|
||||
SQMOD_NODISCARD int32_t GetRandomInt32();
|
||||
SQMOD_NODISCARD int32_t GetRandomInt32(int32_t n);
|
||||
SQMOD_NODISCARD int32_t GetRandomInt32(int32_t m, int32_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint32 GetRandomUint32();
|
||||
Uint32 GetRandomUint32(Uint32 n);
|
||||
Uint32 GetRandomUint32(Uint32 m, Uint32 n);
|
||||
SQMOD_NODISCARD uint32_t GetRandomUint32();
|
||||
SQMOD_NODISCARD uint32_t GetRandomUint32(uint32_t n);
|
||||
SQMOD_NODISCARD uint32_t GetRandomUint32(uint32_t m, uint32_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Int64 GetRandomInt64();
|
||||
Int64 GetRandomInt64(Int64 n);
|
||||
Int64 GetRandomInt64(Int64 m, Int64 n);
|
||||
SQMOD_NODISCARD int64_t GetRandomInt64();
|
||||
SQMOD_NODISCARD int64_t GetRandomInt64(int64_t n);
|
||||
SQMOD_NODISCARD int64_t GetRandomInt64(int64_t m, int64_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Uint64 GetRandomUint64();
|
||||
Uint64 GetRandomUint64(Uint64 n);
|
||||
Uint64 GetRandomUint64(Uint64 m, Uint64 n);
|
||||
SQMOD_NODISCARD uint64_t GetRandomUint64();
|
||||
SQMOD_NODISCARD uint64_t GetRandomUint64(uint64_t n);
|
||||
SQMOD_NODISCARD uint64_t GetRandomUint64(uint64_t m, uint64_t n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float32 GetRandomFloat32();
|
||||
Float32 GetRandomFloat32(Float32 n);
|
||||
Float32 GetRandomFloat32(Float32 m, Float32 n);
|
||||
SQMOD_NODISCARD float GetRandomFloat32();
|
||||
SQMOD_NODISCARD float GetRandomFloat32(float n);
|
||||
SQMOD_NODISCARD float GetRandomFloat32(float m, float n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Float64 GetRandomFloat64();
|
||||
Float64 GetRandomFloat64(Float64 n);
|
||||
Float64 GetRandomFloat64(Float64 m, Float64 n);
|
||||
SQMOD_NODISCARD double GetRandomFloat64();
|
||||
SQMOD_NODISCARD double GetRandomFloat64(double n);
|
||||
SQMOD_NODISCARD double GetRandomFloat64(double m, double n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetRandomString(String & str, String::size_type len);
|
||||
@@ -71,85 +71,85 @@ void GetRandomString(String & str, String::size_type len, String::value_type n);
|
||||
void GetRandomString(String & str, String::size_type len, String::value_type m, String::value_type n);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool GetRandomBool();
|
||||
SQMOD_NODISCARD bool GetRandomBool();
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename T> struct RandomVal
|
||||
{ /* ... */ };
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int8 >
|
||||
template <> struct RandomVal< int8_t >
|
||||
{
|
||||
static inline Int8 Get() { return GetRandomInt8(); }
|
||||
static inline Int8 Get(Int8 n) { return GetRandomInt8(n); }
|
||||
static inline Int8 Get(Int8 m, Int8 n) { return GetRandomInt8(m, n); }
|
||||
static inline int8_t Get() { return GetRandomInt8(); }
|
||||
static inline int8_t Get(int8_t n) { return GetRandomInt8(n); }
|
||||
static inline int8_t Get(int8_t m, int8_t n) { return GetRandomInt8(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint8 >
|
||||
template <> struct RandomVal< uint8_t >
|
||||
{
|
||||
static inline Uint8 Get() { return GetRandomUint8(); }
|
||||
static inline Uint8 Get(Uint8 n) { return GetRandomUint8(n); }
|
||||
static inline Uint8 Get(Uint8 m, Uint8 n) { return GetRandomUint8(m, n); }
|
||||
static inline uint8_t Get() { return GetRandomUint8(); }
|
||||
static inline uint8_t Get(uint8_t n) { return GetRandomUint8(n); }
|
||||
static inline uint8_t Get(uint8_t m, uint8_t n) { return GetRandomUint8(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int16 >
|
||||
template <> struct RandomVal< int16_t >
|
||||
{
|
||||
static inline Int16 Get() { return GetRandomInt16(); }
|
||||
static inline Int16 Get(Int16 n) { return GetRandomInt16(n); }
|
||||
static inline Int16 Get(Int16 m, Int16 n) { return GetRandomInt16(m, n); }
|
||||
static inline int16_t Get() { return GetRandomInt16(); }
|
||||
static inline int16_t Get(int16_t n) { return GetRandomInt16(n); }
|
||||
static inline int16_t Get(int16_t m, int16_t n) { return GetRandomInt16(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint16 >
|
||||
template <> struct RandomVal< uint16_t >
|
||||
{
|
||||
static inline Uint16 Get() { return GetRandomUint16(); }
|
||||
static inline Uint16 Get(Uint16 n) { return GetRandomUint16(n); }
|
||||
static inline Uint16 Get(Uint16 m, Uint16 n) { return GetRandomUint16(m, n); }
|
||||
static inline uint16_t Get() { return GetRandomUint16(); }
|
||||
static inline uint16_t Get(uint16_t n) { return GetRandomUint16(n); }
|
||||
static inline uint16_t Get(uint16_t m, uint16_t n) { return GetRandomUint16(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int32 >
|
||||
template <> struct RandomVal< int32_t >
|
||||
{
|
||||
static inline Int32 Get() { return GetRandomInt32(); }
|
||||
static inline Int32 Get(Int32 n) { return GetRandomInt32(n); }
|
||||
static inline Int32 Get(Int32 m, Int32 n) { return GetRandomInt32(m, n); }
|
||||
static inline int32_t Get() { return GetRandomInt32(); }
|
||||
static inline int32_t Get(int32_t n) { return GetRandomInt32(n); }
|
||||
static inline int32_t Get(int32_t m, int32_t n) { return GetRandomInt32(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint32 >
|
||||
template <> struct RandomVal< uint32_t >
|
||||
{
|
||||
static inline Uint32 Get() { return GetRandomUint32(); }
|
||||
static inline Uint32 Get(Uint32 n) { return GetRandomUint32(n); }
|
||||
static inline Uint32 Get(Uint32 m, Uint32 n) { return GetRandomUint32(m, n); }
|
||||
static inline uint32_t Get() { return GetRandomUint32(); }
|
||||
static inline uint32_t Get(uint32_t n) { return GetRandomUint32(n); }
|
||||
static inline uint32_t Get(uint32_t m, uint32_t n) { return GetRandomUint32(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Int64 >
|
||||
template <> struct RandomVal< int64_t >
|
||||
{
|
||||
static inline Int64 Get() { return GetRandomInt64(); }
|
||||
static inline Int64 Get(Int64 n) { return GetRandomInt64(n); }
|
||||
static inline Int64 Get(Int64 m, Int64 n) { return GetRandomInt64(m, n); }
|
||||
static inline int64_t Get() { return GetRandomInt64(); }
|
||||
static inline int64_t Get(int64_t n) { return GetRandomInt64(n); }
|
||||
static inline int64_t Get(int64_t m, int64_t n) { return GetRandomInt64(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Uint64 >
|
||||
template <> struct RandomVal< uint64_t >
|
||||
{
|
||||
static inline Uint64 Get() { return GetRandomUint64(); }
|
||||
static inline Uint64 Get(Uint64 n) { return GetRandomUint64(n); }
|
||||
static inline Uint64 Get(Uint64 m, Uint64 n) { return GetRandomUint64(m, n); }
|
||||
static inline uint64_t Get() { return GetRandomUint64(); }
|
||||
static inline uint64_t Get(uint64_t n) { return GetRandomUint64(n); }
|
||||
static inline uint64_t Get(uint64_t m, uint64_t n) { return GetRandomUint64(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <> struct RandomVal< Float32 >
|
||||
template <> struct RandomVal< float >
|
||||
{
|
||||
static inline Float32 Get() { return GetRandomFloat32(); }
|
||||
static inline Float32 Get(Float32 n) { return GetRandomFloat32(n); }
|
||||
static inline Float32 Get(Float32 m, Float32 n) { return GetRandomFloat32(m, n); }
|
||||
static inline float Get() { return GetRandomFloat32(); }
|
||||
static inline float Get(float n) { return GetRandomFloat32(n); }
|
||||
static inline float Get(float m, float n) { return GetRandomFloat32(m, n); }
|
||||
};
|
||||
|
||||
template <> struct RandomVal< Float64 >
|
||||
template <> struct RandomVal< double >
|
||||
{
|
||||
static inline Float64 Get() { return GetRandomFloat64(); }
|
||||
static inline Float64 Get(Float64 n) { return GetRandomFloat64(n); }
|
||||
static inline Float64 Get(Float64 m, Float64 n) { return GetRandomFloat64(m, n); }
|
||||
static inline double Get() { return GetRandomFloat64(); }
|
||||
static inline double Get(double n) { return GetRandomFloat64(n); }
|
||||
static inline double Get(double m, double n) { return GetRandomFloat64(m, n); }
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user