valid, child and name methods
right now the bound classes for document and node do not have inheritance; some methods have to be repeated, hence.
This commit is contained in:
parent
0ac3e01d56
commit
d3f972a073
@ -2,5 +2,10 @@ assert(require 'pugilua')
|
|||||||
|
|
||||||
local doc=pugi.xml_document()
|
local doc=pugi.xml_document()
|
||||||
os.execute("cd")
|
os.execute("cd")
|
||||||
local res=doc:load_file [[..\..\tests\data\latintest_latin1.xml]]
|
local res=doc:load_file [[..\..\scripts\pugilua\pugilua.vcxproj]]
|
||||||
print(res.description)
|
print(res.description)
|
||||||
|
|
||||||
|
local node=doc:child('Project')
|
||||||
|
assert(node.valid)
|
||||||
|
print(node.valid)
|
||||||
|
print(node.name)
|
||||||
@ -22,13 +22,39 @@ namespace pugi {
|
|||||||
pugi::xml_parse_result res;
|
pugi::xml_parse_result res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class lxml_node {
|
||||||
|
public:
|
||||||
|
lxml_node(pugi::xml_node& n):node(n){}
|
||||||
|
lxml_node() { }
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool valid() const {
|
||||||
|
return (bool)node;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefCountedPtr<lxml_node> child(char const* name) {
|
||||||
|
return RefCountedPtr<lxml_node>(new lxml_node(node.child(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name() const {
|
||||||
|
return node.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
pugi::xml_node node;
|
||||||
|
};
|
||||||
|
|
||||||
class lxml_document {
|
class lxml_document {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RefCountedPtr<lxml_parse_result> load_file(char const* path) {
|
RefCountedPtr<lxml_parse_result> load_file(char const* path) {
|
||||||
return RefCountedPtr<lxml_parse_result>(new lxml_parse_result(doc.load_file(path)));
|
return RefCountedPtr<lxml_parse_result>(new lxml_parse_result(doc.load_file(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// redundant, but defined due to composition up to now
|
||||||
|
RefCountedPtr<lxml_node> child(char const* name) {
|
||||||
|
return RefCountedPtr<lxml_node>(new lxml_node(doc.child(name)));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
};
|
};
|
||||||
@ -46,9 +72,17 @@ void register_pugilua (lua_State* L) {
|
|||||||
.addProperty("description",&lxml_parse_result::description)
|
.addProperty("description",&lxml_parse_result::description)
|
||||||
.endClass()
|
.endClass()
|
||||||
|
|
||||||
|
.beginClass<lxml_node>("xml_node")
|
||||||
|
.addConstructor<void (*)()>()
|
||||||
|
.addProperty("valid",&lxml_node::valid)
|
||||||
|
.addProperty("name",&lxml_node::name)
|
||||||
|
.addFunction("child",&lxml_node::child)
|
||||||
|
.endClass()
|
||||||
|
|
||||||
.beginClass<lxml_document>("xml_document")
|
.beginClass<lxml_document>("xml_document")
|
||||||
.addConstructor<void (*)()>()
|
.addConstructor<void (*)()>()
|
||||||
.addFunction("load_file",&lxml_document::load_file)
|
.addFunction("load_file",&lxml_document::load_file)
|
||||||
|
.addFunction("child",&lxml_document::child)
|
||||||
.endClass()
|
.endClass()
|
||||||
|
|
||||||
.endNamespace()
|
.endNamespace()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user