Add More Function of Attr and Node

This commit is contained in:
Kirigaya Kazuto 2017-05-20 16:00:19 +08:00
parent 547be65c3e
commit 54e057b590
2 changed files with 112 additions and 28 deletions

View File

@ -29,6 +29,18 @@ void Attribute::_setdoc(Document* pDoc)
_pdoc=pDoc;
}
Attribute::Attribute()
{
_pattr=nullptr;
_pdoc=nullptr;
}
Attribute::Attribute(XAttr* pAttr)
{
_pattr=pAttr;
_pdoc=nullptr;
}
std::string Attribute::getName() const
{
return std::string(getNameRaw());
@ -49,6 +61,27 @@ char* Attribute::getValueRaw() const
return _pattr->value();
}
bool Attribute::hasPrevAttr() const
{
return _pattr->previous_attribute()!=nullptr;
}
bool Attribute::hasNextAttr() const
{
return _pattr->next_attribute()!=nullptr;
}
Attribute Attribute::getPrevAttr() const
{
return Attribute(_pattr->previous_attribute());
}
Attribute Attribute::getNextAttr() const
{
return Attribute(_pattr->next_attribute());
}
Node::Node()
{
@ -105,74 +138,88 @@ char* Node::getValueRaw() const
}
void Node::push_front(const Node& node)
Node& Node::push_front(const Node& node)
{
_pnode->prepend_node(node._pnode);
return *this;
}
void Node::push_back(const Node& node)
Node& Node::push_back(const Node& node)
{
_pnode->append_node(node._pnode);
return *this;
}
void Node::insert(const Node& where, const Node& val)
Node& Node::insert(const Node& where, const Node& val)
{
_pnode->insert_node(where._pnode,val._pnode);
return *this;
}
void Node::remove_first_node()
Node& Node::remove_first_node()
{
_pnode->remove_first_node();
return *this;
}
void Node::remove_last_node()
Node& Node::remove_last_node()
{
_pnode->remove_last_node();
return *this;
}
void Node::remove_node(const Node& todelete)
Node& Node::remove_node(const Node& todelete)
{
_pnode->remove_node(todelete._pnode);
return *this;
}
void Node::remove_all_node()
Node& Node::remove_all_node()
{
_pnode->remove_all_nodes();
return *this;
}
void Node::push_front(const Attribute& attr)
Node& Node::push_front(const Attribute& attr)
{
_pnode->prepend_attribute(attr._get());
return *this;
}
void Node::push_back(const Attribute& attr)
Node& Node::push_back(const Attribute& attr)
{
_pnode->append_attribute(attr._get());
return *this;
}
void Node::insert(const Attribute& where, const Attribute& val)
Node& Node::insert(const Attribute& where, const Attribute& val)
{
_pnode->insert_attribute(where._get(),val._get());
return *this;
}
void Node::remove_first_attr()
Node& Node::remove_first_attr()
{
_pnode->remove_first_attribute();
return *this;
}
void Node::remove_last_attr()
Node& Node::remove_last_attr()
{
_pnode->remove_last_attribute();
return *this;
}
void Node::remove_attr(const Attribute& todelete)
Node& Node::remove_attr(const Attribute& todelete)
{
_pnode->remove_attribute(todelete._get());
return *this;
}
void Node::remove_all_attr()
Node& Node::remove_all_attr()
{
_pnode->remove_all_attributes();
return *this;
}
bool Node::operator==(const Node& node)
@ -205,6 +252,16 @@ Node Node::getNextNode() const
return Node(_pnode->next_sibling());
}
Node Node::getPrevNode(const std::string& name) const
{
return Node(_pnode->previous_sibling(name.c_str()));
}
Node Node::getNextNode(const std::string& name) const
{
return Node(_pnode->next_sibling(name.c_str()));
}
Node Node::getParentNode() const
{
return Node(_pnode->parent());
@ -216,6 +273,17 @@ bool Node::valid()
}
Node Node::getChild() const
{
return _pnode->first_node();
}
Node Node::getChild(const std::string& nodename) const
{
return _pnode->first_node(nodename.c_str());
}
Document::Document()
{
_is_ready=false;

View File

@ -23,11 +23,22 @@ public:
void _clear();
void _setdoc(Document*);
Attribute();
Attribute(XAttr*);
std::string getName() const;
std::string getValue() const;
char* getNameRaw() const;
char* getValueRaw() const;
bool hasPrevAttr() const;
bool hasNextAttr() const;
Attribute getPrevAttr() const;
Attribute getNextAttr() const;
Attribute getPrevAttr(const std::string& name) const;
Attribute getNextAttr(const std::string& name) const;
private:
XAttr* _pattr;
Document* _pdoc;
@ -50,23 +61,23 @@ public:
char* getNameRaw() const;
char* getValueRaw() const;
void push_front(const Node&);
void push_back(const Node&);
void insert(const Node& where,const Node& val);
Node& push_front(const Node&);
Node& push_back(const Node&);
Node& insert(const Node& where,const Node& val);
void remove_first_node();
void remove_last_node();
void remove_node(const Node& todelete);
void remove_all_node();
Node& remove_first_node();
Node& remove_last_node();
Node& remove_node(const Node& todelete);
Node& remove_all_node();
void push_front(const Attribute&);
void push_back(const Attribute&);
void insert(const Attribute& where,const Attribute& val);
Node& push_front(const Attribute&);
Node& push_back(const Attribute&);
Node& insert(const Attribute& where,const Attribute& val);
void remove_first_attr();
void remove_last_attr();
void remove_attr(const Attribute& todelete);
void remove_all_attr();
Node& remove_first_attr();
Node& remove_last_attr();
Node& remove_attr(const Attribute& todelete);
Node& remove_all_attr();
bool operator == (const Node& node);
@ -76,6 +87,11 @@ public:
Node getPrevNode() const;
Node getNextNode() const;
Node getParentNode() const;
Node getPrevNode(const std::string& name) const;
Node getNextNode(const std::string& name) const;
Node getChild() const;
Node getChild(const std::string& nodename) const;
bool valid();