2020-03-22 00:45:04 +01:00
|
|
|
#pragma once
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Base/Shared.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
template < typename T > class LongInt;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Specialization of the Long int class for signed integers.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
template <> class LongInt< Int64 >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
typedef Int64 Type; // The specialized type.
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
Type m_Data; // The assigned value.
|
|
|
|
SQChar m_Text[32]; // String representation of the value.
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Default constructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt()
|
|
|
|
: m_Data(0), m_Text()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Explicit value constructor.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
explicit LongInt(Type n)
|
2016-06-04 23:00:59 +02:00
|
|
|
: m_Data(n), m_Text()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* String encoded constructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
explicit LongInt(CSStr text);
|
2016-08-24 22:36:48 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 23:19:53 +02:00
|
|
|
* String encoded with explicit base constructor.
|
2016-08-24 22:36:48 +02:00
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
LongInt(CSStr text, Uint32 base);
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Copy constructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt(const LongInt< Type > & o)
|
|
|
|
: m_Data(o.m_Data), m_Text()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Destructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
~LongInt()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LongInt & operator = (const LongInt< Type > & o)
|
|
|
|
{
|
|
|
|
m_Data = o.m_Data;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Copy assignment operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt< Type > & operator = (Type data)
|
|
|
|
{
|
|
|
|
m_Data = data;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assignment operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt< Type > & operator = (CSStr text);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Equality comparison operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
bool operator == (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data == o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Inequality comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator != (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data != o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Less than comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator < (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data < o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Greater than comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator > (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data > o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Less than or equal comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator <= (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data <= o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Greater than or equal comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator >= (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data >= o.m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Implicit conversion to the specialized type.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
2016-08-24 22:36:48 +02:00
|
|
|
operator Type () const
|
|
|
|
{
|
|
|
|
return m_Data;
|
|
|
|
}
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Adition operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
template < typename U > LongInt< Type > operator + (const LongInt< U > & o) const
|
|
|
|
{
|
|
|
|
return LongInt< Type >(m_Data + ConvTo< Type >::From(o.GetNum()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Subtraction operator.
|
|
|
|
*/
|
|
|
|
template < typename U > LongInt< Type > operator - (const LongInt< U > & o) const
|
|
|
|
{
|
|
|
|
return LongInt< Type >(m_Data - ConvTo< Type >::From(o.GetNum()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Multiplication operator.
|
|
|
|
*/
|
|
|
|
template < typename U > LongInt< Type > operator * (const LongInt< U > & o) const
|
|
|
|
{
|
|
|
|
return LongInt< Type >(m_Data * ConvTo< Type >::From(o.GetNum()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Division operator.
|
|
|
|
*/
|
|
|
|
template < typename U > LongInt< Type > operator / (const LongInt< U > & o) const
|
|
|
|
{
|
|
|
|
return LongInt< Type >(m_Data / ConvTo< Type >::From(o.GetNum()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modulus operator.
|
|
|
|
*/
|
|
|
|
template < typename U > LongInt< Type > operator % (const LongInt< U > & o) const
|
|
|
|
{
|
|
|
|
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
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data + static_cast< Type >(0));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Subtraction operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
LongInt< Type > operator - (std::nullptr_t) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data - static_cast< Type >(0));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Multiplication operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
LongInt< Type > operator * (std::nullptr_t) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data * static_cast< Type >(0));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Division operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
LongInt< Type > operator / (std::nullptr_t) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(static_cast< Type >(0));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modulus operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
LongInt< Type > operator % (std::nullptr_t) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
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));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Unarry minus operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt< Type > operator - () const
|
|
|
|
{
|
|
|
|
return LongInt< Type >(-m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-05 02:53:58 +02:00
|
|
|
* Used by the script engine to compare two instances of this type.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
Int32 Cmp(const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
if (m_Data == o.m_Data)
|
2016-06-05 02:53:58 +02:00
|
|
|
{
|
2016-06-04 23:00:59 +02:00
|
|
|
return 0;
|
2016-06-05 02:53:58 +02:00
|
|
|
}
|
2016-06-04 23:00:59 +02:00
|
|
|
else if (m_Data > o.m_Data)
|
2016-06-05 02:53:58 +02:00
|
|
|
{
|
2016-06-04 23:00:59 +02:00
|
|
|
return 1;
|
2016-06-05 02:53:58 +02:00
|
|
|
}
|
2016-06-04 23:00:59 +02:00
|
|
|
else
|
2016-06-05 02:53:58 +02:00
|
|
|
{
|
2016-06-04 23:00:59 +02:00
|
|
|
return -1;
|
2016-06-05 02:53:58 +02:00
|
|
|
}
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 23:19:53 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 23:00:59 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-05 02:53:58 +02:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
CSStr ToString();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assign an integer value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
void SetNum(Type data)
|
|
|
|
{
|
|
|
|
m_Data = data;
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve an the specialized value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
Type GetNum() const
|
|
|
|
{
|
|
|
|
return m_Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Retrieve an a Squirrel integer value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
SQInteger GetSNum() const
|
|
|
|
{
|
|
|
|
return ClampL< Type, SQInteger >(m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assign a string value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
void SetStr(CSStr text)
|
|
|
|
{
|
|
|
|
*this = text;
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve a string value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
CSStr GetCStr()
|
|
|
|
{
|
|
|
|
return ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Generate a random value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
void Random();
|
2016-08-24 22:36:48 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Generate a random value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
void Random(Type n);
|
2016-08-24 22:36:48 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Generate a random value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
void Random(Type m, Type n);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel integer.
|
|
|
|
*/
|
|
|
|
SQInteger ToSqInteger() const
|
|
|
|
{
|
|
|
|
return ClampL< Type, SQInteger >(m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel float.
|
|
|
|
*/
|
|
|
|
SQFloat ToSqFloat() const
|
|
|
|
{
|
|
|
|
return ClampL< Float64, SQFloat >(static_cast< Float64 >(m_Data));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel string.
|
|
|
|
*/
|
|
|
|
CSStr ToSqString()
|
|
|
|
{
|
|
|
|
return ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel boolean.
|
|
|
|
*/
|
|
|
|
bool ToSqBool() const
|
|
|
|
{
|
|
|
|
return (m_Data > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel character.
|
|
|
|
*/
|
|
|
|
SQChar ToSqChar() const
|
|
|
|
{
|
|
|
|
return ClampL< Type, SQChar >(m_Data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Specialization of the Long int class for unsigned integers.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
template <> class LongInt< Uint64 >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
typedef Uint64 Type; // The specialized type.
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
Type m_Data; // The assigned value.
|
|
|
|
SQChar m_Text[32]; // String representation of the value.
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Default constructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt()
|
|
|
|
: m_Data(0), m_Text()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Explicit value constructor.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
LongInt(Type n)
|
|
|
|
: m_Data(n), m_Text()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* String encoded constructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt(CSStr text);
|
2016-08-24 22:36:48 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 23:19:53 +02:00
|
|
|
* String encoded with explicit base constructor.
|
2016-08-24 22:36:48 +02:00
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
LongInt(CSStr text, Uint32 base);
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Copy constructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt(const LongInt< Type > & o)
|
|
|
|
: m_Data(o.m_Data), m_Text()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Destructor.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
~LongInt()
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Copy assignment operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt & operator = (const LongInt< Type > & o)
|
|
|
|
{
|
|
|
|
m_Data = o.m_Data;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assignment operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt< Type > & operator = (Type data)
|
|
|
|
{
|
|
|
|
m_Data = data;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assignment operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt< Type > & operator = (CSStr text);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Equality comparison operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
bool operator == (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data == o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Inequality comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator != (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data != o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Less than comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator < (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data < o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Greater than comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator > (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data > o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Less than or equal comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator <= (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data <= o.m_Data);
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Greater than or equal comparison operator.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
bool operator >= (const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
return (m_Data >= o.m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Implicit conversion to the specialized type.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
2016-08-24 22:36:48 +02:00
|
|
|
operator Type () const
|
|
|
|
{
|
|
|
|
return m_Data;
|
|
|
|
}
|
2016-06-04 23:00:59 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Adition operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
template < typename U > LongInt< Type > operator + (const LongInt< U > & o) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data + ConvTo< Type >::From(o.GetNum()));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Subtraction operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
template < typename U > LongInt< Type > operator - (const LongInt< U > & o) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data - ConvTo< Type >::From(o.GetNum()));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Multiplication operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
template < typename U > LongInt< Type > operator * (const LongInt< U > & o) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data * ConvTo< Type >::From(o.GetNum()));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Division operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
template < typename U > LongInt< Type > operator / (const LongInt< U > & o) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
return LongInt< Type >(m_Data / ConvTo< Type >::From(o.GetNum()));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Modulus operator.
|
|
|
|
*/
|
2016-08-24 23:19:53 +02:00
|
|
|
template < typename U > LongInt< Type > operator % (const LongInt< U > & o) const
|
2016-06-04 23:00:59 +02:00
|
|
|
{
|
2016-08-24 23:19:53 +02:00
|
|
|
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));
|
2016-06-04 23:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Unarry minus operator.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
LongInt< Type > operator - () const
|
|
|
|
{
|
|
|
|
return LongInt< Type >(-m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-05 02:53:58 +02:00
|
|
|
* Used by the script engine to compare two instances of this type.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
Int32 Cmp(const LongInt< Type > & o) const
|
|
|
|
{
|
|
|
|
if (m_Data == o.m_Data)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (m_Data > o.m_Data)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 23:19:53 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 23:00:59 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-06-05 02:53:58 +02:00
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
CSStr ToString();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assign an integer value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
void SetNum(Type data)
|
|
|
|
{
|
|
|
|
m_Data = data;
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve an the specialized value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
Type GetNum() const
|
|
|
|
{
|
|
|
|
return m_Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Retrieve an a Squirrel integer value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
SQInteger GetSNum() const
|
|
|
|
{
|
|
|
|
return (SQInteger)(m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Assign a string value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
void SetStr(CSStr text)
|
|
|
|
{
|
|
|
|
*this = text;
|
|
|
|
}
|
|
|
|
|
2016-08-24 22:36:48 +02:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve a string value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
CSStr GetCStr()
|
|
|
|
{
|
|
|
|
return ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-08-24 22:36:48 +02:00
|
|
|
* Generate a random value.
|
2016-06-04 23:00:59 +02:00
|
|
|
*/
|
|
|
|
void Random();
|
2016-08-24 22:36:48 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Generate a random value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
void Random(Type n);
|
2016-08-24 22:36:48 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Generate a random value.
|
|
|
|
*/
|
2016-06-04 23:00:59 +02:00
|
|
|
void Random(Type m, Type n);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel integer.
|
|
|
|
*/
|
|
|
|
SQInteger ToSqInteger() const
|
|
|
|
{
|
|
|
|
return ClampL< Type, SQInteger >(m_Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel float.
|
|
|
|
*/
|
|
|
|
SQFloat ToSqFloat() const
|
|
|
|
{
|
|
|
|
return ClampL< Float64, SQFloat >(static_cast< Float64 >(m_Data));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel string.
|
|
|
|
*/
|
|
|
|
CSStr ToSqString()
|
|
|
|
{
|
|
|
|
return ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel boolean.
|
|
|
|
*/
|
|
|
|
bool ToSqBool() const
|
|
|
|
{
|
|
|
|
return (m_Data > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to convert the long integer to a squirrel character.
|
|
|
|
*/
|
|
|
|
SQChar ToSqChar() const
|
|
|
|
{
|
|
|
|
return ClampL< Type, SQChar >(m_Data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-24 23:19:53 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 23:00:59 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
typedef LongInt< Int64 > SLongInt;
|
|
|
|
typedef LongInt< Uint64 > ULongInt;
|
|
|
|
|
2020-03-21 23:35:03 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Attempt to pop the value at the specified index on the stack as a signed long integer.
|
|
|
|
*/
|
|
|
|
Int64 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);
|
|
|
|
|
2020-03-22 08:16:40 +01:00
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Get a persistent LongInt instance with the given values.
|
|
|
|
*/
|
|
|
|
const SLongInt & GetSLongInt();
|
|
|
|
const SLongInt & GetSLongInt(Int64 n);
|
|
|
|
const SLongInt & GetSLongInt(CSStr s);
|
|
|
|
const ULongInt & GetULongInt();
|
|
|
|
const ULongInt & GetULongInt(Uint64 n);
|
|
|
|
const ULongInt & GetULongInt(CSStr s);
|
|
|
|
|
2016-06-04 23:00:59 +02:00
|
|
|
} // Namespace:: SqMod
|