From 578ed3c98aecf2f30a4a2af140c7261b15f5742f Mon Sep 17 00:00:00 2001 From: d-led Date: Wed, 3 Oct 2012 18:20:26 +0200 Subject: [PATCH] attribute addition by name --- contrib/pugilua/pugilua_lib.cpp | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index 5c8d5f7..c058f4a 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -41,6 +41,11 @@ namespace pugi { return att.hash_value(); } + public: // non-lua interface + pugi::xml_attribute const& get() { + return att; + } + private: pugi::xml_attribute att; }; @@ -108,6 +113,16 @@ namespace pugi { RefCountedPtr next_sibling(char const* name) const; RefCountedPtr previous_sibling(char const* name) const; + std::string child_value(char const* name) const; + + bool set_name(char const* rhs); + bool set_value(char const* rhs); + + RefCountedPtr append_attribute(const char* name); + RefCountedPtr prepend_attribute(const char* name); + RefCountedPtr insert_attribute_after(const char* name, RefCountedPtr attr); + RefCountedPtr insert_attribute_before(const char* name, RefCountedPtr attr); + //todo: text() @@ -269,6 +284,34 @@ namespace pugi { return RefCountedPtr(new lxml_node(node.previous_sibling(name))); } + std::string lxml_node::child_value(char const* name) const { + return node.child_value(name); + } + + bool lxml_node::set_name(char const* rhs) { + return node.set_name(rhs); + } + + bool lxml_node::set_value(char const* rhs) { + return node.set_value(rhs); + } + + RefCountedPtr lxml_node::append_attribute(const char* name) { + return RefCountedPtr(new lxml_attribute(node.append_attribute(name))); + } + + RefCountedPtr lxml_node::prepend_attribute(const char* name) { + return RefCountedPtr(new lxml_attribute(node.prepend_attribute(name))); + } + + RefCountedPtr lxml_node::insert_attribute_after(const char* name, RefCountedPtr attr) { + return RefCountedPtr(new lxml_attribute(node.insert_attribute_after(name,attr->get()))); + } + + RefCountedPtr lxml_node::insert_attribute_before(const char* name, RefCountedPtr attr) { + return RefCountedPtr(new lxml_attribute(node.insert_attribute_before(name,attr->get()))); + } + /////////////////// RefCountedPtr lxml_document::load_file(char const* path) { return RefCountedPtr(new lxml_parse_result(doc.load_file(path))); @@ -370,6 +413,13 @@ void register_pugilua (lua_State* L) { .addFunction("previous",&lxml_node::previous) .addFunction("next_sibling",&lxml_node::next_sibling) .addFunction("previous_sibling",&lxml_node::previous_sibling) + .addFunction("child_value",&lxml_node::child_value) + .addFunction("set_name",&lxml_node::set_name) + .addFunction("set_value",&lxml_node::set_value) + .addFunction("append_attribute",&lxml_node::append_attribute) + .addFunction("prepend_attribute",&lxml_node::prepend_attribute) + .addFunction("insert_attribute_after",&lxml_node::insert_attribute_after) + .addFunction("insert_attribute_before",&lxml_node::insert_attribute_before) .endClass() .beginClass("xml_document")