mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +01:00
Cleanup XML library code.
This commit is contained in:
parent
c9de01e8a3
commit
91c0f2ec02
@ -5,61 +5,11 @@
|
|||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void DocumentRef::Validate() const
|
SQMODE_DECL_TYPENAME(XmlParseResultTypename, _SC("SqXmlParseResult"))
|
||||||
{
|
SQMODE_DECL_TYPENAME(XmlDocumentTypename, _SC("SqXmlDocument"))
|
||||||
if (!m_Ptr)
|
SQMODE_DECL_TYPENAME(XmlNodeTypename, _SC("SqXmlNode"))
|
||||||
{
|
SQMODE_DECL_TYPENAME(XmlAttributeTypename, _SC("SqXmlAttribute"))
|
||||||
STHROWF("Invalid XML document reference");
|
SQMODE_DECL_TYPENAME(XmlTextTypename, _SC("SqXmlText"))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
SQInteger XmlParseResult::Typename(HSQUIRRELVM vm)
|
|
||||||
{
|
|
||||||
static const SQChar name[] = _SC("SqXmlParseResult");
|
|
||||||
sq_pushstring(vm, name, sizeof(name));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void XmlParseResult::Validate() const
|
|
||||||
{
|
|
||||||
// Is the documen handle valid?
|
|
||||||
if (!m_Doc)
|
|
||||||
{
|
|
||||||
STHROWF("Invalid XML document reference");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void XmlParseResult::Check() const
|
|
||||||
{
|
|
||||||
if (m_Result.status != status_ok)
|
|
||||||
{
|
|
||||||
STHROWF("XML parse error [%s]", m_Result.description());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
SQInteger XmlDocument::Typename(HSQUIRRELVM vm)
|
|
||||||
{
|
|
||||||
static const SQChar name[] = _SC("SqXmlDocument");
|
|
||||||
sq_pushstring(vm, name, sizeof(name));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void XmlDocument::CanLoad() const
|
|
||||||
{
|
|
||||||
// Is the document even valid?
|
|
||||||
m_Doc.Validate();
|
|
||||||
// Are there any other references?
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
XmlNode XmlDocument::GetNode() const
|
XmlNode XmlDocument::GetNode() const
|
||||||
@ -70,14 +20,6 @@ XmlNode XmlDocument::GetNode() const
|
|||||||
return XmlNode(m_Doc, m_Doc->document_element());
|
return XmlNode(m_Doc, m_Doc->document_element());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
SQInteger XmlNode::Typename(HSQUIRRELVM vm)
|
|
||||||
{
|
|
||||||
static const SQChar name[] = _SC("SqXmlNode");
|
|
||||||
sq_pushstring(vm, name, sizeof(name));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
XmlAttribute XmlNode::GetFirstAttr() const
|
XmlAttribute XmlNode::GetFirstAttr() const
|
||||||
{
|
{
|
||||||
@ -162,14 +104,6 @@ bool XmlNode::RemoveAttrInst(const XmlAttribute & attr)
|
|||||||
return m_Node.remove_attribute(attr.m_Attr);
|
return m_Node.remove_attribute(attr.m_Attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
SQInteger XmlAttribute::Typename(HSQUIRRELVM vm)
|
|
||||||
{
|
|
||||||
static const SQChar name[] = _SC("SqXmlAttribute");
|
|
||||||
sq_pushstring(vm, name, sizeof(name));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
LightObj XmlAttribute::AsLong(const SLongInt & def) const
|
LightObj XmlAttribute::AsLong(const SLongInt & def) const
|
||||||
{
|
{
|
||||||
@ -218,31 +152,6 @@ void XmlAttribute::SetUlong(const ULongInt & value)
|
|||||||
m_Attr = value.GetNum();
|
m_Attr = value.GetNum();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
SQInteger XmlText::Typename(HSQUIRRELVM vm)
|
|
||||||
{
|
|
||||||
static const SQChar name[] = _SC("SqXmlText");
|
|
||||||
sq_pushstring(vm, name, sizeof(name));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
Int32 XmlText::Cmp(const XmlText & 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
LightObj XmlText::AsLong(const SLongInt & def) const
|
LightObj XmlText::AsLong(const SLongInt & def) const
|
||||||
{
|
{
|
||||||
@ -302,13 +211,13 @@ void Register_XML(HSQUIRRELVM vm)
|
|||||||
{
|
{
|
||||||
Table xmlns(vm);
|
Table xmlns(vm);
|
||||||
|
|
||||||
xmlns.Bind(_SC("XmlParseResult"), Class< XmlParseResult >(vm, _SC("SqXmlParseResult"))
|
xmlns.Bind(_SC("XmlParseResult"), Class< XmlParseResult >(vm, XmlParseResultTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const XmlParseResult & >()
|
.Ctor< const XmlParseResult & >()
|
||||||
// Core Meta-methods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &XmlParseResult::Cmp)
|
.Func(_SC("_cmp"), &XmlParseResult::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &XmlParseResult::Typename)
|
.SquirrelFunc(_SC("_typename"), &XmlParseResultTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &XmlParseResult::ToString)
|
.Func(_SC("_tostring"), &XmlParseResult::ToString)
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Valid"), &XmlParseResult::IsValid)
|
.Prop(_SC("Valid"), &XmlParseResult::IsValid)
|
||||||
@ -322,13 +231,13 @@ void Register_XML(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("Check"), &XmlParseResult::Check)
|
.Func(_SC("Check"), &XmlParseResult::Check)
|
||||||
);
|
);
|
||||||
|
|
||||||
xmlns.Bind(_SC("XmlAttribute"), Class< XmlAttribute >(vm, _SC("SqXmlAttribute"))
|
xmlns.Bind(_SC("XmlAttribute"), Class< XmlAttribute >(vm, XmlAttributeTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const XmlAttribute & >()
|
.Ctor< const XmlAttribute & >()
|
||||||
// Core Meta-methods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &XmlAttribute::Cmp)
|
.Func(_SC("_cmp"), &XmlAttribute::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &XmlAttribute::Typename)
|
.SquirrelFunc(_SC("_typename"), &XmlAttributeTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &XmlAttribute::ToString)
|
.Func(_SC("_tostring"), &XmlAttribute::ToString)
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Valid"), &XmlAttribute::IsValid)
|
.Prop(_SC("Valid"), &XmlAttribute::IsValid)
|
||||||
@ -367,13 +276,13 @@ void Register_XML(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("SetBool"), &XmlAttribute::ApplyBool)
|
.Func(_SC("SetBool"), &XmlAttribute::ApplyBool)
|
||||||
);
|
);
|
||||||
|
|
||||||
xmlns.Bind(_SC("XmlText"), Class< XmlText >(vm, _SC("SqXmlText"))
|
xmlns.Bind(_SC("XmlText"), Class< XmlText >(vm, XmlTextTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const XmlText & >()
|
.Ctor< const XmlText & >()
|
||||||
// Core Meta-methods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &XmlText::Cmp)
|
.Func(_SC("_cmp"), &XmlText::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &XmlText::Typename)
|
.SquirrelFunc(_SC("_typename"), &XmlTextTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &XmlText::ToString)
|
.Func(_SC("_tostring"), &XmlText::ToString)
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Valid"), &XmlText::IsValid)
|
.Prop(_SC("Valid"), &XmlText::IsValid)
|
||||||
@ -407,13 +316,13 @@ void Register_XML(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("SetBool"), &XmlText::ApplyBool)
|
.Func(_SC("SetBool"), &XmlText::ApplyBool)
|
||||||
);
|
);
|
||||||
|
|
||||||
xmlns.Bind(_SC("XmlNode"), Class< XmlNode >(vm, _SC("SqXmlNode"))
|
xmlns.Bind(_SC("XmlNode"), Class< XmlNode >(vm, XmlNodeTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< const XmlNode & >()
|
.Ctor< const XmlNode & >()
|
||||||
// Core Meta-methods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &XmlNode::Cmp)
|
.Func(_SC("_cmp"), &XmlNode::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &XmlNode::Typename)
|
.SquirrelFunc(_SC("_typename"), &XmlNodeTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &XmlNode::ToString)
|
.Func(_SC("_tostring"), &XmlNode::ToString)
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Valid"), &XmlNode::IsValid)
|
.Prop(_SC("Valid"), &XmlNode::IsValid)
|
||||||
@ -483,12 +392,12 @@ void Register_XML(HSQUIRRELVM vm)
|
|||||||
.Func(_SC("FindElemByPath"), &XmlNode::FindElemByPath)
|
.Func(_SC("FindElemByPath"), &XmlNode::FindElemByPath)
|
||||||
);
|
);
|
||||||
|
|
||||||
xmlns.Bind(_SC("XmlDocument"), Class< XmlDocument, NoCopy< XmlDocument > >(vm, _SC("SqXmlDocument"))
|
xmlns.Bind(_SC("XmlDocument"), Class< XmlDocument, NoCopy< XmlDocument > >(vm, XmlDocumentTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
// Core Meta-methods
|
// Core Meta-methods
|
||||||
.Func(_SC("_cmp"), &XmlDocument::Cmp)
|
.Func(_SC("_cmp"), &XmlDocument::Cmp)
|
||||||
.SquirrelFunc(_SC("_typename"), &XmlDocument::Typename)
|
.SquirrelFunc(_SC("_typename"), &XmlDocumentTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &XmlDocument::ToString)
|
.Func(_SC("_tostring"), &XmlDocument::ToString)
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Valid"), &XmlDocument::IsValid)
|
.Prop(_SC("Valid"), &XmlDocument::IsValid)
|
||||||
|
@ -21,11 +21,6 @@ class XmlNode;
|
|||||||
class XmlText;
|
class XmlText;
|
||||||
class XmlDocument;
|
class XmlDocument;
|
||||||
class XmlAttribute;
|
class XmlAttribute;
|
||||||
class XPathNode;
|
|
||||||
class XPathNodeSet;
|
|
||||||
class XPathVariable;
|
|
||||||
class XPathVariableSet;
|
|
||||||
class XPathVariableQuery;
|
|
||||||
class XmlParseResult;
|
class XmlParseResult;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@ -55,7 +50,13 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Validate the managed handle and throw exception if invalid.
|
* Validate the managed handle and throw exception if invalid.
|
||||||
*/
|
*/
|
||||||
void Validate() const;
|
void Validate() const
|
||||||
|
{
|
||||||
|
if (!m_Ptr)
|
||||||
|
{
|
||||||
|
STHROWF("Invalid XML document reference");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -83,28 +84,28 @@ private:
|
|||||||
{
|
{
|
||||||
delete m_Ptr;
|
delete m_Ptr;
|
||||||
delete m_Ref;
|
delete m_Ref;
|
||||||
m_Ptr = NULL;
|
m_Ptr = nullptr;
|
||||||
m_Ref = NULL;
|
m_Ref = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Base constructor.
|
|
||||||
*/
|
|
||||||
DocumentRef(VoidP /* unused */)
|
|
||||||
: m_Ptr(new Type())
|
|
||||||
, m_Ref(new Counter(1))
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default constructor (null).
|
* Default constructor (null).
|
||||||
*/
|
*/
|
||||||
DocumentRef()
|
DocumentRef()
|
||||||
: m_Ptr(NULL), m_Ref(NULL)
|
: m_Ptr(nullptr), m_Ref(nullptr)
|
||||||
|
{
|
||||||
|
/* ... */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Base constructor.
|
||||||
|
*/
|
||||||
|
explicit DocumentRef(std::nullptr_t SQ_UNUSED_ARG(p)) //NOLINT (yes, I am using this constructor)
|
||||||
|
: m_Ptr(new Type())
|
||||||
|
, m_Ref(new Counter(1))
|
||||||
{
|
{
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
@ -122,11 +123,11 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Move constructor.
|
* Move constructor.
|
||||||
*/
|
*/
|
||||||
DocumentRef(DocumentRef && o)
|
DocumentRef(DocumentRef && o) noexcept
|
||||||
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
: m_Ptr(o.m_Ptr), m_Ref(o.m_Ref)
|
||||||
{
|
{
|
||||||
o.m_Ptr = NULL;
|
o.m_Ptr = nullptr;
|
||||||
o.m_Ref = NULL;
|
o.m_Ref = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
@ -140,7 +141,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy assignment operator.
|
* Copy assignment operator.
|
||||||
*/
|
*/
|
||||||
DocumentRef & operator = (const DocumentRef & o)
|
DocumentRef & operator = (const DocumentRef & o) //NOLINT (yes, I am checking for self assignment!)
|
||||||
{
|
{
|
||||||
if (m_Ptr != o.m_Ptr)
|
if (m_Ptr != o.m_Ptr)
|
||||||
{
|
{
|
||||||
@ -155,14 +156,14 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Move assignment operator.
|
* Move assignment operator.
|
||||||
*/
|
*/
|
||||||
DocumentRef & operator = (DocumentRef && o)
|
DocumentRef & operator = (DocumentRef && o) noexcept
|
||||||
{
|
{
|
||||||
if (m_Ptr != o.m_Ptr)
|
if (m_Ptr != o.m_Ptr)
|
||||||
{
|
{
|
||||||
m_Ptr = o.m_Ptr;
|
m_Ptr = o.m_Ptr;
|
||||||
m_Ref = o.m_Ref;
|
m_Ref = o.m_Ref;
|
||||||
o.m_Ptr = NULL;
|
o.m_Ptr = nullptr;
|
||||||
o.m_Ref = NULL;
|
o.m_Ref = nullptr;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -186,7 +187,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Implicit conversion to boolean for use in boolean operations.
|
* Implicit conversion to boolean for use in boolean operations.
|
||||||
*/
|
*/
|
||||||
operator bool () const
|
operator bool () const //NOLINT (intentionally implicit)
|
||||||
{
|
{
|
||||||
return m_Ptr;
|
return m_Ptr;
|
||||||
}
|
}
|
||||||
@ -194,7 +195,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Implicit conversion to the managed instance pointer.
|
* Implicit conversion to the managed instance pointer.
|
||||||
*/
|
*/
|
||||||
operator Pointer ()
|
operator Pointer () //NOLINT (intentionally implicit)
|
||||||
{
|
{
|
||||||
return m_Ptr;
|
return m_Ptr;
|
||||||
}
|
}
|
||||||
@ -202,7 +203,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Implicit conversion to the managed instance pointer.
|
* Implicit conversion to the managed instance pointer.
|
||||||
*/
|
*/
|
||||||
operator ConstPtr () const
|
operator ConstPtr () const //NOLINT (intentionally implicit)
|
||||||
{
|
{
|
||||||
return m_Ptr;
|
return m_Ptr;
|
||||||
}
|
}
|
||||||
@ -210,7 +211,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Implicit conversion to the managed instance reference.
|
* Implicit conversion to the managed instance reference.
|
||||||
*/
|
*/
|
||||||
operator Reference ()
|
operator Reference () //NOLINT (intentionally implicit)
|
||||||
{
|
{
|
||||||
assert(m_Ptr);
|
assert(m_Ptr);
|
||||||
return *m_Ptr;
|
return *m_Ptr;
|
||||||
@ -219,7 +220,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Implicit conversion to the managed instance reference.
|
* Implicit conversion to the managed instance reference.
|
||||||
*/
|
*/
|
||||||
operator ConstRef () const
|
operator ConstRef () const //NOLINT (intentionally implicit)
|
||||||
{
|
{
|
||||||
assert(m_Ptr);
|
assert(m_Ptr);
|
||||||
return *m_Ptr;
|
return *m_Ptr;
|
||||||
@ -278,51 +279,37 @@ protected:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Validate the document reference and throw an error if invalid.
|
* Validate the document reference and throw an error if invalid.
|
||||||
*/
|
*/
|
||||||
void Validate() const;
|
void Validate() const
|
||||||
|
{
|
||||||
|
// Is the documen handle valid?
|
||||||
|
if (!m_Doc)
|
||||||
|
{
|
||||||
|
STHROWF("Invalid XML document reference");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
DocumentRef m_Doc; /* The main xml document instance. */
|
DocumentRef m_Doc{}; /* The main xml document instance. */
|
||||||
Result m_Result; /* The managed parse result. */
|
Result m_Result{}; /* The managed parse result. */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
XmlParseResult()
|
XmlParseResult() = default;
|
||||||
: m_Doc(), m_Result()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy constructor. (disabled)
|
* Copy constructor. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlParseResult(const XmlParseResult & o)
|
XmlParseResult(const XmlParseResult & o) = default;
|
||||||
: m_Doc(o.m_Doc), m_Result(o.m_Result)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~XmlParseResult()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy assignment operator. (disabled)
|
* Copy assignment operator. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlParseResult & operator = (const XmlParseResult & o)
|
XmlParseResult & operator = (const XmlParseResult & o) = default;
|
||||||
{
|
|
||||||
m_Doc = o.m_Doc;
|
|
||||||
m_Result = o.m_Result;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Used by the script engine to compare two instances of this type.
|
* Used by the script engine to compare two instances of this type.
|
||||||
@ -351,11 +338,6 @@ public:
|
|||||||
return m_Result.description();
|
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.
|
* See whether this instance references a valid xml document.
|
||||||
*/
|
*/
|
||||||
@ -415,7 +397,13 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Check the parse result and throw the necessary errors.
|
* Check the parse result and throw the necessary errors.
|
||||||
*/
|
*/
|
||||||
void Check() const;
|
void Check() const
|
||||||
|
{
|
||||||
|
if (m_Result.status != status_ok)
|
||||||
|
{
|
||||||
|
STHROWF("XML parse error [%s]", m_Result.description());
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@ -428,20 +416,20 @@ protected:
|
|||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
typedef xml_document Type;
|
typedef xml_document Type;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy constructor. (disabled)
|
|
||||||
*/
|
|
||||||
XmlDocument(const XmlDocument & o);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Copy assignment operator. (disabled)
|
|
||||||
*/
|
|
||||||
XmlDocument & operator = (const XmlDocument & o);
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* See if the document is allowed to overwrite its contents and throw an error if not.
|
* See if the document is allowed to overwrite its contents and throw an error if not.
|
||||||
*/
|
*/
|
||||||
void CanLoad() const;
|
void CanLoad() const
|
||||||
|
{
|
||||||
|
// Is the document even valid?
|
||||||
|
m_Doc.Validate();
|
||||||
|
// Are there any other references?
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -456,16 +444,18 @@ public:
|
|||||||
XmlDocument()
|
XmlDocument()
|
||||||
: m_Doc(nullptr)
|
: m_Doc(nullptr)
|
||||||
{
|
{
|
||||||
/* ... */
|
/*...*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Destructor.
|
* Copy constructor. (disabled)
|
||||||
*/
|
*/
|
||||||
~XmlDocument()
|
XmlDocument(const XmlDocument & o) = delete;
|
||||||
{
|
|
||||||
/* ... */
|
/* --------------------------------------------------------------------------------------------
|
||||||
}
|
* Copy assignment operator. (disabled)
|
||||||
|
*/
|
||||||
|
XmlDocument & operator = (const XmlDocument & o) = delete;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Used by the script engine to compare two instances of this type.
|
* Used by the script engine to compare two instances of this type.
|
||||||
@ -484,7 +474,8 @@ public:
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (*m_Doc == *o.m_Doc)
|
|
||||||
|
if (*m_Doc == *o.m_Doc)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -512,11 +503,6 @@ public:
|
|||||||
return _SC("");
|
return _SC("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* 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.
|
* See whether this instance references a valid xml document.
|
||||||
*/
|
*/
|
||||||
@ -679,8 +665,8 @@ protected:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Explicit constructor.
|
* Explicit constructor.
|
||||||
*/
|
*/
|
||||||
XmlNode(const DocumentRef doc, const Type & node)
|
XmlNode(DocumentRef doc, const Type & node)
|
||||||
: m_Doc(doc), m_Node(node)
|
: m_Doc(std::move(doc)), m_Node(node)
|
||||||
{
|
{
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
@ -688,46 +674,25 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
DocumentRef m_Doc; // The main xml document instance.
|
DocumentRef m_Doc{}; // The main xml document instance.
|
||||||
Type m_Node; // The managed document node.
|
Type m_Node{}; // The managed document node.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
XmlNode()
|
XmlNode() = default;
|
||||||
: m_Doc(), m_Node()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy constructor. (disabled)
|
* Copy constructor. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlNode(const XmlNode & o)
|
XmlNode(const XmlNode & o) = default;
|
||||||
: m_Doc(o.m_Doc), m_Node(o.m_Node)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~XmlNode()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy assignment operator. (disabled)
|
* Copy assignment operator. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlNode & operator = (const XmlNode & o)
|
XmlNode & operator = (const XmlNode & o) = default;
|
||||||
{
|
|
||||||
m_Doc = o.m_Doc;
|
|
||||||
m_Node = o.m_Node;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Used by the script engine to compare two instances of this type.
|
* Used by the script engine to compare two instances of this type.
|
||||||
@ -756,11 +721,6 @@ public:
|
|||||||
return m_Node.value();
|
return m_Node.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* 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.
|
* See whether this instance references a valid xml document.
|
||||||
*/
|
*/
|
||||||
@ -1278,8 +1238,8 @@ protected:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Explicit constructor.
|
* Explicit constructor.
|
||||||
*/
|
*/
|
||||||
XmlAttribute(const DocumentRef doc, const Type & attr)
|
XmlAttribute(DocumentRef doc, const Type & attr)
|
||||||
: m_Doc(doc), m_Attr(attr)
|
: m_Doc(std::move(doc)), m_Attr(attr)
|
||||||
{
|
{
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
@ -1287,46 +1247,25 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
DocumentRef m_Doc; // The main xml document instance.
|
DocumentRef m_Doc{}; // The main xml document instance.
|
||||||
Type m_Attr; // The managed node attribute.
|
Type m_Attr{}; // The managed node attribute.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
XmlAttribute()
|
XmlAttribute() = default;
|
||||||
: m_Doc(), m_Attr()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy constructor. (disabled)
|
* Copy constructor. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlAttribute(const XmlAttribute & o)
|
XmlAttribute(const XmlAttribute & o) = default;
|
||||||
: m_Doc(o.m_Doc), m_Attr(o.m_Attr)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~XmlAttribute()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy assignment operator. (disabled)
|
* Copy assignment operator. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlAttribute & operator = (const XmlAttribute & o)
|
XmlAttribute & operator = (const XmlAttribute & o) = default;
|
||||||
{
|
|
||||||
m_Doc = o.m_Doc;
|
|
||||||
m_Attr = o.m_Attr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Used by the script engine to compare two instances of this type.
|
* Used by the script engine to compare two instances of this type.
|
||||||
@ -1355,11 +1294,6 @@ public:
|
|||||||
return m_Attr.value();
|
return m_Attr.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* 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.
|
* See whether this instance references a valid xml document.
|
||||||
*/
|
*/
|
||||||
@ -1711,8 +1645,8 @@ protected:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Explicit constructor.
|
* Explicit constructor.
|
||||||
*/
|
*/
|
||||||
XmlText(const DocumentRef doc, const Type & text)
|
XmlText(DocumentRef doc, const Type & text)
|
||||||
: m_Doc(doc), m_Text(text)
|
: m_Doc(std::move(doc)), m_Text(text)
|
||||||
{
|
{
|
||||||
/* ... */
|
/* ... */
|
||||||
}
|
}
|
||||||
@ -1720,51 +1654,44 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
DocumentRef m_Doc; // The main xml document instance.
|
DocumentRef m_Doc{}; // The main xml document instance.
|
||||||
Type m_Text; // The managed document node.
|
Type m_Text{}; // The managed document node.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
XmlText()
|
XmlText() = default;
|
||||||
: m_Doc(), m_Text()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy constructor. (disabled)
|
* Copy constructor. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlText(const XmlText & o)
|
XmlText(const XmlText & o) = default;
|
||||||
: m_Doc(o.m_Doc), m_Text(o.m_Text)
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
~XmlText()
|
|
||||||
{
|
|
||||||
/* ... */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Copy assignment operator. (disabled)
|
* Copy assignment operator. (disabled)
|
||||||
*/
|
*/
|
||||||
XmlText & operator = (const XmlText & o)
|
XmlText & operator = (const XmlText & o) = default;
|
||||||
{
|
|
||||||
m_Doc = o.m_Doc;
|
|
||||||
m_Text = o.m_Text;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Used by the script engine to compare two instances of this type.
|
* Used by the script engine to compare two instances of this type.
|
||||||
*/
|
*/
|
||||||
Int32 Cmp(const XmlText & o);
|
Int32 Cmp(const XmlText & 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Used by the script engine to convert an instance of this type to a string.
|
* Used by the script engine to convert an instance of this type to a string.
|
||||||
*/
|
*/
|
||||||
@ -1773,11 +1700,6 @@ public:
|
|||||||
return m_Text.get();
|
return m_Text.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
|
||||||
* 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.
|
* See whether this instance references a valid xml document.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user