2016-02-27 10:57:10 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Attribute.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-28 16:39:26 +01:00
|
|
|
SQInteger Attribute::Typename(HSQUIRRELVM vm)
|
2016-02-27 10:57:10 +01:00
|
|
|
{
|
2016-05-22 21:34:27 +02:00
|
|
|
static const SQChar name[] = _SC("SqXmlAttribute");
|
2016-02-28 16:39:26 +01:00
|
|
|
sq_pushstring(vm, name, sizeof(name));
|
|
|
|
return 1;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Attribute::AsLong(Object & def) const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< Object >::push(_SqVM, def);
|
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
|
|
|
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
|
|
|
_SqMod->PushSLongObject(_SqVM, m_Attr.as_llong(longint));
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
|
|
|
return Var< Object >(_SqVM, -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Attribute::AsUlong(Object & def) const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< Object >::push(_SqVM, def);
|
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
|
|
|
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
|
|
|
_SqMod->PushULongObject(_SqVM, m_Attr.as_ullong(longint));
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
|
|
|
return Var< Object >(_SqVM, -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Attribute::ApplyLong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< Object & >::push(_SqVM, value);
|
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
|
|
|
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-28 16:39:26 +01:00
|
|
|
// Assign the obtained value and return the result
|
|
|
|
return m_Attr.set_value(longint);
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Attribute::ApplyUlong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< Object & >::push(_SqVM, value);
|
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
|
|
|
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-28 16:39:26 +01:00
|
|
|
// Assign the obtained value and return the result
|
|
|
|
return m_Attr.set_value(longint);
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Attribute::GetLong() const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
|
|
|
_SqMod->PushSLongObject(_SqVM, m_Attr.as_llong());
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
|
|
|
return Var< Object >(_SqVM, -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Attribute::SetLong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< Object & >::push(_SqVM, value);
|
|
|
|
// The resulted long integer value
|
|
|
|
Int64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
|
|
|
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Assign the obtained value
|
2016-02-28 16:39:26 +01:00
|
|
|
m_Attr = longint;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Attribute::GetUlong() const
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
|
|
|
_SqMod->PushULongObject(_SqVM, m_Attr.as_ullong());
|
2016-02-28 16:39:26 +01:00
|
|
|
// Obtain the object from the stack and return it
|
|
|
|
return Var< Object >(_SqVM, -1).value;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Attribute::SetUlong(Object & value)
|
|
|
|
{
|
|
|
|
// Obtain the initial stack size
|
2016-02-28 16:39:26 +01:00
|
|
|
const StackGuard sg(_SqVM);
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push the specified object onto the stack
|
|
|
|
Var< Object & >::push(_SqVM, value);
|
|
|
|
// The resulted long integer value
|
|
|
|
Uint64 longint = 0;
|
|
|
|
// Attempt to get the numeric value inside the specified object
|
|
|
|
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
2016-04-02 10:04:28 +02:00
|
|
|
{
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-04-02 10:04:28 +02:00
|
|
|
}
|
2016-02-27 10:57:10 +01:00
|
|
|
// Assign the obtained value
|
2016-02-28 16:39:26 +01:00
|
|
|
m_Attr = longint;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|