Migrated the XML module to C++ exceptions as well.

Also enabled the latest C++ revision in the project.
Various other fixes and improvements.
This commit is contained in:
Sandu Liviu Catalin
2016-02-28 17:39:26 +02:00
parent 47eec5cb10
commit 3162221e7f
12 changed files with 383 additions and 229 deletions
+40 -70
View File
@@ -11,13 +11,19 @@
namespace SqMod {
// ------------------------------------------------------------------------------------------------
bool Text::Validate() const
SQInteger Text::Typename(HSQUIRRELVM vm)
{
if (m_Doc)
return true;
// Invalid document reference
_SqMod->SqThrow("Invalid XML document reference");
return false;
static SQChar name[] = _SC("SqXmlText");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
void Text::Validate() const
{
// Validate the document handle
if (!m_Doc)
SqThrowF("Invalid XML document reference");
}
// ------------------------------------------------------------------------------------------------
@@ -35,158 +41,122 @@ Int32 Text::Cmp(const Text & o)
Object Text::AsLong(Object & def) const
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// 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)))
_SqMod->SqThrow("Invalid long integer specified");
SqThrowF("Invalid long integer specified");
// Push a long integer instance with the requested value on the stack
_SqMod->PushSLongObject(_SqVM, m_Text.as_llong(longint));
// Obtain the object from the stack
Var< Object > inst(_SqVM, -1);
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
// Return the long integer instance
return inst.value;
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
}
// ------------------------------------------------------------------------------------------------
Object Text::AsUlong(Object & def) const
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// 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)))
_SqMod->SqThrow("Invalid long integer specified");
SqThrowF("Invalid long integer specified");
// Push a long integer instance with the requested value on the stack
_SqMod->PushULongObject(_SqVM, m_Text.as_ullong(longint));
// Obtain the object from the stack
Var< Object > inst(_SqVM, -1);
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
// Return the long integer instance
return inst.value;
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
}
// ------------------------------------------------------------------------------------------------
bool Text::ApplyLong(Object & value)
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
// The resulted long integer value
Int64 longint = 0;
// Whether the operation succeeded
bool res = false;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
_SqMod->SqThrow("Invalid long integer specified");
// Assign the obtained value
else
res = m_Text.set(longint);
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
// Return the result
return res;
SqThrowF("Invalid long integer specified");
// Assign the obtained value and return the result
return m_Text.set(longint);
}
// ------------------------------------------------------------------------------------------------
bool Text::ApplyUlong(Object & value)
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// Push the specified object onto the stack
Var< Object & >::push(_SqVM, value);
// The resulted long integer value
Uint64 longint = 0;
// Whether the operation succeeded
bool res = false;
// Attempt to get the numeric value inside the specified object
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
_SqMod->SqThrow("Invalid long integer specified");
// Assign the obtained value
else
res = m_Text.set(longint);
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
// Return the result
return res;
SqThrowF("Invalid long integer specified");
// Assign the obtained value and return the result
return m_Text.set(longint);
}
// ------------------------------------------------------------------------------------------------
Object Text::GetLong() const
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// Push a long integer instance with the requested value on the stack
_SqMod->PushSLongObject(_SqVM, m_Text.as_llong());
// Obtain the object from the stack
Var< Object > inst(_SqVM, -1);
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
// Return the long integer instance
return inst.value;
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
}
// ------------------------------------------------------------------------------------------------
void Text::SetLong(Object & value)
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// 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)))
_SqMod->SqThrow("Invalid long integer specified");
SqThrowF("Invalid long integer specified");
// Assign the obtained value
else
m_Text = longint;
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
m_Text = longint;
}
// ------------------------------------------------------------------------------------------------
Object Text::GetUlong() const
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// Push a long integer instance with the requested value on the stack
_SqMod->PushULongObject(_SqVM, m_Text.as_ullong());
// Obtain the object from the stack
Var< Object > inst(_SqVM, -1);
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
// Return the long integer instance
return inst.value;
// Obtain the object from the stack and return it
return Var< Object >(_SqVM, -1).value;
}
// ------------------------------------------------------------------------------------------------
void Text::SetUlong(Object & value)
{
// Obtain the initial stack size
const Int32 top = sq_gettop(_SqVM);
const StackGuard sg(_SqVM);
// 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)))
_SqMod->SqThrow("Invalid long integer specified");
SqThrowF("Invalid long integer specified");
// Assign the obtained value
else
m_Text = longint;
// Remove an pushed values (if any) to restore the stack
sq_pop(_SqVM, sq_gettop(_SqVM) - top);
m_Text = longint;
}
// ------------------------------------------------------------------------------------------------