From cc52d7998903743e729856da4b067c2bdb6404a6 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 3 Sep 2014 19:11:03 +0000 Subject: Fix serializer interface to operate only on model part, everything else is via implementor's constructor --- slicer/json/serializer.cpp | 9 +++++++-- slicer/json/serializer.h | 9 +++++++-- slicer/slicer/serializer.h | 4 ++-- slicer/slicer/slicer.h | 8 ++++---- slicer/xml/serializer.cpp | 9 +++++++-- slicer/xml/serializer.h | 9 +++++++-- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index e9cd58c..dcce094 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -156,6 +156,11 @@ namespace Slicer { ModelPartPtr modelPart; }; + Json::Json(const boost::filesystem::path & p) : + path(p) + { + } + void Json::ModelTreeIterateSeq(json::Value * n, ModelPartPtr mp) { @@ -228,7 +233,7 @@ namespace Slicer { } void - Json::Deserialize(const boost::filesystem::path & path, ModelPartPtr modelRoot) + Json::Deserialize(ModelPartPtr modelRoot) { std::ifstream inFile(path.string()); std::stringstream buffer; @@ -240,7 +245,7 @@ namespace Slicer { } void - Json::Serialize(const boost::filesystem::path & path, ModelPartPtr modelRoot) + Json::Serialize(ModelPartPtr modelRoot) { json::Value doc; modelRoot->OnEachChild(boost::bind(&Json::ModelTreeIterateRoot, &doc, _2)); diff --git a/slicer/json/serializer.h b/slicer/json/serializer.h index 0d70f21..c6bfb52 100644 --- a/slicer/json/serializer.h +++ b/slicer/json/serializer.h @@ -10,13 +10,18 @@ namespace json { namespace Slicer { class Json : public Serializer { public: - virtual void Deserialize(const boost::filesystem::path &, ModelPartPtr) override; - virtual void Serialize(const boost::filesystem::path &, ModelPartPtr) override; + Json(const boost::filesystem::path &); + + virtual void Deserialize(ModelPartPtr) override; + virtual void Serialize(ModelPartPtr) override; protected: static void ModelTreeIterate(json::Value *, const std::string &, ModelPartPtr mp); static void ModelTreeIterateSeq(json::Value *, ModelPartPtr mp); static void ModelTreeIterateRoot(json::Value *, ModelPartPtr mp); + + private: + const boost::filesystem::path path; }; } diff --git a/slicer/slicer/serializer.h b/slicer/slicer/serializer.h index dffa0f6..d89f9aa 100644 --- a/slicer/slicer/serializer.h +++ b/slicer/slicer/serializer.h @@ -9,8 +9,8 @@ namespace Slicer { class Serializer : public IceUtil::Shared { public: - virtual void Deserialize(const boost::filesystem::path &, ModelPartPtr) = 0; - virtual void Serialize(const boost::filesystem::path &, ModelPartPtr) = 0; + virtual void Deserialize(ModelPartPtr) = 0; + virtual void Serialize(ModelPartPtr) = 0; }; typedef IceUtil::Handle SerializerPtr; } diff --git a/slicer/slicer/slicer.h b/slicer/slicer/slicer.h index 0900bf9..01b040d 100644 --- a/slicer/slicer/slicer.h +++ b/slicer/slicer/slicer.h @@ -12,8 +12,8 @@ namespace Slicer { Deserialize(const boost::filesystem::path & path) { IceUtil::Handle>> root = new ModelPartForClassRoot>(); - SerializerPtr serializer = new Serializer(); - serializer->Deserialize(path, root); + SerializerPtr serializer = new Serializer(path); + serializer->Deserialize(root); return root->GetModel(); } @@ -22,8 +22,8 @@ namespace Slicer { Serialize(IceInternal::Handle object, const boost::filesystem::path & path) { IceUtil::Handle>> root = new ModelPartForClassRoot>(object); - SerializerPtr serializer = new Serializer(); - serializer->Serialize(path, root); + SerializerPtr serializer = new Serializer(path); + serializer->Serialize(root); } } diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index bc593da..15d954e 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -160,6 +160,11 @@ namespace Slicer { } }; + Xml::Xml(const boost::filesystem::path & p) : + path(p) + { + } + void Xml::DocumentTreeIterate(const xmlpp::Node * node, ModelPartPtr mp) { @@ -230,7 +235,7 @@ namespace Slicer { } void - Xml::Deserialize(const boost::filesystem::path & path, ModelPartPtr modelRoot) + Xml::Deserialize(ModelPartPtr modelRoot) { xmlpp::DomParser dom(path.string()); auto doc = dom.get_document(); @@ -238,7 +243,7 @@ namespace Slicer { } void - Xml::Serialize(const boost::filesystem::path & path, ModelPartPtr modelRoot) + Xml::Serialize(ModelPartPtr modelRoot) { xmlpp::Document doc; modelRoot->OnEachChild(boost::bind(&Xml::ModelTreeIterateRoot, &doc, _1, _2)); diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index 8e8a023..487070b 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -14,14 +14,19 @@ namespace xmlpp { namespace Slicer { class Xml : public Serializer { public: - virtual void Deserialize(const boost::filesystem::path &, ModelPartPtr) override; - virtual void Serialize(const boost::filesystem::path &, ModelPartPtr) override; + Xml(const boost::filesystem::path &); + + virtual void Deserialize(ModelPartPtr) override; + virtual void Serialize(ModelPartPtr) override; protected: static void DocumentTreeIterate(const xmlpp::Node * node, ModelPartPtr mp); static void DocumentTreeIterate(const xmlpp::Document * doc, ModelPartPtr mp); static void ModelTreeIterate(xmlpp::Element *, const std::string &, ModelPartPtr mp); static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, ModelPartPtr mp); + + private: + const boost::filesystem::path path; }; } -- cgit v1.2.3