diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-15 10:48:54 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-15 10:48:54 (GMT) |
commit | 1dc6b7f7a3d96df848edad85c0d07d99340e3a3e (patch) | |
tree | db68d9c342293b18ce982a1eccbebde307ad0773 /Swiften/Serializer | |
parent | 70de68383506430c297056cd3389595fc696df1e (diff) | |
download | swift-contrib-1dc6b7f7a3d96df848edad85c0d07d99340e3a3e.zip swift-contrib-1dc6b7f7a3d96df848edad85c0d07d99340e3a3e.tar.bz2 |
Moved serialization of elements to WhiteboardSerializer
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp | 27 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h | 14 |
2 files changed, 39 insertions, 2 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp index 578b0ab..def21b1 100644 --- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp @@ -5,13 +5,36 @@ */ #include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h> -#include <Swiften/Serializer/XML/XMLElement.h> + +#include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { + void WhiteboardElementSerializingVisitor::visit(const WhiteboardLineElement* line) { + element = boost::make_shared<XMLElement>("line"); + element->setAttribute("x1", intToStr(line->x1())); + element->setAttribute("y1", intToStr(line->y1())); + element->setAttribute("x2", intToStr(line->x2())); + element->setAttribute("y2", intToStr(line->y2())); + } + + std::string WhiteboardElementSerializingVisitor::intToStr(const int t) { + std::stringstream ss; + ss << t; + return ss.str(); + } + + XMLElement::ref WhiteboardElementSerializingVisitor::getResult() const { + return element; + } + std::string WhiteboardSerializer::serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const { XMLElement element("wb"); - element.addNode(XMLTextNode::ref(new XMLTextNode(payload->getData()))); + if (payload->getType() == WhiteboardPayload::Data) { + WhiteboardElementSerializingVisitor visitor; + payload->getElement()->accept(visitor); + element.addNode(visitor.getResult()); + } element.setAttribute("type", typeToString(payload->getType())); return element.serialize(); } diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h index 975d537..219ebcc 100644 --- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h @@ -7,9 +7,23 @@ #pragma once #include <Swiften/Elements/WhiteboardPayload.h> +#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h> #include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> namespace Swift { + class WhiteboardElementSerializingVisitor : public WhiteboardElementVisitor { + public: + void visit(const WhiteboardLineElement* line); + XMLElement::ref getResult() const; + + private: + std::string intToStr(const int t); + + XMLElement::ref element; + }; + class WhiteboardSerializer : public GenericPayloadSerializer<WhiteboardPayload> { public: std::string serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const; |