Browse Source

XMLElement: unsigned to signed (#3033)

Related: https://github.com/urho3d/Urho3D/issues/2940
1vanK 3 years ago
parent
commit
f2d6679ad1

+ 1 - 1
Source/Urho3D/AngelScript/Generated_Classes.cpp

@@ -3235,7 +3235,7 @@ static void XMLElement__XMLElement_constspXMLElementamp(XMLElement* _ptr, const
 // class XMLElement | File: ../Resource/XMLElement.h
 static void Register_XMLElement(asIScriptEngine* engine)
 {
-    // XMLElement::XMLElement(XMLFile* file, const XPathResultSet* resultSet, const pugi::xpath_node* xpathNode, unsigned xpathResultIndex)
+    // XMLElement::XMLElement(XMLFile* file, const XPathResultSet* resultSet, const pugi::xpath_node* xpathNode, i32 xpathResultIndex)
     // Error: type "const XPathResultSet*" can not automatically bind
     // XMLElement::XMLElement(XMLFile* file, pugi::xml_node_struct* node)
     // Error: type "pugi::xml_node_struct*" can not automatically bind

+ 11 - 11
Source/Urho3D/AngelScript/Generated_Members.h

@@ -6679,7 +6679,7 @@ template <class T> void RegisterMembers_XMLElement(asIScriptEngine* engine, cons
     // Error: type "const char*" can not automatically bind
     // bool XMLElement::SetAttribute(const char* value)
     // Error: type "const char*" can not automatically bind
-    // bool XMLElement::SetBuffer(const String& name, const void* data, unsigned size)
+    // bool XMLElement::SetBuffer(const String& name, const void* data, i32 size)
     // Error: type "const void*" can not automatically bind
     // bool XMLElement::SetBuffer(const String& name, const Vector<unsigned char>& value)
     // Error: type "const Vector<unsigned char>&" can not automatically bind
@@ -6759,9 +6759,9 @@ template <class T> void RegisterMembers_XMLElement(asIScriptEngine* engine, cons
     // XMLElement XMLElement::GetNext(const String& name = String::EMPTY) const
     engine->RegisterObjectMethod(className, "XMLElement GetNext(const String&in = String::EMPTY) const", AS_METHODPR(T, GetNext, (const String&) const, XMLElement), AS_CALL_THISCALL);
 
-    // unsigned XMLElement::GetNumAttributes() const
-    engine->RegisterObjectMethod(className, "uint GetNumAttributes() const", AS_METHODPR(T, GetNumAttributes, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_numAttributes() const", AS_METHODPR(T, GetNumAttributes, () const, unsigned), AS_CALL_THISCALL);
+    // i32 XMLElement::GetNumAttributes() const
+    engine->RegisterObjectMethod(className, "int GetNumAttributes() const", AS_METHODPR(T, GetNumAttributes, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_numAttributes() const", AS_METHODPR(T, GetNumAttributes, () const, i32), AS_CALL_THISCALL);
 
     // XMLElement XMLElement::GetOrCreateChild(const String& name)
     engine->RegisterObjectMethod(className, "XMLElement GetOrCreateChild(const String&in)", AS_METHODPR(T, GetOrCreateChild, (const String&), XMLElement), AS_CALL_THISCALL);
@@ -6819,8 +6819,8 @@ template <class T> void RegisterMembers_XMLElement(asIScriptEngine* engine, cons
     // Variant XMLElement::GetVectorVariant(const String& name) const
     engine->RegisterObjectMethod(className, "Variant GetVectorVariant(const String&in) const", AS_METHODPR(T, GetVectorVariant, (const String&) const, Variant), AS_CALL_THISCALL);
 
-    // unsigned XMLElement::GetXPathResultIndex() const
-    engine->RegisterObjectMethod(className, "uint GetXPathResultIndex() const", AS_METHODPR(T, GetXPathResultIndex, () const, unsigned), AS_CALL_THISCALL);
+    // i32 XMLElement::GetXPathResultIndex() const
+    engine->RegisterObjectMethod(className, "int GetXPathResultIndex() const", AS_METHODPR(T, GetXPathResultIndex, () const, i32), AS_CALL_THISCALL);
 
     // bool XMLElement::HasAttribute(const String& name) const
     engine->RegisterObjectMethod(className, "bool HasAttribute(const String&in) const", AS_METHODPR(T, HasAttribute, (const String&) const, bool), AS_CALL_THISCALL);
@@ -7038,12 +7038,12 @@ template <class T> void RegisterMembers_XPathResultSet(asIScriptEngine* engine,
     // XPathResultSet& XPathResultSet::operator =(const XPathResultSet& rhs)
     engine->RegisterObjectMethod(className, "XPathResultSet& opAssign(const XPathResultSet&in)", AS_METHODPR(T, operator=, (const XPathResultSet&), XPathResultSet&), AS_CALL_THISCALL);
 
-    // XMLElement XPathResultSet::operator [](unsigned index) const
-    engine->RegisterObjectMethod(className, "XMLElement opIndex(uint) const", AS_METHODPR(T, operator[], (unsigned) const, XMLElement), AS_CALL_THISCALL);
+    // XMLElement XPathResultSet::operator [](i32 index) const
+    engine->RegisterObjectMethod(className, "XMLElement opIndex(int) const", AS_METHODPR(T, operator[], (i32) const, XMLElement), AS_CALL_THISCALL);
 
-    // unsigned XPathResultSet::Size() const
-    engine->RegisterObjectMethod(className, "uint Size() const", AS_METHODPR(T, Size, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_size() const", AS_METHODPR(T, Size, () const, unsigned), AS_CALL_THISCALL);
+    // i32 XPathResultSet::Size() const
+    engine->RegisterObjectMethod(className, "int Size() const", AS_METHODPR(T, Size, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_size() const", AS_METHODPR(T, Size, () const, i32), AS_CALL_THISCALL);
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_XPathResultSet
         REGISTER_MEMBERS_MANUAL_PART_XPathResultSet();

+ 12 - 8
Source/Urho3D/Resource/XMLElement.cpp

@@ -36,13 +36,14 @@ XMLElement::XMLElement(XMLFile* file, pugi::xml_node_struct* node) :
 }
 
 XMLElement::XMLElement(XMLFile* file, const XPathResultSet* resultSet, const pugi::xpath_node* xpathNode,
-    unsigned xpathResultIndex) :
+    i32 xpathResultIndex) :
     file_(file),
     node_(nullptr),
     xpathResultSet_(resultSet),
     xpathNode_(resultSet ? xpathNode : (xpathNode ? new pugi::xpath_node(*xpathNode) : nullptr)),
     xpathResultIndex_(xpathResultIndex)
 {
+    assert(xpathResultIndex >= 0);
 }
 
 XMLElement::XMLElement(const XMLElement& rhs) :
@@ -312,8 +313,9 @@ bool XMLElement::SetBoundingBox(const BoundingBox& value)
     return SetVector3("max", value.max_);
 }
 
-bool XMLElement::SetBuffer(const String& name, const void* data, unsigned size)
+bool XMLElement::SetBuffer(const String& name, const void* data, i32 size)
 {
+    assert(size >= 0);
     String dataStr;
     BufferToString(dataStr, data, size);
     return SetAttribute(name, dataStr);
@@ -628,13 +630,13 @@ XMLElement XMLElement::GetParent() const
     return XMLElement(file_, node.parent().internal_object());
 }
 
-unsigned XMLElement::GetNumAttributes() const
+i32 XMLElement::GetNumAttributes() const
 {
     if (!file_ || (!node_ && !xpathNode_))
         return 0;
 
     const pugi::xml_node& node = xpathNode_ ? xpathNode_->node() : pugi::xml_node(node_);
-    unsigned ret = 0;
+    i32 ret = 0;
 
     pugi::xml_attribute attr = node.first_attribute();
     while (!attr.empty())
@@ -1016,8 +1018,10 @@ XPathResultSet& XPathResultSet::operator =(const XPathResultSet& rhs)
     return *this;
 }
 
-XMLElement XPathResultSet::operator [](unsigned index) const
+XMLElement XPathResultSet::operator [](i32 index) const
 {
+    assert(index >= 0);
+
     if (!resultSet_)
         URHO3D_LOGERRORF(
             "Could not return result at index: %u. Most probably this is caused by the XPathResultSet not being stored in a lhs variable.",
@@ -1031,9 +1035,9 @@ XMLElement XPathResultSet::FirstResult()
     return operator [](0);
 }
 
-unsigned XPathResultSet::Size() const
+i32 XPathResultSet::Size() const
 {
-    return resultSet_ ? (unsigned)resultSet_->size() : 0;
+    return resultSet_ ? (i32)resultSet_->size() : 0;
 }
 
 bool XPathResultSet::Empty() const
@@ -1171,7 +1175,7 @@ String XPathQuery::EvaluateToString(const XMLElement& element) const
     const pugi::xml_node& node = element.GetXPathNode() ? element.GetXPathNode()->node() : pugi::xml_node(element.GetNode());
     String result;
     // First call get the size
-    result.Reserve((unsigned)query_->evaluate_string(nullptr, 0, node));
+    result.Reserve((i32)query_->evaluate_string(nullptr, 0, node));
     // Second call get the actual string
     query_->evaluate_string(const_cast<pugi::char_t*>(result.CString()), result.Capacity(), node);
     return result;

+ 7 - 7
Source/Urho3D/Resource/XMLElement.h

@@ -37,7 +37,7 @@ public:
     /// Construct with document and node pointers.
     XMLElement(XMLFile* file, pugi::xml_node_struct* node);
     /// Construct from xpath query result set.
-    XMLElement(XMLFile* file, const XPathResultSet* resultSet, const pugi::xpath_node* xpathNode, unsigned xpathResultIndex);
+    XMLElement(XMLFile* file, const XPathResultSet* resultSet, const pugi::xpath_node* xpathNode, i32 xpathResultIndex);
     /// Copy-construct from another element.
     XMLElement(const XMLElement& rhs);
     /// Destruct.
@@ -99,7 +99,7 @@ public:
     /// Set a BoundingBox attribute.
     bool SetBoundingBox(const BoundingBox& value);
     /// Set a buffer attribute.
-    bool SetBuffer(const String& name, const void* data, unsigned size);
+    bool SetBuffer(const String& name, const void* data, i32 size);
     /// Set a buffer attribute.
     bool SetBuffer(const String& name, const Vector<unsigned char>& value);
     /// Set a color attribute.
@@ -185,7 +185,7 @@ public:
     XMLElement GetParent() const;
     /// Return number of attributes.
     /// @property
-    unsigned GetNumAttributes() const;
+    i32 GetNumAttributes() const;
     /// Return whether has an attribute.
     bool HasAttribute(const String& name) const;
     /// Return whether has an attribute.
@@ -285,7 +285,7 @@ public:
     const pugi::xpath_node* GetXPathNode() const { return xpathNode_; }
 
     /// Return current result index.
-    unsigned GetXPathResultIndex() const { return xpathResultIndex_; }
+    i32 GetXPathResultIndex() const { return xpathResultIndex_; }
 
     /// Return next XPath query result. Only valid when this instance of XMLElement is itself one of the query result in the result set.
     /// @property
@@ -304,7 +304,7 @@ private:
     /// Pugixml xpath_node.
     const pugi::xpath_node* xpathNode_;
     /// Current XPath query result index (used internally to advance to subsequent query result).
-    mutable unsigned xpathResultIndex_;
+    mutable i32 xpathResultIndex_;
 };
 
 /// XPath query result set.
@@ -323,14 +323,14 @@ public:
     XPathResultSet& operator =(const XPathResultSet& rhs);
     /// Return the n-th result in the set. Call XMLElement::GetNextResult() to get the subsequent result in the set.
     /// Note: The XPathResultSet return value must be stored in a lhs variable to ensure the underlying xpath_node_set* is still valid while performing XPathResultSet::FirstResult(), XPathResultSet::operator [], and XMLElement::NextResult().
-    XMLElement operator [](unsigned index) const;
+    XMLElement operator [](i32 index) const;
     /// Return the first result in the set. Call XMLElement::GetNextResult() to get the subsequent result in the set.
     /// Note: The XPathResultSet return value must be stored in a lhs variable to ensure the underlying xpath_node_set* is still valid while performing XPathResultSet::FirstResult(), XPathResultSet::operator [], and XMLElement::NextResult().
     /// @property
     XMLElement FirstResult();
     /// Return size of result set.
     /// @property
-    unsigned Size() const;
+    i32 Size() const;
     /// Return whether result set is empty.
     /// @property
     bool Empty() const;