diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp | 118 |
1 files changed, 62 insertions, 56 deletions
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(); } -} + |