mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Fixed excpetion throwing in XML document to that generated corrupted messages because snprintf was used instead of vsnprintf.
Revised most of the XML plugin and cleaned code.
This commit is contained in:
parent
3a08e17cad
commit
b6466b9181
@ -16,14 +16,6 @@ SQInteger Attribute::Typename(HSQUIRRELVM vm)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Attribute::Validate() const
|
||||
{
|
||||
// Validate the document handle
|
||||
if (!m_Doc)
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object Attribute::AsLong(Object & def) const
|
||||
{
|
||||
@ -35,7 +27,9 @@ Object Attribute::AsLong(Object & def) const
|
||||
Int64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Push a long integer instance with the requested value on the stack
|
||||
_SqMod->PushSLongObject(_SqVM, m_Attr.as_llong(longint));
|
||||
// Obtain the object from the stack and return it
|
||||
@ -53,7 +47,9 @@ Object Attribute::AsUlong(Object & def) const
|
||||
Uint64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Push a long integer instance with the requested value on the stack
|
||||
_SqMod->PushULongObject(_SqVM, m_Attr.as_ullong(longint));
|
||||
// Obtain the object from the stack and return it
|
||||
@ -71,7 +67,9 @@ bool Attribute::ApplyLong(Object & value)
|
||||
Int64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value and return the result
|
||||
return m_Attr.set_value(longint);
|
||||
}
|
||||
@ -87,7 +85,9 @@ bool Attribute::ApplyUlong(Object & value)
|
||||
Uint64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value and return the result
|
||||
return m_Attr.set_value(longint);
|
||||
}
|
||||
@ -114,7 +114,9 @@ void Attribute::SetLong(Object & value)
|
||||
Int64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value
|
||||
m_Attr = longint;
|
||||
}
|
||||
@ -141,7 +143,9 @@ void Attribute::SetUlong(Object & value)
|
||||
Uint64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value
|
||||
m_Attr = longint;
|
||||
}
|
||||
|
@ -29,16 +29,11 @@ protected:
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the document reference and throw an error if invalid.
|
||||
*/
|
||||
void Validate() const;
|
||||
|
||||
private:
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
DocumentRef m_Doc; /* The main xml document instance. */
|
||||
Type m_Attr; /* The managed node attribute. */
|
||||
DocumentRef m_Doc; // The main xml document instance.
|
||||
Type m_Attr; // The managed node attribute.
|
||||
|
||||
public:
|
||||
|
||||
@ -84,12 +79,18 @@ public:
|
||||
Int32 Cmp(const Attribute & o)
|
||||
{
|
||||
if (m_Attr == o.m_Attr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_Attr > o.m_Attr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
@ -150,7 +151,9 @@ public:
|
||||
void SetName(CSStr name)
|
||||
{
|
||||
if (!m_Attr.set_name(name))
|
||||
STHROWF("Unable to set xml attribute name");
|
||||
{
|
||||
STHROWF("Unable to set XML attribute name");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -175,7 +178,9 @@ public:
|
||||
void SetValue(CSStr name)
|
||||
{
|
||||
if (!m_Attr.set_value(name))
|
||||
STHROWF("Unable to set xml attribute value");
|
||||
{
|
||||
STHROWF("Unable to set XML attribute value");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -355,7 +360,7 @@ public:
|
||||
*/
|
||||
SQFloat GetFloat() const
|
||||
{
|
||||
return (SQFloat)m_Attr.as_float();
|
||||
return static_cast< SQFloat >(m_Attr.as_float());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -371,7 +376,7 @@ public:
|
||||
*/
|
||||
SQFloat GetDouble() const
|
||||
{
|
||||
return (SQFloat)m_Attr.as_double();
|
||||
return static_cast< SQFloat >(m_Attr.as_double());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "Module.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <stdarg.h>
|
||||
#include <cstdarg>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqrat.h>
|
||||
@ -33,8 +33,10 @@ void SqThrowF(CSStr str, ...)
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Write the requested contents
|
||||
if (snprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
strcpy(g_Buffer, "Unknown error has occurred");
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Throw the exception with the resulted message
|
||||
@ -48,17 +50,26 @@ CSStr FmtStr(CSStr str, ...)
|
||||
va_list args;
|
||||
va_start (args, str);
|
||||
// Write the requested contents
|
||||
if (snprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
g_Buffer[0] = 0; /* make sure the string is terminated */
|
||||
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
|
||||
{
|
||||
g_Buffer[0] = 0; // Make sure the string is terminated
|
||||
}
|
||||
// Release the argument list
|
||||
va_end(args);
|
||||
// Return the data from the buffer
|
||||
return g_Buffer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
StackGuard::StackGuard()
|
||||
: m_VM(_SqVM), m_Top(sq_gettop(m_VM))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
StackGuard::StackGuard(HSQUIRRELVM vm)
|
||||
: m_Top(sq_gettop(vm)), m_VM(vm)
|
||||
: m_VM(vm), m_Top(sq_gettop(vm))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@ -69,6 +80,15 @@ StackGuard::~StackGuard()
|
||||
sq_pop(m_VM, sq_gettop(m_VM) - m_Top);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DocumentRef::Validate() const
|
||||
{
|
||||
if (!m_Ptr)
|
||||
{
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQInteger ParseResult::Typename(HSQUIRRELVM vm)
|
||||
{
|
||||
@ -82,14 +102,18 @@ void ParseResult::Validate() const
|
||||
{
|
||||
// Is the documen handle valid?
|
||||
if (!m_Doc)
|
||||
{
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ParseResult::Check() const
|
||||
{
|
||||
if (m_Result.status != status_ok)
|
||||
{
|
||||
STHROWF("XML parse error [%s]", m_Result.description());
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "ModBase.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <pugixml.hpp>
|
||||
@ -71,6 +71,11 @@ CSStr FmtStr(CSStr str, ...);
|
||||
*/
|
||||
struct StackGuard
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
StackGuard();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
@ -106,8 +111,8 @@ private:
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Int32 m_Top; /* The top of the stack when this instance was created. */
|
||||
HSQUIRRELVM m_VM; /* The VM where the stack should be restored. */
|
||||
HSQUIRRELVM m_VM; // The VM where the stack should be restored.
|
||||
Int32 m_Top; // The top of the stack when this instance was created.
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -134,6 +139,11 @@ public:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
typedef unsigned int Counter; /* Reference counter type. */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and throw exception if invalid.
|
||||
*/
|
||||
void Validate() const;
|
||||
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
@ -14,32 +14,26 @@ SQInteger Document::Typename(HSQUIRRELVM vm)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Document::Validate() const
|
||||
{
|
||||
// Validate the document handle
|
||||
if (!m_Doc)
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Document::CanLoad() const
|
||||
{
|
||||
// Is the document even valid?
|
||||
if (!m_Doc)
|
||||
STHROWF("Invalid XML document reference");
|
||||
m_Doc.Validate();
|
||||
// Are there any other references?
|
||||
else if (m_Doc.Count() > 1)
|
||||
if (m_Doc.Count() > 1)
|
||||
{
|
||||
// To load new values now, would mean to cause undefined behavior in existing references
|
||||
STHROWF("Loading is disabled while document is referenced");
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Node Document::GetNode() const
|
||||
{
|
||||
if (m_Doc)
|
||||
// Validate the document handle
|
||||
m_Doc.Validate();
|
||||
// Return the requested information
|
||||
return Node(m_Doc, m_Doc->document_element());
|
||||
return Node();
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -27,11 +27,6 @@ protected:
|
||||
*/
|
||||
Document & operator = (const Document & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the document reference and throw an error if invalid.
|
||||
*/
|
||||
void Validate() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the document is allowed to overwrite its contents and throw an error if not.
|
||||
*/
|
||||
@ -40,7 +35,7 @@ protected:
|
||||
private:
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
DocumentRef m_Doc; /* The main xml document instance. */
|
||||
DocumentRef m_Doc; // The main xml document instance.
|
||||
|
||||
public:
|
||||
|
||||
@ -48,7 +43,7 @@ public:
|
||||
* Default constructor.
|
||||
*/
|
||||
Document()
|
||||
: m_Doc(NULL)
|
||||
: m_Doc(nullptr)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@ -67,26 +62,42 @@ public:
|
||||
Int32 Cmp(const Document & o) const
|
||||
{
|
||||
if (m_Doc && !o.m_Doc)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (!m_Doc && o.m_Doc)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (!m_Doc && !o.m_Doc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*m_Doc == *o.m_Doc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (*m_Doc > *o.m_Doc)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
*/
|
||||
CSStr ToString() const
|
||||
{
|
||||
// Do we manage a valid document?
|
||||
if (m_Doc)
|
||||
{
|
||||
return m_Doc->name();
|
||||
}
|
||||
// Default to an empty name
|
||||
return _SC("");
|
||||
}
|
||||
|
||||
@ -117,7 +128,7 @@ public:
|
||||
void Reset()
|
||||
{
|
||||
// Validate the document handle
|
||||
Validate();
|
||||
m_Doc.Validate();
|
||||
// Perform the requested operation
|
||||
m_Doc->reset();
|
||||
}
|
||||
@ -128,10 +139,10 @@ public:
|
||||
void Reset(const Document & doc)
|
||||
{
|
||||
// Validate the document handles
|
||||
Validate();
|
||||
doc.Validate();
|
||||
m_Doc.Validate();
|
||||
doc.m_Doc.Validate();
|
||||
// Perform the requested operation
|
||||
m_Doc->reset(*doc.m_Doc);
|
||||
m_Doc->reset(*(doc.m_Doc));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -186,7 +197,8 @@ public:
|
||||
// Make sure that we are allowed to load in data
|
||||
CanLoad();
|
||||
// Perform the requested operation and return the result
|
||||
return ParseResult(m_Doc, m_Doc->load_file(filepath, options, (xml_encoding)encoding));
|
||||
return ParseResult(m_Doc, m_Doc->load_file(filepath, options,
|
||||
static_cast< xml_encoding >(encoding)));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -195,7 +207,7 @@ public:
|
||||
void SaveFile(CSStr filepath)
|
||||
{
|
||||
// Validate the document handle
|
||||
Validate();
|
||||
m_Doc.Validate();
|
||||
// Perform the requested operation
|
||||
m_Doc->save_file(filepath);
|
||||
}
|
||||
@ -206,7 +218,7 @@ public:
|
||||
void SaveFile(CSStr filepath, CSStr indent)
|
||||
{
|
||||
// Validate the document handle
|
||||
Validate();
|
||||
m_Doc.Validate();
|
||||
// Perform the requested operation
|
||||
m_Doc->save_file(filepath, indent);
|
||||
}
|
||||
@ -217,7 +229,7 @@ public:
|
||||
void SaveFile(CSStr filepath, CSStr indent, Uint32 format)
|
||||
{
|
||||
// Validate the document handle
|
||||
Validate();
|
||||
m_Doc.Validate();
|
||||
// Perform the requested operation
|
||||
m_Doc->save_file(filepath, indent, format);
|
||||
}
|
||||
@ -228,9 +240,9 @@ public:
|
||||
void SaveFile(CSStr filepath, CSStr indent, Uint32 format, Int32 encoding)
|
||||
{
|
||||
// Validate the document handle
|
||||
Validate();
|
||||
m_Doc.Validate();
|
||||
// Perform the requested operation
|
||||
m_Doc->save_file(filepath, indent, format, (xml_encoding)encoding);
|
||||
m_Doc->save_file(filepath, indent, format, static_cast< xml_encoding >(encoding));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
@ -7,12 +7,12 @@
|
||||
#include "Document.hpp"
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
#include <sqrat.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sqrat.h>
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
@ -55,7 +55,9 @@ void OnSquirrelInitialize()
|
||||
_SqMod = sq_api_import(_Func);
|
||||
// Did we failed to obtain the plugin exports?
|
||||
if(!_SqMod)
|
||||
{
|
||||
OutputError("Failed to attach [%s] on host plugin.", SQXML_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Obtain the Squirrel API
|
||||
@ -72,12 +74,16 @@ void OnSquirrelLoad()
|
||||
{
|
||||
// Make sure that we have a valid plugin API
|
||||
if (!_SqMod)
|
||||
return; /* Unable to proceed. */
|
||||
{
|
||||
return; // Unable to proceed.
|
||||
}
|
||||
// Obtain the Squirrel API and VM
|
||||
_SqVM = _SqMod->GetSquirrelVM();
|
||||
// Make sure that a valid virtual machine exists
|
||||
if (!_SqVM)
|
||||
return; /* Unable to proceed. */
|
||||
{
|
||||
return; // Unable to proceed.
|
||||
}
|
||||
// Set this as the default database
|
||||
DefaultVM::Set(_SqVM);
|
||||
// Register the module API
|
||||
@ -105,7 +111,9 @@ bool CheckAPIVer(CCStr ver)
|
||||
long vernum = strtol(ver, NULL, 10);
|
||||
// Check against version mismatch
|
||||
if (vernum == SQMOD_API_VER)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// Log the incident
|
||||
OutputError("API version mismatch on %s", SQXML_NAME);
|
||||
OutputMessage("=> Requested: %ld Have: %ld", vernum, SQMOD_API_VER);
|
||||
@ -122,7 +130,9 @@ static int OnInternalCommand(unsigned int type, const char * text)
|
||||
{
|
||||
case SQMOD_INITIALIZE_CMD:
|
||||
if (CheckAPIVer(text))
|
||||
{
|
||||
OnSquirrelInitialize();
|
||||
}
|
||||
break;
|
||||
case SQMOD_LOAD_CMD:
|
||||
OnSquirrelLoad();
|
||||
@ -171,14 +181,14 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
Table xmlns(vm);
|
||||
|
||||
xmlns.Bind(_SC("ParseResult"), Class< ParseResult >(vm, _SC("SqXmlParseResult"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const ParseResult & >()
|
||||
/* Core Metamethods */
|
||||
// Core Metamethods
|
||||
.Func(_SC("_cmp"), &ParseResult::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &ParseResult::Typename)
|
||||
.Func(_SC("_tostring"), &ParseResult::ToString)
|
||||
/* Properties */
|
||||
// Properties
|
||||
.Prop(_SC("Valid"), &ParseResult::IsValid)
|
||||
.Prop(_SC("References"), &ParseResult::GetRefCount)
|
||||
.Prop(_SC("Ok"), &ParseResult::IsOk)
|
||||
@ -186,19 +196,19 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Offset"), &ParseResult::GetOffset)
|
||||
.Prop(_SC("Encoding"), &ParseResult::GetEncoding)
|
||||
.Prop(_SC("Description"), &ParseResult::GetDescription)
|
||||
/* Functions */
|
||||
// Member Methods
|
||||
.Func(_SC("Check"), &ParseResult::Check)
|
||||
);
|
||||
|
||||
xmlns.Bind(_SC("Attribute"), Class< Attribute >(vm, _SC("SqXmlAttribute"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const Attribute & >()
|
||||
/* Core Metamethods */
|
||||
// Core Metamethods
|
||||
.Func(_SC("_cmp"), &Attribute::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Attribute::Typename)
|
||||
.Func(_SC("_tostring"), &Attribute::ToString)
|
||||
/* Properties */
|
||||
// Properties
|
||||
.Prop(_SC("Valid"), &Attribute::IsValid)
|
||||
.Prop(_SC("References"), &Attribute::GetRefCount)
|
||||
.Prop(_SC("Empty"), &Attribute::IsEmpty)
|
||||
@ -214,7 +224,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Bool"), &Attribute::GetBool, &Attribute::SetBool)
|
||||
.Prop(_SC("Next"), &Attribute::NextAttribute)
|
||||
.Prop(_SC("Prev"), &Attribute::PrevAttribute)
|
||||
/* Functions */
|
||||
// Member Methods
|
||||
.Func(_SC("SetName"), &Attribute::ApplyName)
|
||||
.Func(_SC("SetValue"), &Attribute::ApplyValue)
|
||||
.Func(_SC("AsString"), &Attribute::AsString)
|
||||
@ -236,14 +246,14 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
);
|
||||
|
||||
xmlns.Bind(_SC("Text"), Class< Text >(vm, _SC("SqXmlText"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const Text & >()
|
||||
/* Core Metamethods */
|
||||
// Core Metamethods
|
||||
.Func(_SC("_cmp"), &Text::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Text::Typename)
|
||||
.Func(_SC("_tostring"), &Text::ToString)
|
||||
/* Properties */
|
||||
// Properties
|
||||
.Prop(_SC("Valid"), &Text::IsValid)
|
||||
.Prop(_SC("References"), &Text::GetRefCount)
|
||||
.Prop(_SC("Empty"), &Text::IsEmpty)
|
||||
@ -256,7 +266,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Ulong"), &Text::GetUlong, &Text::SetUlong)
|
||||
.Prop(_SC("Bool"), &Text::GetBool, &Text::SetBool)
|
||||
.Prop(_SC("Data"), &Text::GetData)
|
||||
/* Functions */
|
||||
// Member Methods
|
||||
.Func(_SC("AsString"), &Text::AsString)
|
||||
.Func(_SC("AsInt"), &Text::AsInt)
|
||||
.Func(_SC("AsUint"), &Text::AsUint)
|
||||
@ -276,14 +286,14 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
);
|
||||
|
||||
xmlns.Bind(_SC("Node"), Class< Node >(vm, _SC("SqXmlNode"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const Node & >()
|
||||
/* Core Metamethods */
|
||||
// Core Metamethods
|
||||
.Func(_SC("_cmp"), &Node::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Node::Typename)
|
||||
.Func(_SC("_tostring"), &Node::ToString)
|
||||
/* Properties */
|
||||
// Properties
|
||||
.Prop(_SC("Valid"), &Node::IsValid)
|
||||
.Prop(_SC("References"), &Node::GetRefCount)
|
||||
.Prop(_SC("Empty"), &Node::IsEmpty)
|
||||
@ -302,7 +312,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Root"), &Node::GetRoot)
|
||||
.Prop(_SC("Text"), &Node::GetText)
|
||||
.Prop(_SC("ChildValue"), &Node::GetChildValue)
|
||||
/* Functions */
|
||||
// Member Methods
|
||||
.Overload< ParseResult (Node::*)(CSStr) >(_SC("AppendBuffer"), &Node::AppendBuffer)
|
||||
.Overload< ParseResult (Node::*)(CSStr, Uint32) >(_SC("AppendBuffer"), &Node::AppendBuffer)
|
||||
.Overload< ParseResult (Node::*)(CSStr, Uint32, Int32) >(_SC("AppendBuffer"), &Node::AppendBuffer)
|
||||
@ -352,17 +362,17 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
);
|
||||
|
||||
xmlns.Bind(_SC("Document"), Class< Document, NoCopy< Document > >(vm, _SC("SqXmlDocument"))
|
||||
/* Constructors */
|
||||
// Constructors
|
||||
.Ctor()
|
||||
/* Core Metamethods */
|
||||
// Core Metamethods
|
||||
.Func(_SC("_cmp"), &Document::Cmp)
|
||||
.SquirrelFunc(_SC("_typename"), &Document::Typename)
|
||||
.Func(_SC("_tostring"), &Document::ToString)
|
||||
/* Properties */
|
||||
// Properties
|
||||
.Prop(_SC("Valid"), &Document::IsValid)
|
||||
.Prop(_SC("References"), &Document::GetRefCount)
|
||||
.Prop(_SC("Node"), &Document::GetNode)
|
||||
/* Functions */
|
||||
// Member Methods
|
||||
.Overload< void (Document::*)(void) >(_SC("Reset"), &Document::Reset)
|
||||
.Overload< void (Document::*)(const Document &) >(_SC("Reset"), &Document::Reset)
|
||||
.Overload< ParseResult (Document::*)(CSStr) >(_SC("LoadString"), &Document::LoadData)
|
||||
@ -379,87 +389,87 @@ void RegisterAPI(HSQUIRRELVM vm)
|
||||
RootTable(vm).Bind(_SC("SqXml"), xmlns);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlNodeType"), Enumeration(vm)
|
||||
.Const(_SC("Null"), Int32(node_null))
|
||||
.Const(_SC("Document"), Int32(node_document))
|
||||
.Const(_SC("Element"), Int32(node_element))
|
||||
.Const(_SC("PCData"), Int32(node_pcdata))
|
||||
.Const(_SC("CData"), Int32(node_cdata))
|
||||
.Const(_SC("Comment"), Int32(node_comment))
|
||||
.Const(_SC("Pi"), Int32(node_pi))
|
||||
.Const(_SC("Declaration"), Int32(node_declaration))
|
||||
.Const(_SC("Doctype"), Int32(node_doctype))
|
||||
.Const(_SC("Null"), static_cast< Int32 >(node_null))
|
||||
.Const(_SC("Document"), static_cast< Int32 >(node_document))
|
||||
.Const(_SC("Element"), static_cast< Int32 >(node_element))
|
||||
.Const(_SC("PCData"), static_cast< Int32 >(node_pcdata))
|
||||
.Const(_SC("CData"), static_cast< Int32 >(node_cdata))
|
||||
.Const(_SC("Comment"), static_cast< Int32 >(node_comment))
|
||||
.Const(_SC("Pi"), static_cast< Int32 >(node_pi))
|
||||
.Const(_SC("Declaration"), static_cast< Int32 >(node_declaration))
|
||||
.Const(_SC("Doctype"), static_cast< Int32 >(node_doctype))
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlParse"), Enumeration(vm)
|
||||
.Const(_SC("Minimal"), Int32(parse_minimal))
|
||||
.Const(_SC("Default"), Int32(parse_default))
|
||||
.Const(_SC("Full"), Int32(parse_full))
|
||||
.Const(_SC("Pi"), Int32(parse_pi))
|
||||
.Const(_SC("Comments"), Int32(parse_comments))
|
||||
.Const(_SC("CData"), Int32(parse_cdata))
|
||||
.Const(_SC("WSPCData"), Int32(parse_ws_pcdata))
|
||||
.Const(_SC("Escapes"), Int32(parse_escapes))
|
||||
.Const(_SC("EOL"), Int32(parse_eol))
|
||||
.Const(_SC("WConvAttribute"), Int32(parse_wconv_attribute))
|
||||
.Const(_SC("WNormAttribute"), Int32(parse_wnorm_attribute))
|
||||
.Const(_SC("Declaration"), Int32(parse_declaration))
|
||||
.Const(_SC("Doctype"), Int32(parse_doctype))
|
||||
.Const(_SC("WSPCDataSingle"), Int32(parse_ws_pcdata_single))
|
||||
.Const(_SC("TrimPCData"), Int32(parse_trim_pcdata))
|
||||
.Const(_SC("Fragment"), Int32(parse_fragment))
|
||||
.Const(_SC("EmbedPCData"), Int32(parse_embed_pcdata))
|
||||
.Const(_SC("Minimal"), static_cast< Int32 >(parse_minimal))
|
||||
.Const(_SC("Default"), static_cast< Int32 >(parse_default))
|
||||
.Const(_SC("Full"), static_cast< Int32 >(parse_full))
|
||||
.Const(_SC("Pi"), static_cast< Int32 >(parse_pi))
|
||||
.Const(_SC("Comments"), static_cast< Int32 >(parse_comments))
|
||||
.Const(_SC("CData"), static_cast< Int32 >(parse_cdata))
|
||||
.Const(_SC("WSPCData"), static_cast< Int32 >(parse_ws_pcdata))
|
||||
.Const(_SC("Escapes"), static_cast< Int32 >(parse_escapes))
|
||||
.Const(_SC("EOL"), static_cast< Int32 >(parse_eol))
|
||||
.Const(_SC("WConvAttribute"), static_cast< Int32 >(parse_wconv_attribute))
|
||||
.Const(_SC("WNormAttribute"), static_cast< Int32 >(parse_wnorm_attribute))
|
||||
.Const(_SC("Declaration"), static_cast< Int32 >(parse_declaration))
|
||||
.Const(_SC("Doctype"), static_cast< Int32 >(parse_doctype))
|
||||
.Const(_SC("WSPCDataSingle"), static_cast< Int32 >(parse_ws_pcdata_single))
|
||||
.Const(_SC("TrimPCData"), static_cast< Int32 >(parse_trim_pcdata))
|
||||
.Const(_SC("Fragment"), static_cast< Int32 >(parse_fragment))
|
||||
.Const(_SC("EmbedPCData"), static_cast< Int32 >(parse_embed_pcdata))
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlEncoding"), Enumeration(vm)
|
||||
.Const(_SC("Auto"), Int32(encoding_auto))
|
||||
.Const(_SC("Utf8"), Int32(encoding_utf8))
|
||||
.Const(_SC("Utf16LE"), Int32(encoding_utf16_le))
|
||||
.Const(_SC("Utf16BE"), Int32(encoding_utf16_be))
|
||||
.Const(_SC("Utf16"), Int32(encoding_utf16))
|
||||
.Const(_SC("Utf32LE"), Int32(encoding_utf32_le))
|
||||
.Const(_SC("Utf32BE"), Int32(encoding_utf32_be))
|
||||
.Const(_SC("Utf32"), Int32(encoding_utf32))
|
||||
.Const(_SC("WChar"), Int32(encoding_wchar))
|
||||
.Const(_SC("Latin1"), Int32(encoding_latin1))
|
||||
.Const(_SC("Auto"), static_cast< Int32 >(encoding_auto))
|
||||
.Const(_SC("Utf8"), static_cast< Int32 >(encoding_utf8))
|
||||
.Const(_SC("Utf16LE"), static_cast< Int32 >(encoding_utf16_le))
|
||||
.Const(_SC("Utf16BE"), static_cast< Int32 >(encoding_utf16_be))
|
||||
.Const(_SC("Utf16"), static_cast< Int32 >(encoding_utf16))
|
||||
.Const(_SC("Utf32LE"), static_cast< Int32 >(encoding_utf32_le))
|
||||
.Const(_SC("Utf32BE"), static_cast< Int32 >(encoding_utf32_be))
|
||||
.Const(_SC("Utf32"), static_cast< Int32 >(encoding_utf32))
|
||||
.Const(_SC("WChar"), static_cast< Int32 >(encoding_wchar))
|
||||
.Const(_SC("Latin1"), static_cast< Int32 >(encoding_latin1))
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlFormat"), Enumeration(vm)
|
||||
.Const(_SC("Indent"), Int32(format_indent))
|
||||
.Const(_SC("WriteBOM"), Int32(format_write_bom))
|
||||
.Const(_SC("Raw"), Int32(format_raw))
|
||||
.Const(_SC("NoDeclaration"), Int32(format_no_declaration))
|
||||
.Const(_SC("NoEscapes"), Int32(format_no_escapes))
|
||||
.Const(_SC("SaveFileText"), Int32(format_save_file_text))
|
||||
.Const(_SC("IndentAttributes"), Int32(format_indent_attributes))
|
||||
.Const(_SC("Default"), Int32(format_default))
|
||||
.Const(_SC("Indent"), static_cast< Int32 >(format_indent))
|
||||
.Const(_SC("WriteBOM"), static_cast< Int32 >(format_write_bom))
|
||||
.Const(_SC("Raw"), static_cast< Int32 >(format_raw))
|
||||
.Const(_SC("NoDeclaration"), static_cast< Int32 >(format_no_declaration))
|
||||
.Const(_SC("NoEscapes"), static_cast< Int32 >(format_no_escapes))
|
||||
.Const(_SC("SaveFileText"), static_cast< Int32 >(format_save_file_text))
|
||||
.Const(_SC("IndentAttributes"), static_cast< Int32 >(format_indent_attributes))
|
||||
.Const(_SC("Default"), static_cast< Int32 >(format_default))
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlParseStatus"), Enumeration(vm)
|
||||
.Const(_SC("Ok"), Int32(status_ok))
|
||||
.Const(_SC("FileNotFound"), Int32(status_file_not_found))
|
||||
.Const(_SC("IOError"), Int32(status_io_error))
|
||||
.Const(_SC("OutOfMemory"), Int32(status_out_of_memory))
|
||||
.Const(_SC("InternalError"), Int32(status_internal_error))
|
||||
.Const(_SC("UnrecognizedTag"), Int32(status_unrecognized_tag))
|
||||
.Const(_SC("BadPi"), Int32(status_bad_pi))
|
||||
.Const(_SC("BadComment"), Int32(status_bad_comment))
|
||||
.Const(_SC("BadCData"), Int32(status_bad_cdata))
|
||||
.Const(_SC("BadDoctype"), Int32(status_bad_doctype))
|
||||
.Const(_SC("BadPCData"), Int32(status_bad_pcdata))
|
||||
.Const(_SC("BadStartElement"), Int32(status_bad_start_element))
|
||||
.Const(_SC("BadAttribute"), Int32(status_bad_attribute))
|
||||
.Const(_SC("BadEndElement"), Int32(status_bad_end_element))
|
||||
.Const(_SC("EndElementMismatch"), Int32(status_end_element_mismatch))
|
||||
.Const(_SC("AppendInvalidRoot"), Int32(status_append_invalid_root))
|
||||
.Const(_SC("NoDocumentElement"), Int32(status_no_document_element))
|
||||
.Const(_SC("Ok"), static_cast< Int32 >(status_ok))
|
||||
.Const(_SC("FileNotFound"), static_cast< Int32 >(status_file_not_found))
|
||||
.Const(_SC("IOError"), static_cast< Int32 >(status_io_error))
|
||||
.Const(_SC("OutOfMemory"), static_cast< Int32 >(status_out_of_memory))
|
||||
.Const(_SC("InternalError"), static_cast< Int32 >(status_internal_error))
|
||||
.Const(_SC("UnrecognizedTag"), static_cast< Int32 >(status_unrecognized_tag))
|
||||
.Const(_SC("BadPi"), static_cast< Int32 >(status_bad_pi))
|
||||
.Const(_SC("BadComment"), static_cast< Int32 >(status_bad_comment))
|
||||
.Const(_SC("BadCData"), static_cast< Int32 >(status_bad_cdata))
|
||||
.Const(_SC("BadDoctype"), static_cast< Int32 >(status_bad_doctype))
|
||||
.Const(_SC("BadPCData"), static_cast< Int32 >(status_bad_pcdata))
|
||||
.Const(_SC("BadStartElement"), static_cast< Int32 >(status_bad_start_element))
|
||||
.Const(_SC("BadAttribute"), static_cast< Int32 >(status_bad_attribute))
|
||||
.Const(_SC("BadEndElement"), static_cast< Int32 >(status_bad_end_element))
|
||||
.Const(_SC("EndElementMismatch"), static_cast< Int32 >(status_end_element_mismatch))
|
||||
.Const(_SC("AppendInvalidRoot"), static_cast< Int32 >(status_append_invalid_root))
|
||||
.Const(_SC("NoDocumentElement"), static_cast< Int32 >(status_no_document_element))
|
||||
);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlXpathValueType"), Enumeration(vm)
|
||||
.Const(_SC("None"), Int32(xpath_type_none))
|
||||
.Const(_SC("NodeSet"), Int32(xpath_type_node_set))
|
||||
.Const(_SC("Number"), Int32(xpath_type_number))
|
||||
.Const(_SC("String"), Int32(xpath_type_string))
|
||||
.Const(_SC("Boolean"), Int32(xpath_type_boolean))
|
||||
.Const(_SC("None"), static_cast< Int32 >(xpath_type_none))
|
||||
.Const(_SC("NodeSet"), static_cast< Int32 >(xpath_type_node_set))
|
||||
.Const(_SC("Number"), static_cast< Int32 >(xpath_type_number))
|
||||
.Const(_SC("String"), static_cast< Int32 >(xpath_type_string))
|
||||
.Const(_SC("Boolean"), static_cast< Int32 >(xpath_type_boolean))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -15,14 +15,6 @@ SQInteger Node::Typename(HSQUIRRELVM vm)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Node::Validate() const
|
||||
{
|
||||
// Validate the document handle
|
||||
if (!m_Doc)
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Attribute Node::GetFirstAttr() const
|
||||
{
|
||||
|
@ -30,16 +30,11 @@ protected:
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the document reference and throw an error if invalid.
|
||||
*/
|
||||
void Validate() const;
|
||||
|
||||
private:
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
DocumentRef m_Doc; /* The main xml document instance. */
|
||||
Type m_Node; /* The managed document node. */
|
||||
DocumentRef m_Doc; // The main xml document instance.
|
||||
Type m_Node; // The managed document node.
|
||||
|
||||
public:
|
||||
|
||||
@ -85,12 +80,18 @@ public:
|
||||
Int32 Cmp(const Node & o)
|
||||
{
|
||||
if (m_Node == o.m_Node)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (m_Node > o.m_Node)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Used by the script engine to convert an instance of this type to a string.
|
||||
@ -134,7 +135,7 @@ public:
|
||||
*/
|
||||
SQInteger GetHashValue() const
|
||||
{
|
||||
return (SQInteger)m_Node.hash_value();
|
||||
return static_cast< SQInteger >(m_Node.hash_value());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -142,7 +143,7 @@ public:
|
||||
*/
|
||||
SQInteger GetOffsetDebug() const
|
||||
{
|
||||
return (SQInteger)m_Node.offset_debug();
|
||||
return static_cast< SQInteger >(m_Node.offset_debug());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -150,7 +151,7 @@ public:
|
||||
*/
|
||||
Int32 GetType() const
|
||||
{
|
||||
return (Int32)m_Node.type();
|
||||
return static_cast< Int32 >(m_Node.type());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -167,8 +168,10 @@ public:
|
||||
void SetName(CSStr name)
|
||||
{
|
||||
if (!m_Node.set_name(name))
|
||||
{
|
||||
STHROWF("Unable to set XML node name");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the node name.
|
||||
@ -192,8 +195,10 @@ public:
|
||||
void SetValue(CSStr name)
|
||||
{
|
||||
if (!m_Node.set_value(name))
|
||||
{
|
||||
STHROWF("Unable to set XML node value");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the node value.
|
||||
@ -208,9 +213,13 @@ public:
|
||||
*/
|
||||
ParseResult AppendBuffer(CSStr source)
|
||||
{
|
||||
// Is the specified source buffer even valid?
|
||||
if (source)
|
||||
{
|
||||
return ParseResult(m_Doc, m_Node.append_buffer(source,
|
||||
std::char_traits< SQChar >::length(source) * sizeof(SQChar)));
|
||||
}
|
||||
// Return the default result
|
||||
return ParseResult();
|
||||
}
|
||||
|
||||
@ -219,9 +228,13 @@ public:
|
||||
*/
|
||||
ParseResult AppendBuffer(CSStr source, Uint32 options)
|
||||
{
|
||||
// Is the specified source buffer even valid?
|
||||
if (source)
|
||||
{
|
||||
return ParseResult(m_Doc, m_Node.append_buffer(source,
|
||||
std::char_traits< SQChar >::length(source) * sizeof(SQChar), options));
|
||||
}
|
||||
// Return the default result
|
||||
return ParseResult();
|
||||
}
|
||||
|
||||
@ -230,10 +243,14 @@ public:
|
||||
*/
|
||||
ParseResult AppendBuffer(CSStr source, Uint32 options, Int32 encoding)
|
||||
{
|
||||
// Is the specified source buffer even valid?
|
||||
if (source)
|
||||
{
|
||||
return ParseResult(m_Doc, m_Node.append_buffer(source,
|
||||
std::char_traits< SQChar >::length(source) * sizeof(SQChar)
|
||||
, options, (xml_encoding)encoding));
|
||||
std::char_traits< SQChar >::length(source) * sizeof(SQChar),
|
||||
options, (xml_encoding)encoding));
|
||||
}
|
||||
// Return the default result
|
||||
return ParseResult();
|
||||
}
|
||||
|
||||
@ -427,7 +444,7 @@ public:
|
||||
*/
|
||||
Node AppendChildType(Int32 type)
|
||||
{
|
||||
return Node(m_Doc, m_Node.append_child((xml_node_type)type));
|
||||
return Node(m_Doc, m_Node.append_child(static_cast< xml_node_type >(type)));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -435,7 +452,7 @@ public:
|
||||
*/
|
||||
Node PrependChildType(Int32 type)
|
||||
{
|
||||
return Node(m_Doc, m_Node.prepend_child((xml_node_type)type));
|
||||
return Node(m_Doc, m_Node.prepend_child(static_cast< xml_node_type >(type)));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -459,7 +476,8 @@ public:
|
||||
*/
|
||||
Node InsertChildTypeAfter(Int32 type, const Node & node)
|
||||
{
|
||||
return Node(m_Doc, m_Node.insert_child_after((xml_node_type)type, node.m_Node));
|
||||
return Node(m_Doc, m_Node.insert_child_after(static_cast< xml_node_type >(type),
|
||||
node.m_Node));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -467,7 +485,8 @@ public:
|
||||
*/
|
||||
Node InsertChildTypeBefore(Int32 type, const Node & node)
|
||||
{
|
||||
return Node(m_Doc, m_Node.insert_child_before((xml_node_type)type, node.m_Node));
|
||||
return Node(m_Doc, m_Node.insert_child_before(static_cast< xml_node_type >(type),
|
||||
node.m_Node));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -503,7 +522,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Append the specified node as a child and take ownersip of it.
|
||||
* Append the specified node as a child and take ownership of it.
|
||||
*/
|
||||
Node AppendMove(const Node & proto)
|
||||
{
|
||||
@ -511,7 +530,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Prepend the specified node as a child and take ownersip of it.
|
||||
* Prepend the specified node as a child and take ownership of it.
|
||||
*/
|
||||
Node PrependMove(const Node & proto)
|
||||
{
|
||||
@ -519,7 +538,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Insert the specified node as a child after the specified node and take ownersip of it.
|
||||
* Insert the specified node as a child after the specified node and take ownership of it.
|
||||
*/
|
||||
Node InsertMoveAfter(const Node & proto, const Node & node)
|
||||
{
|
||||
@ -527,7 +546,7 @@ public:
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Insert the specified node as a child before the specified node and take ownersip of it.
|
||||
* Insert the specified node as a child before the specified node and take ownership of it.
|
||||
*/
|
||||
Node InsertMoveBefore(const Node & proto, const Node & node)
|
||||
{
|
||||
|
@ -4,7 +4,9 @@
|
||||
#include "Module.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqrat.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -18,24 +20,22 @@ SQInteger Text::Typename(HSQUIRRELVM vm)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Text::Validate() const
|
||||
{
|
||||
// Validate the document handle
|
||||
if (!m_Doc)
|
||||
STHROWF("Invalid XML document reference");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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
|
||||
@ -48,7 +48,9 @@ Object Text::AsLong(Object & def) const
|
||||
Int64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("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 and return it
|
||||
@ -66,7 +68,9 @@ Object Text::AsUlong(Object & def) const
|
||||
Uint64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("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 and return it
|
||||
@ -84,7 +88,9 @@ bool Text::ApplyLong(Object & value)
|
||||
Int64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value and return the result
|
||||
return m_Text.set(longint);
|
||||
}
|
||||
@ -100,7 +106,9 @@ bool Text::ApplyUlong(Object & value)
|
||||
Uint64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value and return the result
|
||||
return m_Text.set(longint);
|
||||
}
|
||||
@ -127,7 +135,9 @@ void Text::SetLong(Object & value)
|
||||
Int64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetSLongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value
|
||||
m_Text = longint;
|
||||
}
|
||||
@ -154,7 +164,9 @@ void Text::SetUlong(Object & value)
|
||||
Uint64 longint = 0;
|
||||
// Attempt to get the numeric value inside the specified object
|
||||
if (SQ_FAILED(_SqMod->GetULongValue(_SqVM, -1, &longint)))
|
||||
{
|
||||
STHROWF("Invalid long integer specified");
|
||||
}
|
||||
// Assign the obtained value
|
||||
m_Text = longint;
|
||||
}
|
||||
|
@ -29,16 +29,11 @@ protected:
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the document reference and throw an error if invalid.
|
||||
*/
|
||||
void Validate() const;
|
||||
|
||||
private:
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
DocumentRef m_Doc; /* The main xml document instance. */
|
||||
Type m_Text; /* The managed document node. */
|
||||
DocumentRef m_Doc; // The main xml document instance.
|
||||
Type m_Text; // The managed document node.
|
||||
|
||||
public:
|
||||
|
||||
@ -156,7 +151,7 @@ public:
|
||||
*/
|
||||
SQFloat AsFloat(SQFloat def) const
|
||||
{
|
||||
return (SQFloat)m_Text.as_float(def);
|
||||
return static_cast< SQFloat >(m_Text.as_float(static_cast< Float32 >(def)));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -164,7 +159,7 @@ public:
|
||||
*/
|
||||
SQFloat AsDouble(SQFloat def) const
|
||||
{
|
||||
return (SQFloat)m_Text.as_double(def);
|
||||
return static_cast< SQFloat >(m_Text.as_double(static_cast< Float64 >(def)));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -296,7 +291,7 @@ public:
|
||||
*/
|
||||
SQFloat GetFloat() const
|
||||
{
|
||||
return (SQFloat)m_Text.as_float();
|
||||
return static_cast< SQFloat >(m_Text.as_float());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -312,7 +307,7 @@ public:
|
||||
*/
|
||||
SQFloat GetDouble() const
|
||||
{
|
||||
return (SQFloat)m_Text.as_double();
|
||||
return static_cast< SQFloat >(m_Text.as_double());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user