From 9d169706deec5b361452ca8c954b7de54e9d0964 Mon Sep 17 00:00:00 2001 From: d-led Date: Tue, 2 Oct 2012 20:20:53 +0200 Subject: [PATCH] started wrapping xml_xpath_node_set --- Lua/lib/test.lua | 7 ++++- Notepad++.lnk | Bin 1081 -> 0 bytes contrib/pugilua/pugilua_lib.cpp | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) delete mode 100644 Notepad++.lnk diff --git a/Lua/lib/test.lua b/Lua/lib/test.lua index 699b064..239bc4b 100644 --- a/Lua/lib/test.lua +++ b/Lua/lib/test.lua @@ -9,4 +9,9 @@ assert(res.valid) local node=doc:child('Project') assert(node.valid) print(node.valid) -print(node.name) \ No newline at end of file +print(node.name) +local query1=doc:select_nodes('Project/PropertyGroup') +local query2=node:select_nodes('PropertyGroup') +assert(query1) +assert(query2) +print(query1.type,pugi.xpath_node_set.type_sorted) \ No newline at end of file diff --git a/Notepad++.lnk b/Notepad++.lnk deleted file mode 100644 index 93733fbc7e6ce407ec44e386ad6bb279158fff15..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1081 zcma)4Ur1A76#uPEj2@aa!AfutgtokGZrWN@o6GfY>17(MyboU7#YUTsxnhJY5JC!y zK#M2>34)^M1T8}8C8DAiA$l6U1U+Qb+h)}7T(9oI!tTd8-|suW^PO|VdA}L;mJck5BAfq9&xLtz9ZfV zJG#1iJJnEuWd^O9W)D~25l(7~ypejATSs7hU92d_Tp8AsfQw7wCYVRsb}#t)v2!)9 z(i!grj$5&XllT(5@2|0k*2GqrDNg|!D7v*vU2|bgP5mCE4T2x7(6#xo?1FJesbS*wYCwtP38c-#3r22#NydbEIvNI zCt)Ruhd12Rm9L+Wv!04urbH?;P+@_bcWk;ev)D0N`n9mtRetvAU^(+@yjc6>QNzWW LFVhq2@e=C~XkpVM diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index 77f7454..42609cb 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -4,10 +4,30 @@ #include #include #include +#include namespace pugi { namespace lua { + class lxml_xpath_node_set { + public: + lxml_xpath_node_set(pugi::xpath_node_set& s):node_set(s) { } + lxml_xpath_node_set() { } + public: + + int _type() const { + return node_set.type(); + } + + public: + // enums + static int type_unsorted () { return pugi::xpath_node_set::type_unsorted; } + static int type_sorted () { return pugi::xpath_node_set::type_sorted; } + static int type_sorted_reverse () { return pugi::xpath_node_set::type_sorted_reverse; } + private: + pugi::xpath_node_set node_set; + }; + class lxml_parse_result { public: lxml_parse_result(pugi::xml_parse_result& r):res(r) { } @@ -26,6 +46,10 @@ namespace pugi { pugi::xml_parse_result res; }; + //int const lxml_xpath_node_set::type_unsorted=pugi::xpath_node_set::type_unsorted; + //int const lxml_xpath_node_set::type_sorted=pugi::xpath_node_set::type_sorted; + //int const lxml_xpath_node_set::type_sorted_reverse=pugi::xpath_node_set::type_sorted_reverse; + class lxml_node { public: lxml_node(pugi::xml_node& n):node(n){} @@ -44,6 +68,15 @@ namespace pugi { return node.name(); } + RefCountedPtr select_nodes(char const* query) { + try { + return RefCountedPtr(new lxml_xpath_node_set(node.select_nodes(query))); + } catch (pugi::xpath_exception const& e) { + std::cerr<<"Error: "<(new lxml_xpath_node_set()); + } + } + private: pugi::xml_node node; }; @@ -59,6 +92,15 @@ namespace pugi { return RefCountedPtr(new lxml_node(doc.child(name))); } + RefCountedPtr select_nodes(char const* query) { + try { + return RefCountedPtr(new lxml_xpath_node_set(doc.select_nodes(query))); + } catch (pugi::xpath_exception const& e) { + std::cerr<<"Error: "<(new lxml_xpath_node_set()); + } + } + bool valid() const { return (bool)doc; } @@ -75,6 +117,14 @@ void register_pugilua (lua_State* L) { luabridge::getGlobalNamespace(L) .beginNamespace("pugi") + .beginClass("xpath_node_set") + .addConstructor() + .addProperty("type",&lxml_xpath_node_set::_type) + .addStaticProperty("type_unsorted",&lxml_xpath_node_set::type_unsorted) + .addStaticProperty("type_sorted",&lxml_xpath_node_set::type_sorted) + .addStaticProperty("type_sorted_reverse",&lxml_xpath_node_set::type_sorted_reverse) + .endClass() + .beginClass("xml_parse_result") .addConstructor() .addProperty("description",&lxml_parse_result::description) @@ -86,6 +136,7 @@ void register_pugilua (lua_State* L) { .addProperty("valid",&lxml_node::valid) .addProperty("name",&lxml_node::name) .addFunction("child",&lxml_node::child) + .addFunction("select_nodes",&lxml_node::select_nodes) .endClass() .beginClass("xml_document") @@ -93,6 +144,7 @@ void register_pugilua (lua_State* L) { .addProperty("valid",&lxml_document::valid) .addFunction("load_file",&lxml_document::load_file) .addFunction("child",&lxml_document::child) + .addFunction("select_nodes",&lxml_document::select_nodes) .endClass() .endNamespace()