summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-01-04 14:40:25 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-01-04 15:52:05 +0000
commit4235f42672569c390609bc5154fac7f1e3f08c96 (patch)
tree8ded18312a83000968d4b7bac3214d89aa9fdf8b
parentSupport custom filtering of children (by hook) in GetChild (diff)
downloadslicer-0.9.tar.bz2
slicer-0.9.tar.xz
slicer-0.9.zip
Switch to using metadata rather than the @ hack for using XML attributesslicer-0.9
-rw-r--r--slicer/test/initial/xmlattr.xml7
-rw-r--r--slicer/test/serializers.cpp7
-rw-r--r--slicer/test/types.ice1
-rw-r--r--slicer/xml/Jamfile.jam1
-rw-r--r--slicer/xml/serializer.cpp24
-rw-r--r--slicer/xml/serializer.h10
6 files changed, 35 insertions, 15 deletions
diff --git a/slicer/test/initial/xmlattr.xml b/slicer/test/initial/xmlattr.xml
new file mode 100644
index 0000000..475f0f3
--- /dev/null
+++ b/slicer/test/initial/xmlattr.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ClassClass simp="3">
+ <str>
+ <a>0</a>
+ <b>3</b>
+ </str>
+</ClassClass>
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 0319473..045146c 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -36,7 +36,7 @@ class FileBased : public FileStructure {
BOOST_TEST_CHECKPOINT("Deserialize: " << input);
IceInternal::Handle<T> p = Slicer::Deserialize<DeserializerIn, T>(input);
-
+
if (check) {
BOOST_TEST_CHECKPOINT("Check1: " << input);
check(*p);
@@ -293,5 +293,10 @@ BOOST_AUTO_TEST_CASE( optionals_areset_xml )
verifyByHelper<TestModule::Optionals, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, xmlpp::Document *>("optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset);
}
+BOOST_AUTO_TEST_CASE( xml_attribute_xml )
+{
+ verifyByFile<TestModule::ClassClass, Slicer::XmlFileDeserializer>("xmlattr.xml");
+}
+
BOOST_AUTO_TEST_SUITE_END();
diff --git a/slicer/test/types.ice b/slicer/test/types.ice
index 761e5e1..62037a1 100644
--- a/slicer/test/types.ice
+++ b/slicer/test/types.ice
@@ -46,6 +46,7 @@ module TestModule {
class ClassClass {
ClassType cls;
StructType str;
+ ["slicer:xml:attribute"]
int simp;
};
struct StructStruct {
diff --git a/slicer/xml/Jamfile.jam b/slicer/xml/Jamfile.jam
index 6c5322b..e959b64 100644
--- a/slicer/xml/Jamfile.jam
+++ b/slicer/xml/Jamfile.jam
@@ -13,6 +13,7 @@ lib slicer-xml :
<library>boost_filesystem
<library>IceUtil
<library>libxmlpp
+ <library>../slicer//slicer
: :
<library>libxmlpp
;
diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp
index ad3e87b..85fe99e 100644
--- a/slicer/xml/serializer.cpp
+++ b/slicer/xml/serializer.cpp
@@ -1,12 +1,16 @@
#include "serializer.h"
+#include <slicer/metadata.h>
#include <libxml++/document.h>
#include <libxml++/parsers/domparser.h>
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
+#include <boost/intrusive_ptr.hpp>
#include <stdexcept>
#include <glibmm/ustring.h>
namespace Slicer {
+ const std::string md_attribute = "xml:attribute";
+
class BadBooleanValue : public std::invalid_argument {
public:
BadBooleanValue(const Glib::ustring &) :
@@ -151,7 +155,7 @@ namespace Slicer {
{
}
};
-
+
class XmlContentValueTarget : public XmlValueTarget {
public:
XmlContentValueTarget(xmlpp::Element * p) :
@@ -159,13 +163,14 @@ namespace Slicer {
{
}
};
-
+
void
XmlDeserializer::DocumentTreeIterate(const xmlpp::Node * node, ModelPartPtr mp)
{
while (node) {
if (auto element = dynamic_cast<const xmlpp::Element *>(node)) {
- auto smp = mp->GetChild(element->get_name());
+ auto smp = mp->GetChild(element->get_name(),
+ boost::bind(metaDataFlagNotSet, boost::bind(&Slicer::HookCommon::GetMetadata, _1), md_attribute));
if (smp) {
if (auto typeIdPropName = smp->GetTypeIdProperty()) {
if (auto typeAttr = element->get_attribute(*typeIdPropName)) {
@@ -182,7 +187,8 @@ namespace Slicer {
}
}
else if (auto attribute = dynamic_cast<const xmlpp::Attribute *>(node)) {
- auto smp = mp->GetChild("@" + attribute->get_name());
+ auto smp = mp->GetChild(attribute->get_name(),
+ boost::bind(metaDataFlagSet, boost::bind(&Slicer::HookCommon::GetMetadata, _1), md_attribute));
if (smp) {
smp->Create();
smp->SetValue(new XmlAttributeValueSource(attribute));
@@ -203,13 +209,13 @@ namespace Slicer {
}
void
- XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, ModelPartPtr mp)
+ XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, ModelPartPtr mp, HookCommonPtr hp)
{
if (name.empty()) {
return;
}
- if (name[0] == '@') {
- mp->GetValue(new XmlAttributeValueTarget(n, name.substr(1)));
+ if (hp && metaDataFlagSet(hp->GetMetadata(), md_attribute)) {
+ mp->GetValue(new XmlAttributeValueTarget(n, name));
}
else if (mp) {
auto element = n->add_child(name);
@@ -220,7 +226,7 @@ namespace Slicer {
mp = mp->GetSubclassModelPart(*typeId);
}
mp->GetValue(new XmlContentValueTarget(element));
- mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, element, _1, _2));
+ mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, element, _1, _2, _3));
}
}
@@ -228,7 +234,7 @@ namespace Slicer {
XmlSerializer::ModelTreeIterateRoot(xmlpp::Document * doc, const std::string & name, ModelPartPtr mp)
{
auto root = doc->create_root_node(name);
- mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, root, _1, _2));
+ mp->OnEachChild(boost::bind(&XmlSerializer::ModelTreeIterate, root, _1, _2, _3));
}
XmlFileSerializer::XmlFileSerializer(const boost::filesystem::path & p) :
diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h
index fc5794d..4e37eed 100644
--- a/slicer/xml/serializer.h
+++ b/slicer/xml/serializer.h
@@ -7,10 +7,10 @@
namespace Slicer {
class XmlSerializer : public Serializer {
protected:
- static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartPtr mp);
+ static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartPtr mp, HookCommonPtr hp);
static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, ModelPartPtr mp);
};
-
+
class XmlFileSerializer : public XmlSerializer {
public:
XmlFileSerializer(const boost::filesystem::path &);
@@ -20,7 +20,7 @@ namespace Slicer {
private:
const boost::filesystem::path path;
};
-
+
class XmlDocumentSerializer : public XmlSerializer {
public:
XmlDocumentSerializer(xmlpp::Document * &);
@@ -36,7 +36,7 @@ namespace Slicer {
static void DocumentTreeIterate(const xmlpp::Node * node, ModelPartPtr mp);
static void DocumentTreeIterate(const xmlpp::Document * doc, ModelPartPtr mp);
};
-
+
class XmlFileDeserializer : public XmlDeserializer {
public:
XmlFileDeserializer(const boost::filesystem::path &);
@@ -46,7 +46,7 @@ namespace Slicer {
private:
const boost::filesystem::path path;
};
-
+
class XmlDocumentDeserializer : public XmlDeserializer {
public:
XmlDocumentDeserializer(const xmlpp::Document *);