Add more functions to Attr and Node

This commit is contained in:
Kirigaya Kazuto 2017-05-18 09:00:27 +08:00
parent d47a3ed09d
commit 547be65c3e
2 changed files with 134 additions and 6 deletions

View File

@ -9,6 +9,102 @@ namespace MiniEngine
namespace XML namespace XML
{ {
void Attribute::_set(XAttr* pattr)
{
_pattr=pattr;
}
XAttr* Attribute::_get() const
{
return _pattr;
}
void Attribute::_clear()
{
_pattr=nullptr;
}
void Attribute::_setdoc(Document* pDoc)
{
_pdoc=pDoc;
}
std::string Attribute::getName() const
{
return std::string(getNameRaw());
}
std::string Attribute::getValue() const
{
return std::string(getValueRaw());
}
char* Attribute::getNameRaw() const
{
return _pattr->name();
}
char* Attribute::getValueRaw() const
{
return _pattr->value();
}
Node::Node()
{
_pnode=nullptr;
_pdoc=nullptr;
}
Node::Node(XNode* expNode)
{
_pnode=expNode;
_pdoc=nullptr;
}
void Node::_set(XNode* node)
{
_pnode=node;
}
XNode* Node::_get() const
{
return _pnode;
}
void Node::_clear()
{
_pnode=nullptr;
}
void Node::_setdoc(Document* pDoc)
{
_pdoc=pDoc;
}
std::string Node::getName() const
{
return std::string(getNameRaw());
}
std::string Node::getValue() const
{
return std::string(getValueRaw());
}
char* Node::getNameRaw() const
{
return _pnode->name();
}
char* Node::getValueRaw() const
{
return _pnode->value();
}
void Node::push_front(const Node& node) void Node::push_front(const Node& node)
{ {
_pnode->prepend_node(node._pnode); _pnode->prepend_node(node._pnode);
@ -79,6 +175,11 @@ void Node::remove_all_attr()
_pnode->remove_all_attributes(); _pnode->remove_all_attributes();
} }
bool Node::operator==(const Node& node)
{
return _pnode==node._pnode && _pdoc==node._pdoc;
}
bool Node::hasPrevNode() const bool Node::hasPrevNode() const
{ {
return _pnode->previous_sibling()!=nullptr; return _pnode->previous_sibling()!=nullptr;
@ -109,6 +210,11 @@ Node Node::getParentNode() const
return Node(_pnode->parent()); return Node(_pnode->parent());
} }
bool Node::valid()
{
return _pnode!=nullptr && _pdoc!=nullptr;
}
Document::Document() Document::Document()
{ {
@ -180,6 +286,16 @@ Attribute Document::newAttr(const std::string& name,const std::string& value)
return attr; return attr;
} }
Node Document::cloneNode(const Node& node)
{
return Node(_doc.clone_node(node._get()));
}
void Document::clear()
{
return _doc.clear();
}
//protected //protected
char* Document::_allocate_string(const std::string& str) char* Document::_allocate_string(const std::string& str)
{ {

View File

@ -22,6 +22,12 @@ public:
XAttr* _get() const; XAttr* _get() const;
void _clear(); void _clear();
void _setdoc(Document*); void _setdoc(Document*);
std::string getName() const;
std::string getValue() const;
char* getNameRaw() const;
char* getValueRaw() const;
private: private:
XAttr* _pattr; XAttr* _pattr;
Document* _pdoc; Document* _pdoc;
@ -31,13 +37,19 @@ class Node
{ {
public: public:
void _set(XNode*); void _set(XNode*);
XNode* _get(); XNode* _get() const;
void _clear(); void _clear();
void _setdoc(Document*); void _setdoc(Document*);
Node(); Node();
Node(XNode*); Node(XNode*);
std::string getName() const;
std::string getValue() const;
char* getNameRaw() const;
char* getValueRaw() const;
void push_front(const Node&); void push_front(const Node&);
void push_back(const Node&); void push_back(const Node&);
void insert(const Node& where,const Node& val); void insert(const Node& where,const Node& val);
@ -56,10 +68,7 @@ public:
void remove_attr(const Attribute& todelete); void remove_attr(const Attribute& todelete);
void remove_all_attr(); void remove_all_attr();
bool operator == (const Node& node) bool operator == (const Node& node);
{
return _pnode==node._pnode && _pdoc==node._pdoc;
}
bool hasPrevNode() const; bool hasPrevNode() const;
bool hasNextNode() const; bool hasNextNode() const;
@ -68,7 +77,7 @@ public:
Node getNextNode() const; Node getNextNode() const;
Node getParentNode() const; Node getParentNode() const;
Node clone(); bool valid();
private: private:
XNode* _pnode; XNode* _pnode;
@ -85,6 +94,9 @@ public:
bool ready(); bool ready();
Node newNode(const std::string& name,const std::string& value); Node newNode(const std::string& name,const std::string& value);
Attribute newAttr(const std::string& name,const std::string& value); Attribute newAttr(const std::string& name,const std::string& value);
Node cloneNode(const Node&);
void clear();
protected: protected:
char* _allocate_string(const std::string& str); char* _allocate_string(const std::string& str);
char* _allocate_string(const char* pstr,int sz); char* _allocate_string(const char* pstr,int sz);