2016-02-27 10:57:10 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Text.hpp"
|
|
|
|
#include "Node.hpp"
|
|
|
|
#include "Module.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <string.h>
|
|
|
|
#include <sqrat.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-28 16:39:26 +01:00
|
|
|
SQInteger Text::Typename(HSQUIRRELVM vm)
|
2016-02-27 10:57:10 +01:00
|
|
|
{
|
2016-02-28 16:39:26 +01:00
|
|
|
static SQChar name[] = _SC("SqXmlText");
|
|
|
|
sq_pushstring(vm, name, sizeof(name));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Text::Validate() const
|
|
|
|
{
|
|
|
|
// Validate the document handle
|
|
|
|
if (!m_Doc)
|
2016-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid XML document reference");
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Int32 Text::Cmp(const Text & o)
|
|
|
|
{
|
|
|
|
if (strcmp(m_Text.get(), o.m_Text.get()) == 0)
|
|
|
|
return 0;
|
|
|
|
else if (strlen(m_Text.get()) > strlen(o.m_Text.get()))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::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-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
|
|
|
_SqMod->PushSLongObject(_SqVM, m_Text.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 Text::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-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-02-27 10:57:10 +01:00
|
|
|
// Push a long integer instance with the requested value on the stack
|
|
|
|
_SqMod->PushULongObject(_SqVM, m_Text.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 Text::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-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-02-28 16:39:26 +01:00
|
|
|
// Assign the obtained value and return the result
|
|
|
|
return m_Text.set(longint);
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Text::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-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-02-28 16:39:26 +01:00
|
|
|
// Assign the obtained value and return the result
|
|
|
|
return m_Text.set(longint);
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::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_Text.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 Text::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-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-02-27 10:57:10 +01:00
|
|
|
// Assign the obtained value
|
2016-02-28 16:39:26 +01:00
|
|
|
m_Text = longint;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Object Text::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_Text.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 Text::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-03-22 23:26:35 +01:00
|
|
|
STHROWF("Invalid long integer specified");
|
2016-02-27 10:57:10 +01:00
|
|
|
// Assign the obtained value
|
2016-02-28 16:39:26 +01:00
|
|
|
m_Text = longint;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Node Text::GetData() const
|
|
|
|
{
|
|
|
|
return Node(m_Doc, m_Text.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|