mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-04-19 02:37:12 +02:00
Update the XML module to work with the modified API.
Separate the XML handles into their own source files.
This commit is contained in:
parent
4d77386b21
commit
a792ae525e
@ -417,12 +417,19 @@
|
|||||||
<Unit filename="../modules/xml/Common.hpp" />
|
<Unit filename="../modules/xml/Common.hpp" />
|
||||||
<Unit filename="../modules/xml/Document.cpp" />
|
<Unit filename="../modules/xml/Document.cpp" />
|
||||||
<Unit filename="../modules/xml/Document.hpp" />
|
<Unit filename="../modules/xml/Document.hpp" />
|
||||||
|
<Unit filename="../modules/xml/Handle/Document.cpp" />
|
||||||
|
<Unit filename="../modules/xml/Handle/Document.hpp" />
|
||||||
<Unit filename="../modules/xml/Module.cpp" />
|
<Unit filename="../modules/xml/Module.cpp" />
|
||||||
<Unit filename="../modules/xml/Module.hpp" />
|
|
||||||
<Unit filename="../modules/xml/Node.cpp" />
|
<Unit filename="../modules/xml/Node.cpp" />
|
||||||
<Unit filename="../modules/xml/Node.hpp" />
|
<Unit filename="../modules/xml/Node.hpp" />
|
||||||
<Unit filename="../modules/xml/Text.cpp" />
|
<Unit filename="../modules/xml/Text.cpp" />
|
||||||
<Unit filename="../modules/xml/Text.hpp" />
|
<Unit filename="../modules/xml/Text.hpp" />
|
||||||
|
<Unit filename="../modules/xml/Wrapper/ParseResult.cpp" />
|
||||||
|
<Unit filename="../modules/xml/Wrapper/ParseResult.hpp" />
|
||||||
|
<Unit filename="../shared/Base/Buffer.cpp" />
|
||||||
|
<Unit filename="../shared/Base/Buffer.hpp" />
|
||||||
|
<Unit filename="../shared/Base/Utility.cpp" />
|
||||||
|
<Unit filename="../shared/Base/Utility.hpp" />
|
||||||
<Unit filename="../shared/SqMod.cpp" />
|
<Unit filename="../shared/SqMod.cpp" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<code_completion />
|
<code_completion />
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Attribute.hpp"
|
#include "Attribute.hpp"
|
||||||
#include "Module.hpp"
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include <sqrat.h>
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef _XML_ATTRIBUTE_HPP_
|
#ifndef _SQXML_ATTRIBUTE_HPP_
|
||||||
#define _XML_ATTRIBUTE_HPP_
|
#define _SQXML_ATTRIBUTE_HPP_
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Common.hpp"
|
#include "Handle/Document.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
@ -442,4 +442,4 @@ public:
|
|||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
#endif // _XML_ATTRIBUTE_HPP_
|
#endif // _SQXML_ATTRIBUTE_HPP_
|
@ -1,119 +1,9 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Common.hpp"
|
#include "Common.hpp"
|
||||||
#include "Module.hpp"
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include <cstdarg>
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include <sqrat.h>
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
static SQChar g_Buffer[4096]; // Common buffer to reduce memory allocations.
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
SStr GetTempBuff()
|
|
||||||
{
|
|
||||||
return g_Buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
Uint32 GetTempBuffSize()
|
|
||||||
{
|
|
||||||
return sizeof(g_Buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void SqThrowF(CSStr str, ...)
|
|
||||||
{
|
|
||||||
// Initialize the argument list
|
|
||||||
va_list args;
|
|
||||||
va_start (args, str);
|
|
||||||
// Write the requested contents
|
|
||||||
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
|
|
||||||
throw Sqrat::Exception(g_Buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
CSStr FmtStr(CSStr str, ...)
|
|
||||||
{
|
|
||||||
// Initialize the argument list
|
|
||||||
va_list args;
|
|
||||||
va_start (args, str);
|
|
||||||
// Write the requested contents
|
|
||||||
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_VM(vm), m_Top(sq_gettop(vm))
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
static const SQChar name[] = _SC("SqXmlParseResult");
|
|
||||||
sq_pushstring(vm, name, sizeof(name));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
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
|
} // Namespace:: SqMod
|
||||||
|
@ -1,21 +1,12 @@
|
|||||||
#ifndef _XML_COMMON_HPP_
|
#ifndef _SQXML_COMMON_HPP_
|
||||||
#define _XML_COMMON_HPP_
|
#define _SQXML_COMMON_HPP_
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "ModBase.hpp"
|
#include "Base/Utility.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
extern "C" {
|
|
||||||
struct SQVM;
|
|
||||||
typedef struct SQVM* HSQUIRRELVM;
|
|
||||||
} /*extern "C"*/
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
@ -45,458 +36,8 @@ class XPathNodeSet;
|
|||||||
class XPathVariable;
|
class XPathVariable;
|
||||||
class XPathVariableSet;
|
class XPathVariableSet;
|
||||||
class XPathVariableQuery;
|
class XPathVariableQuery;
|
||||||
|
class ParseResult;
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Retrieve the temporary buffer.
|
|
||||||
*/
|
|
||||||
SStr GetTempBuff();
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Retrieve the size of the temporary buffer.
|
|
||||||
*/
|
|
||||||
Uint32 GetTempBuffSize();
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Throw a formatted exception.
|
|
||||||
*/
|
|
||||||
void SqThrowF(CSStr str, ...);
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Generate a formatted string.
|
|
||||||
*/
|
|
||||||
CSStr FmtStr(CSStr str, ...);
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Implements RAII to restore the VM stack to it's initial size on function exit.
|
|
||||||
*/
|
|
||||||
struct StackGuard
|
|
||||||
{
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Default constructor.
|
|
||||||
*/
|
|
||||||
StackGuard();
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Base constructor.
|
|
||||||
*/
|
|
||||||
StackGuard(HSQUIRRELVM vm);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~StackGuard();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy constructor.
|
|
||||||
*/
|
|
||||||
StackGuard(const StackGuard &);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Move constructor.
|
|
||||||
*/
|
|
||||||
StackGuard(StackGuard &&);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy assignment operator.
|
|
||||||
*/
|
|
||||||
StackGuard & operator = (const StackGuard &);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Move assignment operator.
|
|
||||||
*/
|
|
||||||
StackGuard & operator = (StackGuard &&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
HSQUIRRELVM m_VM; // The VM where the stack should be restored.
|
|
||||||
Int32 m_Top; // The top of the stack when this instance was created.
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Manages a reference counted xml document instance.
|
|
||||||
*/
|
|
||||||
class DocumentRef
|
|
||||||
{
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
friend class Document;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
typedef xml_document Type; /* The managed type. */
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
typedef Type* Pointer; /* Pointer to the managed type. */
|
|
||||||
typedef const Type* ConstPtr; /* Constant pointer to the managed type. */
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
typedef Type& Reference; /* Reference to the managed type. */
|
|
||||||
typedef const Type& ConstRef; /* Constant reference to the managed type. */
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
typedef unsigned int Counter; /* Reference counter type. */
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Validate the managed handle and throw exception if invalid.
|
|
||||||
*/
|
|
||||||
void Validate() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
Pointer m_Ptr; /* The document reader, writer and manager instance. */
|
|
||||||
Counter* m_Ref; /* Reference count to the managed instance. */
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Grab a strong reference to a document instance.
|
|
||||||
*/
|
|
||||||
void Grab()
|
|
||||||
{
|
|
||||||
if (m_Ptr)
|
|
||||||
++(*m_Ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Drop a strong reference to a document instance.
|
|
||||||
*/
|
|
||||||
void Drop()
|
|
||||||
{
|
|
||||||
if (m_Ptr && --(*m_Ref) == 0)
|
|
||||||
{
|
|
||||||
delete m_Ptr;
|
|
||||||
delete m_Ref;
|
|
||||||
m_Ptr = NULL;
|
|
||||||
m_Ref = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Base constructor.
|
|
||||||
*/
|
|
||||||
DocumentRef(VoidP /* unused */)
|
|
||||||
: m_Ptr(new Type())
|
|
||||||
, m_Ref(new Counter(1))
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Default constructor (null).
|
|
||||||
*/
|
|
||||||
DocumentRef()
|
|
||||||
: m_Ptr(NULL), m_Ref(NULL)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy constructor.
|
|
||||||
*/
|
|
||||||
DocumentRef(const DocumentRef & o)
|
|
||||||
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
|
||||||
|
|
||||||
{
|
|
||||||
Grab();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Move constructor.
|
|
||||||
*/
|
|
||||||
DocumentRef(DocumentRef && o)
|
|
||||||
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
|
||||||
{
|
|
||||||
o.m_Ptr = NULL;
|
|
||||||
o.m_Ref = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~DocumentRef()
|
|
||||||
{
|
|
||||||
Drop();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy assignment operator.
|
|
||||||
*/
|
|
||||||
DocumentRef & operator = (const DocumentRef & o)
|
|
||||||
{
|
|
||||||
if (m_Ptr != o.m_Ptr)
|
|
||||||
{
|
|
||||||
Drop();
|
|
||||||
m_Ptr = o.m_Ptr;
|
|
||||||
m_Ref = o.m_Ref;
|
|
||||||
Grab();
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Move assignment operator.
|
|
||||||
*/
|
|
||||||
DocumentRef & operator = (DocumentRef && o)
|
|
||||||
{
|
|
||||||
if (m_Ptr != o.m_Ptr)
|
|
||||||
{
|
|
||||||
m_Ptr = o.m_Ptr;
|
|
||||||
m_Ref = o.m_Ref;
|
|
||||||
o.m_Ptr = NULL;
|
|
||||||
o.m_Ref = NULL;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Perform an equality comparison between two document instances.
|
|
||||||
*/
|
|
||||||
bool operator == (const DocumentRef & o) const
|
|
||||||
{
|
|
||||||
return (m_Ptr == o.m_Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Perform an inequality comparison between two document instances.
|
|
||||||
*/
|
|
||||||
bool operator != (const DocumentRef & o) const
|
|
||||||
{
|
|
||||||
return (m_Ptr != o.m_Ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Implicit conversion to boolean for use in boolean operations.
|
|
||||||
*/
|
|
||||||
operator bool () const
|
|
||||||
{
|
|
||||||
return m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Implicit conversion to the managed instance pointer.
|
|
||||||
*/
|
|
||||||
operator Pointer ()
|
|
||||||
{
|
|
||||||
return m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Implicit conversion to the managed instance pointer.
|
|
||||||
*/
|
|
||||||
operator ConstPtr () const
|
|
||||||
{
|
|
||||||
return m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Implicit conversion to the managed instance reference.
|
|
||||||
*/
|
|
||||||
operator Reference ()
|
|
||||||
{
|
|
||||||
assert(m_Ptr);
|
|
||||||
return *m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Implicit conversion to the managed instance reference.
|
|
||||||
*/
|
|
||||||
operator ConstRef () const
|
|
||||||
{
|
|
||||||
assert(m_Ptr);
|
|
||||||
return *m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Member operator for dereferencing the managed pointer.
|
|
||||||
*/
|
|
||||||
Pointer operator -> () const
|
|
||||||
{
|
|
||||||
assert(m_Ptr);
|
|
||||||
return m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Indirection operator for obtaining a reference of the managed pointer.
|
|
||||||
*/
|
|
||||||
Reference operator * () const
|
|
||||||
{
|
|
||||||
assert(m_Ptr);
|
|
||||||
return *m_Ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Retrieve the number of active references to the managed instance.
|
|
||||||
*/
|
|
||||||
Counter Count() const
|
|
||||||
{
|
|
||||||
return (m_Ptr && m_Ref) ? (*m_Ref) : 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Allows the user to inspect the result of certain operations and act accordingly.
|
|
||||||
*/
|
|
||||||
class ParseResult
|
|
||||||
{
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
friend class Document;
|
|
||||||
friend class Node;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
typedef xml_parse_result Result;
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Explicit constructor.
|
|
||||||
*/
|
|
||||||
ParseResult(const DocumentRef doc, const Result & result)
|
|
||||||
: m_Doc(doc), m_Result(result)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Validate the document reference and throw an error if invalid.
|
|
||||||
*/
|
|
||||||
void Validate() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
|
||||||
DocumentRef m_Doc; /* The main xml document instance. */
|
|
||||||
Result m_Result; /* The managed parse result. */
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Default constructor.
|
|
||||||
*/
|
|
||||||
ParseResult()
|
|
||||||
: m_Doc(), m_Result()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy constructor. (disabled)
|
|
||||||
*/
|
|
||||||
ParseResult(const ParseResult & o)
|
|
||||||
: m_Doc(o.m_Doc), m_Result(o.m_Result)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~ParseResult()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy assignment operator. (disabled)
|
|
||||||
*/
|
|
||||||
ParseResult & operator = (const ParseResult & o)
|
|
||||||
{
|
|
||||||
m_Doc = o.m_Doc;
|
|
||||||
m_Result = o.m_Result;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Used by the script engine to compare two instances of this type.
|
|
||||||
*/
|
|
||||||
Int32 Cmp(const ParseResult & o)
|
|
||||||
{
|
|
||||||
if (m_Result.status == o.m_Result.status)
|
|
||||||
return 0;
|
|
||||||
else if (m_Result.status > o.m_Result.status)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Used by the script engine to convert an instance of this type to a string.
|
|
||||||
*/
|
|
||||||
CSStr ToString() const
|
|
||||||
{
|
|
||||||
return m_Result.description();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Used by the script engine to retrieve the name from instances of this type.
|
|
||||||
*/
|
|
||||||
static SQInteger Typename(HSQUIRRELVM vm);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* See whether this instance references a valid xml document.
|
|
||||||
*/
|
|
||||||
bool IsValid() const
|
|
||||||
{
|
|
||||||
return m_Doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Return the number of active references to this document instance.
|
|
||||||
*/
|
|
||||||
Uint32 GetRefCount() const
|
|
||||||
{
|
|
||||||
return m_Doc.Count();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Cast to bool operator.
|
|
||||||
*/
|
|
||||||
bool IsOk() const
|
|
||||||
{
|
|
||||||
return m_Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Parsing status code.
|
|
||||||
*/
|
|
||||||
Int32 GetStatus() const
|
|
||||||
{
|
|
||||||
return (Int32)m_Result.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Last parsed offset. (in char_t units from start of input data)
|
|
||||||
*/
|
|
||||||
SQInteger GetOffset() const
|
|
||||||
{
|
|
||||||
return (SQInteger)m_Result.offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Source document encoding.
|
|
||||||
*/
|
|
||||||
Int32 GetEncoding() const
|
|
||||||
{
|
|
||||||
return m_Result.encoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Retrieve error description as a string.
|
|
||||||
*/
|
|
||||||
CSStr GetDescription() const
|
|
||||||
{
|
|
||||||
return m_Result.description();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Check the parse result and throw the necessary errors.
|
|
||||||
*/
|
|
||||||
void Check() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
#endif // _XML_COMMON_HPP_
|
#endif // _SQXML_COMMON_HPP_
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Document.hpp"
|
#include "Document.hpp"
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#include "Module.hpp"
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef _XML_DOCUMENT_HPP_
|
#ifndef _SQXML_DOCUMENT_HPP_
|
||||||
#define _XML_DOCUMENT_HPP_
|
#define _SQXML_DOCUMENT_HPP_
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Common.hpp"
|
#include "Handle/Document.hpp"
|
||||||
|
#include "Wrapper/ParseResult.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
@ -253,4 +254,4 @@ public:
|
|||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
#endif // _XML_DOCUMENT_HPP_
|
#endif // _SQXML_DOCUMENT_HPP_
|
||||||
|
16
modules/xml/Handle/Document.cpp
Normal file
16
modules/xml/Handle/Document.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
#include "Handle/Document.hpp"
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
namespace SqMod {
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void DocumentRef::Validate() const
|
||||||
|
{
|
||||||
|
if (!m_Ptr)
|
||||||
|
{
|
||||||
|
STHROWF("Invalid XML document reference");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Namespace:: SqMod
|
236
modules/xml/Handle/Document.hpp
Normal file
236
modules/xml/Handle/Document.hpp
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
#ifndef _SQXML_HANDLE_DOCUMENT_HPP_
|
||||||
|
#define _SQXML_HANDLE_DOCUMENT_HPP_
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
#include "Common.hpp"
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
namespace SqMod {
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* Manages a reference counted xml document instance.
|
||||||
|
*/
|
||||||
|
class DocumentRef
|
||||||
|
{
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
friend class Document;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
typedef xml_document Type; /* The managed type. */
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
typedef Type* Pointer; /* Pointer to the managed type. */
|
||||||
|
typedef const Type* ConstPtr; /* Constant pointer to the managed type. */
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
typedef Type& Reference; /* Reference to the managed type. */
|
||||||
|
typedef const Type& ConstRef; /* Constant reference to the managed type. */
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
typedef unsigned int Counter; /* Reference counter type. */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Validate the managed handle and throw exception if invalid.
|
||||||
|
*/
|
||||||
|
void Validate() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
Pointer m_Ptr; /* The document reader, writer and manager instance. */
|
||||||
|
Counter* m_Ref; /* Reference count to the managed instance. */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Grab a strong reference to a document instance.
|
||||||
|
*/
|
||||||
|
void Grab()
|
||||||
|
{
|
||||||
|
if (m_Ptr)
|
||||||
|
{
|
||||||
|
++(*m_Ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Drop a strong reference to a document instance.
|
||||||
|
*/
|
||||||
|
void Drop()
|
||||||
|
{
|
||||||
|
if (m_Ptr && --(*m_Ref) == 0)
|
||||||
|
{
|
||||||
|
delete m_Ptr;
|
||||||
|
delete m_Ref;
|
||||||
|
m_Ptr = NULL;
|
||||||
|
m_Ref = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Base constructor.
|
||||||
|
*/
|
||||||
|
DocumentRef(VoidP /* unused */)
|
||||||
|
: m_Ptr(new Type())
|
||||||
|
, m_Ref(new Counter(1))
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Default constructor (null).
|
||||||
|
*/
|
||||||
|
DocumentRef()
|
||||||
|
: m_Ptr(NULL), m_Ref(NULL)
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy constructor.
|
||||||
|
*/
|
||||||
|
DocumentRef(const DocumentRef & o)
|
||||||
|
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
||||||
|
|
||||||
|
{
|
||||||
|
Grab();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move constructor.
|
||||||
|
*/
|
||||||
|
DocumentRef(DocumentRef && o)
|
||||||
|
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
||||||
|
{
|
||||||
|
o.m_Ptr = NULL;
|
||||||
|
o.m_Ref = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
~DocumentRef()
|
||||||
|
{
|
||||||
|
Drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy assignment operator.
|
||||||
|
*/
|
||||||
|
DocumentRef & operator = (const DocumentRef & o)
|
||||||
|
{
|
||||||
|
if (m_Ptr != o.m_Ptr)
|
||||||
|
{
|
||||||
|
Drop();
|
||||||
|
m_Ptr = o.m_Ptr;
|
||||||
|
m_Ref = o.m_Ref;
|
||||||
|
Grab();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Move assignment operator.
|
||||||
|
*/
|
||||||
|
DocumentRef & operator = (DocumentRef && o)
|
||||||
|
{
|
||||||
|
if (m_Ptr != o.m_Ptr)
|
||||||
|
{
|
||||||
|
m_Ptr = o.m_Ptr;
|
||||||
|
m_Ref = o.m_Ref;
|
||||||
|
o.m_Ptr = NULL;
|
||||||
|
o.m_Ref = NULL;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Perform an equality comparison between two document instances.
|
||||||
|
*/
|
||||||
|
bool operator == (const DocumentRef & o) const
|
||||||
|
{
|
||||||
|
return (m_Ptr == o.m_Ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Perform an inequality comparison between two document instances.
|
||||||
|
*/
|
||||||
|
bool operator != (const DocumentRef & o) const
|
||||||
|
{
|
||||||
|
return (m_Ptr != o.m_Ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to boolean for use in boolean operations.
|
||||||
|
*/
|
||||||
|
operator bool () const
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to the managed instance pointer.
|
||||||
|
*/
|
||||||
|
operator Pointer ()
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to the managed instance pointer.
|
||||||
|
*/
|
||||||
|
operator ConstPtr () const
|
||||||
|
{
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to the managed instance reference.
|
||||||
|
*/
|
||||||
|
operator Reference ()
|
||||||
|
{
|
||||||
|
assert(m_Ptr);
|
||||||
|
return *m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Implicit conversion to the managed instance reference.
|
||||||
|
*/
|
||||||
|
operator ConstRef () const
|
||||||
|
{
|
||||||
|
assert(m_Ptr);
|
||||||
|
return *m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Member operator for dereferencing the managed pointer.
|
||||||
|
*/
|
||||||
|
Pointer operator -> () const
|
||||||
|
{
|
||||||
|
assert(m_Ptr);
|
||||||
|
return m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Indirection operator for obtaining a reference of the managed pointer.
|
||||||
|
*/
|
||||||
|
Reference operator * () const
|
||||||
|
{
|
||||||
|
assert(m_Ptr);
|
||||||
|
return *m_Ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve the number of active references to the managed instance.
|
||||||
|
*/
|
||||||
|
Counter Count() const
|
||||||
|
{
|
||||||
|
return (m_Ptr && m_Ref) ? (*m_Ref) : 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
|
#endif // _SQXML_HANDLE_DOCUMENT_HPP_
|
@ -1,38 +1,20 @@
|
|||||||
// --------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Module.hpp"
|
|
||||||
#include "Common.hpp"
|
#include "Common.hpp"
|
||||||
#include "Attribute.hpp"
|
#include "Attribute.hpp"
|
||||||
#include "Text.hpp"
|
#include "Text.hpp"
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#include "Document.hpp"
|
#include "Document.hpp"
|
||||||
|
#include "Wrapper/ParseResult.hpp"
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdarg>
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
#include <sqrat.h>
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
|
||||||
#include <Windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
PluginFuncs* _Func = nullptr;
|
|
||||||
PluginCallbacks* _Clbk = nullptr;
|
|
||||||
PluginInfo* _Info = nullptr;
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
HSQAPI _SqAPI = nullptr;
|
|
||||||
HSQEXPORTS _SqMod = nullptr;
|
|
||||||
HSQUIRRELVM _SqVM = nullptr;
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Bind speciffic functions to certain server events.
|
* Bind specific functions to certain server events.
|
||||||
*/
|
*/
|
||||||
void BindCallbacks();
|
void BindCallbacks();
|
||||||
|
|
||||||
@ -41,22 +23,22 @@ void BindCallbacks();
|
|||||||
*/
|
*/
|
||||||
void UnbindCallbacks();
|
void UnbindCallbacks();
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Register the module API under the specified virtual machine.
|
* Register the module API under the specified virtual machine.
|
||||||
*/
|
*/
|
||||||
void RegisterAPI(HSQUIRRELVM vm);
|
void RegisterAPI(HSQUIRRELVM vm);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Initialize the plugin by obtaining the API provided by the host plugin.
|
* Initialize the plug-in by obtaining the API provided by the host plug-in.
|
||||||
*/
|
*/
|
||||||
void OnSquirrelInitialize()
|
void OnSquirrelInitialize()
|
||||||
{
|
{
|
||||||
// Attempt to import the plugin API exported by the host plugin
|
// Attempt to import the plug-in API exported by the host plug-in
|
||||||
_SqMod = sq_api_import(_Func);
|
_SqMod = sq_api_import(_Func);
|
||||||
// Did we failed to obtain the plugin exports?
|
// Did we failed to obtain the plug-in exports?
|
||||||
if(!_SqMod)
|
if (!_SqMod)
|
||||||
{
|
{
|
||||||
OutputError("Failed to attach [%s] on host plugin.", SQXML_NAME);
|
OutputError("Failed to attach [%s] on host plug-in.", SQXML_NAME);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -67,12 +49,12 @@ void OnSquirrelInitialize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Load the module on the virtual machine provided by the host module.
|
* Load the module on the virtual machine provided by the host module.
|
||||||
*/
|
*/
|
||||||
void OnSquirrelLoad()
|
void OnSquirrelLoad()
|
||||||
{
|
{
|
||||||
// Make sure that we have a valid plugin API
|
// Make sure that we have a valid plug-in API
|
||||||
if (!_SqMod)
|
if (!_SqMod)
|
||||||
{
|
{
|
||||||
return; // Unable to proceed!
|
return; // Unable to proceed!
|
||||||
@ -92,23 +74,28 @@ void OnSquirrelLoad()
|
|||||||
OutputMessage("Registered: %s", SQXML_NAME);
|
OutputMessage("Registered: %s", SQXML_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* The virtual machine is about to be terminated and script resources should be released.
|
* The virtual machine is about to be terminated and script resources should be released.
|
||||||
*/
|
*/
|
||||||
void OnSquirrelTerminate()
|
void OnSquirrelTerminate()
|
||||||
{
|
{
|
||||||
OutputMessage("Terminating: %s", SQXML_NAME);
|
OutputMessage("Terminating: %s", SQXML_NAME);
|
||||||
|
// Release null objects just in case
|
||||||
|
NullObject().Release();
|
||||||
|
NullTable().Release();
|
||||||
|
NullArray().Release();
|
||||||
|
NullFunction().ReleaseGently();
|
||||||
// Release the current virtual machine, if any
|
// Release the current virtual machine, if any
|
||||||
DefaultVM::Set(nullptr);
|
DefaultVM::Set(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Validate the module API to make sure we don't run into issues.
|
* Validate the module API to make sure we don't run into issues.
|
||||||
*/
|
*/
|
||||||
bool CheckAPIVer(CCStr ver)
|
bool CheckAPIVer(CCStr ver)
|
||||||
{
|
{
|
||||||
// Obtain the numeric representation of the API version
|
// Obtain the numeric representation of the API version
|
||||||
long vernum = std::strtol(ver, nullptr, 10);
|
const LongI vernum = std::strtol(ver, nullptr, 10);
|
||||||
// Check against version mismatch
|
// Check against version mismatch
|
||||||
if (vernum == SQMOD_API_VER)
|
if (vernum == SQMOD_API_VER)
|
||||||
{
|
{
|
||||||
@ -121,8 +108,8 @@ bool CheckAPIVer(CCStr ver)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* React to command sent by other plugins.
|
* React to command sent by other plug-ins.
|
||||||
*/
|
*/
|
||||||
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
|
static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
|
||||||
{
|
{
|
||||||
@ -145,8 +132,8 @@ static uint8_t OnPluginCommand(uint32_t command_identifier, CCStr message)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* The server was initialized and this plugin was loaded successfully.
|
* The server was initialized and this plug-in was loaded successfully.
|
||||||
*/
|
*/
|
||||||
static uint8_t OnServerInitialise()
|
static uint8_t OnServerInitialise()
|
||||||
{
|
{
|
||||||
@ -175,7 +162,7 @@ void UnbindCallbacks()
|
|||||||
_Clbk->OnPluginCommand = nullptr;
|
_Clbk->OnPluginCommand = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void RegisterAPI(HSQUIRRELVM vm)
|
void RegisterAPI(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
Table xmlns(vm);
|
Table xmlns(vm);
|
||||||
@ -184,7 +171,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
|||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const ParseResult & >()
|
.Ctor< const ParseResult & >()
|
||||||
// Core Metamethods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &ParseResult::Cmp)
|
.Func(_SC("_cmp"), &ParseResult::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &ParseResult::Typename)
|
.SquirrelFunc(_SC("_typename"), &ParseResult::Typename)
|
||||||
.Func(_SC("_tostring"), &ParseResult::ToString)
|
.Func(_SC("_tostring"), &ParseResult::ToString)
|
||||||
@ -204,7 +191,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
|||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const Attribute & >()
|
.Ctor< const Attribute & >()
|
||||||
// Core Metamethods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &Attribute::Cmp)
|
.Func(_SC("_cmp"), &Attribute::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &Attribute::Typename)
|
.SquirrelFunc(_SC("_typename"), &Attribute::Typename)
|
||||||
.Func(_SC("_tostring"), &Attribute::ToString)
|
.Func(_SC("_tostring"), &Attribute::ToString)
|
||||||
@ -249,7 +236,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
|||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const Text & >()
|
.Ctor< const Text & >()
|
||||||
// Core Metamethods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &Text::Cmp)
|
.Func(_SC("_cmp"), &Text::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &Text::Typename)
|
.SquirrelFunc(_SC("_typename"), &Text::Typename)
|
||||||
.Func(_SC("_tostring"), &Text::ToString)
|
.Func(_SC("_tostring"), &Text::ToString)
|
||||||
@ -289,7 +276,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
|||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const Node & >()
|
.Ctor< const Node & >()
|
||||||
// Core Metamethods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &Node::Cmp)
|
.Func(_SC("_cmp"), &Node::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &Node::Typename)
|
.SquirrelFunc(_SC("_typename"), &Node::Typename)
|
||||||
.Func(_SC("_tostring"), &Node::ToString)
|
.Func(_SC("_tostring"), &Node::ToString)
|
||||||
@ -364,7 +351,7 @@ void RegisterAPI(HSQUIRRELVM vm)
|
|||||||
xmlns.Bind(_SC("Document"), Class< Document, NoCopy< Document > >(vm, _SC("SqXmlDocument"))
|
xmlns.Bind(_SC("Document"), Class< Document, NoCopy< Document > >(vm, _SC("SqXmlDocument"))
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
// Core Metamethods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &Document::Cmp)
|
.Func(_SC("_cmp"), &Document::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &Document::Typename)
|
.SquirrelFunc(_SC("_typename"), &Document::Typename)
|
||||||
.Func(_SC("_tostring"), &Document::ToString)
|
.Func(_SC("_tostring"), &Document::ToString)
|
||||||
@ -473,119 +460,33 @@ void RegisterAPI(HSQUIRRELVM vm)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
void OutputMessageImpl(const char * msg, va_list args)
|
|
||||||
{
|
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
|
||||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
|
||||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
|
||||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
|
|
||||||
std::printf("[SQMOD] ");
|
|
||||||
|
|
||||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
|
||||||
std::vprintf(msg, args);
|
|
||||||
std::puts("");
|
|
||||||
|
|
||||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
|
||||||
#else
|
|
||||||
std::printf("%c[0;32m[SQMOD]%c[0m", 27, 27);
|
|
||||||
std::vprintf(msg, args);
|
|
||||||
std::puts("");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
void OutputErrorImpl(const char * msg, va_list args)
|
|
||||||
{
|
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
|
||||||
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csb_before;
|
|
||||||
GetConsoleScreenBufferInfo( hstdout, &csb_before);
|
|
||||||
SetConsoleTextAttribute(hstdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
|
||||||
std::printf("[SQMOD] ");
|
|
||||||
|
|
||||||
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
|
|
||||||
std::vprintf(msg, args);
|
|
||||||
std::puts("");
|
|
||||||
|
|
||||||
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
|
|
||||||
#else
|
|
||||||
std::printf("%c[0;91m[SQMOD]%c[0m", 27, 27);
|
|
||||||
std::vprintf(msg, args);
|
|
||||||
std::puts("");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
void OutputDebug(const char * msg, ...)
|
|
||||||
{
|
|
||||||
#ifdef _DEBUG
|
|
||||||
// Initialize the arguments list
|
|
||||||
va_list args;
|
|
||||||
va_start(args, msg);
|
|
||||||
// Call the output function
|
|
||||||
OutputMessageImpl(msg, args);
|
|
||||||
// Finalize the arguments list
|
|
||||||
va_end(args);
|
|
||||||
#else
|
|
||||||
SQMOD_UNUSED_VAR(msg);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
void OutputMessage(const char * msg, ...)
|
|
||||||
{
|
|
||||||
// Initialize the arguments list
|
|
||||||
va_list args;
|
|
||||||
va_start(args, msg);
|
|
||||||
// Call the output function
|
|
||||||
OutputMessageImpl(msg, args);
|
|
||||||
// Finalize the arguments list
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
|
||||||
void OutputError(const char * msg, ...)
|
|
||||||
{
|
|
||||||
// Initialize the arguments list
|
|
||||||
va_list args;
|
|
||||||
va_start(args, msg);
|
|
||||||
// Call the output function
|
|
||||||
OutputErrorImpl(msg, args);
|
|
||||||
// Finalize the arguments list
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallbacks* callbacks, PluginInfo* info)
|
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * functions, PluginCallbacks * callbacks, PluginInfo * info)
|
||||||
{
|
{
|
||||||
using namespace SqMod;
|
using namespace SqMod;
|
||||||
// Output plugin header
|
// Output plug-in header
|
||||||
puts("");
|
puts("");
|
||||||
OutputMessage("--------------------------------------------------------------------");
|
OutputMessage("--------------------------------------------------------------------");
|
||||||
OutputMessage("Plugin: %s", SQXML_NAME);
|
OutputMessage("Plug-in: %s", SQXML_NAME);
|
||||||
OutputMessage("Author: %s", SQXML_AUTHOR);
|
OutputMessage("Author: %s", SQXML_AUTHOR);
|
||||||
OutputMessage("Legal: %s", SQXML_COPYRIGHT);
|
OutputMessage("Legal: %s", SQXML_COPYRIGHT);
|
||||||
OutputMessage("--------------------------------------------------------------------");
|
OutputMessage("--------------------------------------------------------------------");
|
||||||
puts("");
|
puts("");
|
||||||
// Attempt to find the host plugin ID
|
// Attempt to find the host plug-in ID
|
||||||
int host_plugin_id = functions->FindPlugin((char *)(SQMOD_HOST_NAME));
|
const int host_plugin_id = functions->FindPlugin(SQMOD_HOST_NAME);
|
||||||
// See if our plugin was loaded after the host plugin
|
// See if our plug-in was loaded after the host plug-in
|
||||||
if (host_plugin_id < 0)
|
if (host_plugin_id < 0)
|
||||||
{
|
{
|
||||||
OutputError("%s could find the host plugin", SQXML_NAME);
|
OutputError("%s could find the host plug-in", SQXML_NAME);
|
||||||
// Don't load!
|
// Don't load!
|
||||||
return SQMOD_FAILURE;
|
return SQMOD_FAILURE;
|
||||||
}
|
}
|
||||||
// Should never reach this point but just in case
|
// Should never reach this point but just in case
|
||||||
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
|
else if (static_cast< Uint32 >(host_plugin_id) > info->pluginId)
|
||||||
{
|
{
|
||||||
OutputError("%s loaded after the host plugin", SQXML_NAME);
|
OutputError("%s loaded after the host plug-in", SQXML_NAME);
|
||||||
// Don't load!
|
// Don't load!
|
||||||
return SQMOD_FAILURE;
|
return SQMOD_FAILURE;
|
||||||
}
|
}
|
||||||
@ -593,15 +494,15 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallb
|
|||||||
_Func = functions;
|
_Func = functions;
|
||||||
_Clbk = callbacks;
|
_Clbk = callbacks;
|
||||||
_Info = info;
|
_Info = info;
|
||||||
// Assign plugin version
|
// Assign plug-in version
|
||||||
_Info->pluginVersion = SQXML_VERSION;
|
_Info->pluginVersion = SQXML_VERSION;
|
||||||
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
|
_Info->apiMajorVersion = PLUGIN_API_MAJOR;
|
||||||
_Info->apiMinorVersion = PLUGIN_API_MINOR;
|
_Info->apiMinorVersion = PLUGIN_API_MINOR;
|
||||||
// Assign the plugin name
|
// Assign the plug-in name
|
||||||
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQXML_HOST_NAME);
|
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQXML_HOST_NAME);
|
||||||
// Bind callbacks
|
// Bind callbacks
|
||||||
BindCallbacks();
|
BindCallbacks();
|
||||||
// Notify that the plugin was successfully loaded
|
// Notify that the plug-in was successfully loaded
|
||||||
OutputMessage("Successfully loaded %s", SQXML_NAME);
|
OutputMessage("Successfully loaded %s", SQXML_NAME);
|
||||||
// Dummy spacing
|
// Dummy spacing
|
||||||
puts("");
|
puts("");
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
#ifndef _XML_MODULE_HPP_
|
|
||||||
#define _XML_MODULE_HPP_
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include "SqMod.h"
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
namespace SqMod {
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Proxies to comunicate with the server.
|
|
||||||
*/
|
|
||||||
extern PluginFuncs* _Func;
|
|
||||||
extern PluginCallbacks* _Clbk;
|
|
||||||
extern PluginInfo* _Info;
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Proxies to comunicate with the Squirrel plugin.
|
|
||||||
*/
|
|
||||||
extern HSQAPI _SqAPI;
|
|
||||||
extern HSQEXPORTS _SqMod;
|
|
||||||
extern HSQUIRRELVM _SqVM;
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Output a message only if the _DEBUG was defined.
|
|
||||||
*/
|
|
||||||
void OutputDebug(const char * msg, ...);
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Output a formatted user message to the console.
|
|
||||||
*/
|
|
||||||
void OutputMessage(const char * msg, ...);
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
|
||||||
* Output a formatted error message to the console.
|
|
||||||
*/
|
|
||||||
void OutputError(const char * msg, ...);
|
|
||||||
|
|
||||||
} // Namespace:: SqMod
|
|
||||||
|
|
||||||
#endif // _XML_MODULE_HPP_
|
|
@ -2,7 +2,6 @@
|
|||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#include "Attribute.hpp"
|
#include "Attribute.hpp"
|
||||||
#include "Text.hpp"
|
#include "Text.hpp"
|
||||||
#include "Module.hpp"
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef _XML_NODE_HPP_
|
#ifndef _SQXML_NODE_HPP_
|
||||||
#define _XML_NODE_HPP_
|
#define _SQXML_NODE_HPP_
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Common.hpp"
|
#include "Handle/Document.hpp"
|
||||||
|
#include "Wrapper/ParseResult.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
@ -609,4 +610,4 @@ public:
|
|||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
#endif // _XML_NODE_HPP_
|
#endif // _SQXML_NODE_HPP_
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Text.hpp"
|
#include "Text.hpp"
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#include "Module.hpp"
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
#include <sqrat.h>
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef _XML_TEXT_HPP_
|
#ifndef _SQXML_TEXT_HPP_
|
||||||
#define _XML_TEXT_HPP_
|
#define _SQXML_TEXT_HPP_
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
#include "Common.hpp"
|
#include "Handle/Document.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
@ -362,4 +362,4 @@ public:
|
|||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
#endif // _XML_TEXT_HPP_
|
#endif // _SQXML_TEXT_HPP_
|
34
modules/xml/Wrapper/ParseResult.cpp
Normal file
34
modules/xml/Wrapper/ParseResult.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
#include "Wrapper/ParseResult.hpp"
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
namespace SqMod {
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
SQInteger ParseResult::Typename(HSQUIRRELVM vm)
|
||||||
|
{
|
||||||
|
static const SQChar name[] = _SC("SqXmlParseResult");
|
||||||
|
sq_pushstring(vm, name, sizeof(name));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
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
|
178
modules/xml/Wrapper/ParseResult.hpp
Normal file
178
modules/xml/Wrapper/ParseResult.hpp
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
#ifndef _SQXML_WRAPPER_PARSERESULT_HPP_
|
||||||
|
#define _SQXML_WRAPPER_PARSERESULT_HPP_
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
#include "Handle/Document.hpp"
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
namespace SqMod {
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------------
|
||||||
|
* Allows the user to inspect the result of certain operations and act accordingly.
|
||||||
|
*/
|
||||||
|
class ParseResult
|
||||||
|
{
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
friend class Document;
|
||||||
|
friend class Node;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------------------
|
||||||
|
typedef xml_parse_result Result;
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Explicit constructor.
|
||||||
|
*/
|
||||||
|
ParseResult(const DocumentRef doc, const Result & result)
|
||||||
|
: m_Doc(doc), m_Result(result)
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Validate the document reference and throw an error if invalid.
|
||||||
|
*/
|
||||||
|
void Validate() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
DocumentRef m_Doc; /* The main xml document instance. */
|
||||||
|
Result m_Result; /* The managed parse result. */
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
ParseResult()
|
||||||
|
: m_Doc(), m_Result()
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy constructor. (disabled)
|
||||||
|
*/
|
||||||
|
ParseResult(const ParseResult & o)
|
||||||
|
: m_Doc(o.m_Doc), m_Result(o.m_Result)
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
~ParseResult()
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Copy assignment operator. (disabled)
|
||||||
|
*/
|
||||||
|
ParseResult & operator = (const ParseResult & o)
|
||||||
|
{
|
||||||
|
m_Doc = o.m_Doc;
|
||||||
|
m_Result = o.m_Result;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Used by the script engine to compare two instances of this type.
|
||||||
|
*/
|
||||||
|
Int32 Cmp(const ParseResult & o)
|
||||||
|
{
|
||||||
|
if (m_Result.status == o.m_Result.status)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (m_Result.status > o.m_Result.status)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Used by the script engine to convert an instance of this type to a string.
|
||||||
|
*/
|
||||||
|
CSStr ToString() const
|
||||||
|
{
|
||||||
|
return m_Result.description();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Used by the script engine to retrieve the name from instances of this type.
|
||||||
|
*/
|
||||||
|
static SQInteger Typename(HSQUIRRELVM vm);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* See whether this instance references a valid xml document.
|
||||||
|
*/
|
||||||
|
bool IsValid() const
|
||||||
|
{
|
||||||
|
return m_Doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Return the number of active references to this document instance.
|
||||||
|
*/
|
||||||
|
Uint32 GetRefCount() const
|
||||||
|
{
|
||||||
|
return m_Doc.Count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Cast to bool operator.
|
||||||
|
*/
|
||||||
|
bool IsOk() const
|
||||||
|
{
|
||||||
|
return m_Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Parsing status code.
|
||||||
|
*/
|
||||||
|
Int32 GetStatus() const
|
||||||
|
{
|
||||||
|
return (Int32)m_Result.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Last parsed offset. (in char_t units from start of input data)
|
||||||
|
*/
|
||||||
|
SQInteger GetOffset() const
|
||||||
|
{
|
||||||
|
return (SQInteger)m_Result.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Source document encoding.
|
||||||
|
*/
|
||||||
|
Int32 GetEncoding() const
|
||||||
|
{
|
||||||
|
return m_Result.encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve error description as a string.
|
||||||
|
*/
|
||||||
|
CSStr GetDescription() const
|
||||||
|
{
|
||||||
|
return m_Result.description();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Check the parse result and throw the necessary errors.
|
||||||
|
*/
|
||||||
|
void Check() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Namespace:: SqMod
|
||||||
|
|
||||||
|
#endif // _SQXML_WRAPPER_PARSERESULT_HPP_
|
Loading…
x
Reference in New Issue
Block a user