diff options
author | Remko Tronçon <git@el-tramo.be> | 2014-01-30 13:08:25 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2014-02-02 09:42:58 (GMT) |
commit | 3d881ddd0b65d3a2bc1213386fb75fd95e4de691 (patch) | |
tree | ccf21c7f537f43e72f3daec9080bd8850acad357 /Swiften/Serializer/PayloadSerializers | |
parent | 9d9b6c625cd872bc907f0d1f6a516ff7c4e1b61f (diff) | |
download | swift-3d881ddd0b65d3a2bc1213386fb75fd95e4de691.zip swift-3d881ddd0b65d3a2bc1213386fb75fd95e4de691.tar.bz2 |
Update user tune & geoloc serializer
Change-Id: I0657f752e78e050798b42876ae256eff64c8e325
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
5 files changed, 125 insertions, 89 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 16c79d5..cd9b4d7 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -117,8 +117,8 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new ReplaceSerializer()); serializers_.push_back(new LastSerializer()); serializers_.push_back(new WhiteboardSerializer()); - serializers_.push_back(new UserLocationSerializer()); - serializers_.push_back(new UserTuneSerializer()); + serializers_.push_back(new UserLocationSerializer(this)); + serializers_.push_back(new UserTuneSerializer(this)); serializers_.push_back(new IdleSerializer()); serializers_.push_back(new StreamInitiationFileInfoSerializer()); diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp index e257654..3c8dde1 100644 --- a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp @@ -4,91 +4,97 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h> +#pragma clang diagnostic ignored "-Wunused-private-field" -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> +#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Base/DateTime.h> #include <boost/lexical_cast.hpp> +#include <boost/smart_ptr/make_shared.hpp> -#include <Swiften/Base/foreach.h> -#include <Swiften/Base/DateTime.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> #include <Swiften/Serializer/XML/XMLElement.h> -namespace Swift { +using namespace Swift; + +UserLocationSerializer::UserLocationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { +} -UserLocationSerializer::UserLocationSerializer() { +UserLocationSerializer::~UserLocationSerializer() { } -std::string UserLocationSerializer::serializePayload( - boost::shared_ptr<UserLocation> payload) const { - XMLElement result("geoloc", "http://jabber.org/protocol/geoloc"); - if (boost::optional<std::string> value = payload->getArea()) { - result.addNode(boost::make_shared<XMLElement>("area", "", *value)); +std::string UserLocationSerializer::serializePayload(boost::shared_ptr<UserLocation> payload) const { + if (!payload) { + return ""; } - if (boost::optional<float> value = payload->getAltitude()) { - result.addNode(boost::make_shared<XMLElement>("alt", "", boost::lexical_cast<std::string>(*value))); + XMLElement element("geoloc", "http://jabber.org/protocol/geoloc"); + if (payload->getArea()) { + element.addNode(boost::make_shared<XMLElement>("area", "", *payload->getArea())); } - if (boost::optional<std::string> value = payload->getLocality()) { - result.addNode(boost::make_shared<XMLElement>("locality", "", *value)); + if (payload->getAltitude()) { + element.addNode(boost::make_shared<XMLElement>("alt", "", boost::lexical_cast<std::string>(*payload->getAltitude()))); } - if (boost::optional<float> value = payload->getLatitude()) { - result.addNode(boost::make_shared<XMLElement>("lat", "", boost::lexical_cast<std::string>(*value))); + if (payload->getLocality()) { + element.addNode(boost::make_shared<XMLElement>("locality", "", *payload->getLocality())); } - if (boost::optional<float> value = payload->getAccuracy()) { - result.addNode(boost::make_shared<XMLElement>("accuracy", "", boost::lexical_cast<std::string>(*value))); + if (payload->getLatitude()) { + element.addNode(boost::make_shared<XMLElement>("lat", "", boost::lexical_cast<std::string>(*payload->getLatitude()))); } - if (boost::optional<std::string> value = payload->getDescription()) { - result.addNode(boost::make_shared<XMLElement>("description", "", *value)); + if (payload->getAccuracy()) { + element.addNode(boost::make_shared<XMLElement>("accuracy", "", boost::lexical_cast<std::string>(*payload->getAccuracy()))); } - if (boost::optional<std::string> value = payload->getCountryCode()) { - result.addNode(boost::make_shared<XMLElement>("countrycode", "", *value)); + if (payload->getDescription()) { + element.addNode(boost::make_shared<XMLElement>("description", "", *payload->getDescription())); } - if (boost::optional<boost::posix_time::ptime> value = payload->getTimestamp()) { - result.addNode(boost::make_shared<XMLElement>("timestamp", "", dateTimeToString(*value))); + if (payload->getCountryCode()) { + element.addNode(boost::make_shared<XMLElement>("countrycode", "", *payload->getCountryCode())); } - if (boost::optional<std::string> value = payload->getFloor()) { - result.addNode(boost::make_shared<XMLElement>("floor", "", *value)); + if (payload->getTimestamp()) { + element.addNode(boost::make_shared<XMLElement>("timestamp", "", dateTimeToString(*payload->getTimestamp()))); } - if (boost::optional<std::string> value = payload->getBuilding()) { - result.addNode(boost::make_shared<XMLElement>("building", "", *value)); + if (payload->getFloor()) { + element.addNode(boost::make_shared<XMLElement>("floor", "", *payload->getFloor())); } - if (boost::optional<std::string> value = payload->getRoom()) { - result.addNode(boost::make_shared<XMLElement>("room", "", *value)); + if (payload->getBuilding()) { + element.addNode(boost::make_shared<XMLElement>("building", "", *payload->getBuilding())); } - if (boost::optional<std::string> value = payload->getCountry()) { - result.addNode(boost::make_shared<XMLElement>("country", "", *value)); + if (payload->getRoom()) { + element.addNode(boost::make_shared<XMLElement>("room", "", *payload->getRoom())); } - if (boost::optional<std::string> value = payload->getRegion()) { - result.addNode(boost::make_shared<XMLElement>("region", "", *value)); + if (payload->getCountry()) { + element.addNode(boost::make_shared<XMLElement>("country", "", *payload->getCountry())); } - if (boost::optional<std::string> value = payload->getURI()) { - result.addNode(boost::make_shared<XMLElement>("uri", "", *value)); + if (payload->getRegion()) { + element.addNode(boost::make_shared<XMLElement>("region", "", *payload->getRegion())); } - if (boost::optional<float> value = payload->getLongitude()) { - result.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*value))); + if (payload->getURI()) { + element.addNode(boost::make_shared<XMLElement>("uri", "", *payload->getURI())); } - if (boost::optional<float> value = payload->getError()) { - result.addNode(boost::make_shared<XMLElement>("error", "", boost::lexical_cast<std::string>(*value))); + if (payload->getLongitude()) { + element.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*payload->getLongitude()))); } - if (boost::optional<std::string> value = payload->getPostalCode()) { - result.addNode(boost::make_shared<XMLElement>("postalcode", "", *value)); + if (payload->getError()) { + element.addNode(boost::make_shared<XMLElement>("error", "", boost::lexical_cast<std::string>(*payload->getError()))); } - if (boost::optional<float> value = payload->getBearing()) { - result.addNode(boost::make_shared<XMLElement>("bearing", "", boost::lexical_cast<std::string>(*value))); + if (payload->getPostalCode()) { + element.addNode(boost::make_shared<XMLElement>("postalcode", "", *payload->getPostalCode())); } - if (boost::optional<std::string> value = payload->getText()) { - result.addNode(boost::make_shared<XMLElement>("text", "", *value)); + if (payload->getBearing()) { + element.addNode(boost::make_shared<XMLElement>("bearing", "", boost::lexical_cast<std::string>(*payload->getBearing()))); } - if (boost::optional<std::string> value = payload->getDatum()) { - result.addNode(boost::make_shared<XMLElement>("datum", "", *value)); + if (payload->getText()) { + element.addNode(boost::make_shared<XMLElement>("text", "", *payload->getText())); } - if (boost::optional<std::string> value = payload->getStreet()) { - result.addNode(boost::make_shared<XMLElement>("street", "", *value)); + if (payload->getDatum()) { + element.addNode(boost::make_shared<XMLElement>("datum", "", *payload->getDatum())); } - if (boost::optional<float> value = payload->getSpeed()) { - result.addNode(boost::make_shared<XMLElement>("speed", "", boost::lexical_cast<std::string>(*value))); + if (payload->getStreet()) { + element.addNode(boost::make_shared<XMLElement>("street", "", *payload->getStreet())); } - return result.serialize(); + if (payload->getSpeed()) { + element.addNode(boost::make_shared<XMLElement>("speed", "", boost::lexical_cast<std::string>(*payload->getSpeed()))); + } + return element.serialize(); } -} + diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h index 28a5fe8..d00187e 100644 --- a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h @@ -6,14 +6,26 @@ #pragma once +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Elements/UserLocation.h> +#include <boost/shared_ptr.hpp> namespace Swift { - class UserLocationSerializer : public GenericPayloadSerializer<UserLocation> { + class PayloadSerializerCollection; + + class SWIFTEN_API UserLocationSerializer : public GenericPayloadSerializer<UserLocation> { public: - UserLocationSerializer(); + UserLocationSerializer(PayloadSerializerCollection* serializers); + virtual ~UserLocationSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<UserLocation>) const SWIFTEN_OVERRIDE; + + private: + - virtual std::string serializePayload(boost::shared_ptr<UserLocation>) const; + private: + PayloadSerializerCollection* serializers; }; } diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp index 6c7799e..c27259c 100644 --- a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.cpp @@ -4,45 +4,51 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h> +#pragma clang diagnostic ignored "-Wunused-private-field" -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> +#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h> +#include <Swiften/Serializer/XML/XMLElement.h> #include <boost/lexical_cast.hpp> +#include <boost/smart_ptr/make_shared.hpp> -#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/PayloadSerializerCollection.h> #include <Swiften/Serializer/XML/XMLElement.h> -namespace Swift { +using namespace Swift; -UserTuneSerializer::UserTuneSerializer() { +UserTuneSerializer::UserTuneSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) { } -std::string UserTuneSerializer::serializePayload( - boost::shared_ptr<UserTune> payload) const { - XMLElement result("tune", "http://jabber.org/protocol/tune"); - if (boost::optional<std::string> value = payload->getArtist()) { - result.addNode(boost::make_shared<XMLElement>("artist", "", *value)); +UserTuneSerializer::~UserTuneSerializer() { +} + +std::string UserTuneSerializer::serializePayload(boost::shared_ptr<UserTune> payload) const { + if (!payload) { + return ""; + } + XMLElement element("tune", "http://jabber.org/protocol/tune"); + if (payload->getRating()) { + element.addNode(boost::make_shared<XMLElement>("rating", "", boost::lexical_cast<std::string>(*payload->getRating()))); } - if (boost::optional<unsigned int> value = payload->getLength()) { - result.addNode(boost::make_shared<XMLElement>("length", "", boost::lexical_cast<std::string>(*value))); + if (payload->getTitle()) { + element.addNode(boost::make_shared<XMLElement>("title", "", *payload->getTitle())); } - if (boost::optional<unsigned int> value = payload->getRating()) { - result.addNode(boost::make_shared<XMLElement>("rating", "", boost::lexical_cast<std::string>(*value))); + if (payload->getTrack()) { + element.addNode(boost::make_shared<XMLElement>("track", "", *payload->getTrack())); } - if (boost::optional<std::string> value = payload->getSource()) { - result.addNode(boost::make_shared<XMLElement>("source", "", *value)); + if (payload->getArtist()) { + element.addNode(boost::make_shared<XMLElement>("artist", "", *payload->getArtist())); } - if (boost::optional<std::string> value = payload->getTitle()) { - result.addNode(boost::make_shared<XMLElement>("title", "", *value)); + if (payload->getURI()) { + element.addNode(boost::make_shared<XMLElement>("uri", "", *payload->getURI())); } - if (boost::optional<std::string> value = payload->getTrack()) { - result.addNode(boost::make_shared<XMLElement>("track", "", *value)); + if (payload->getSource()) { + element.addNode(boost::make_shared<XMLElement>("source", "", *payload->getSource())); } - if (boost::optional<std::string> value = payload->getURI()) { - result.addNode(boost::make_shared<XMLElement>("uri", "", *value)); + if (payload->getLength()) { + element.addNode(boost::make_shared<XMLElement>("length", "", boost::lexical_cast<std::string>(*payload->getLength()))); } - return result.serialize(); + return element.serialize(); } -} + diff --git a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h index 8c20cbd..62be6f2 100644 --- a/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h @@ -6,14 +6,26 @@ #pragma once +#include <Swiften/Base/Override.h> +#include <Swiften/Base/API.h> #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Elements/UserTune.h> +#include <boost/shared_ptr.hpp> namespace Swift { - class UserTuneSerializer : public GenericPayloadSerializer<UserTune> { + class PayloadSerializerCollection; + + class SWIFTEN_API UserTuneSerializer : public GenericPayloadSerializer<UserTune> { public: - UserTuneSerializer(); + UserTuneSerializer(PayloadSerializerCollection* serializers); + virtual ~UserTuneSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<UserTune>) const SWIFTEN_OVERRIDE; + + private: + - virtual std::string serializePayload(boost::shared_ptr<UserTune>) const; + private: + PayloadSerializerCollection* serializers; }; } |