summaryrefslogtreecommitdiffstats
blob: e257654954e9570a11200b7cc7bda6e63c948f1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2013 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h>

#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>

#include <Swiften/Base/foreach.h>
#include <Swiften/Base/DateTime.h>
#include <Swiften/Serializer/XML/XMLElement.h>

namespace Swift {

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));
	}
	if (boost::optional<float> value = payload->getAltitude()) {
		result.addNode(boost::make_shared<XMLElement>("alt", "", boost::lexical_cast<std::string>(*value)));
	}
	if (boost::optional<std::string> value = payload->getLocality()) {
		result.addNode(boost::make_shared<XMLElement>("locality", "", *value));
	}
	if (boost::optional<float> value = payload->getLatitude()) {
		result.addNode(boost::make_shared<XMLElement>("lat", "", boost::lexical_cast<std::string>(*value)));
	}
	if (boost::optional<float> value = payload->getAccuracy()) {
		result.addNode(boost::make_shared<XMLElement>("accuracy", "", boost::lexical_cast<std::string>(*value)));
	}
	if (boost::optional<std::string> value = payload->getDescription()) {
		result.addNode(boost::make_shared<XMLElement>("description", "", *value));
	}
	if (boost::optional<std::string> value = payload->getCountryCode()) {
		result.addNode(boost::make_shared<XMLElement>("countrycode", "", *value));
	}
	if (boost::optional<boost::posix_time::ptime> value = payload->getTimestamp()) {
		result.addNode(boost::make_shared<XMLElement>("timestamp", "", dateTimeToString(*value)));
	}
	if (boost::optional<std::string> value = payload->getFloor()) {
		result.addNode(boost::make_shared<XMLElement>("floor", "", *value));
	}
	if (boost::optional<std::string> value = payload->getBuilding()) {
		result.addNode(boost::make_shared<XMLElement>("building", "", *value));
	}
	if (boost::optional<std::string> value = payload->getRoom()) {
		result.addNode(boost::make_shared<XMLElement>("room", "", *value));
	}
	if (boost::optional<std::string> value = payload->getCountry()) {
		result.addNode(boost::make_shared<XMLElement>("country", "", *value));
	}
	if (boost::optional<std::string> value = payload->getRegion()) {
		result.addNode(boost::make_shared<XMLElement>("region", "", *value));
	}
	if (boost::optional<std::string> value = payload->getURI()) {
		result.addNode(boost::make_shared<XMLElement>("uri", "", *value));
	}
	if (boost::optional<float> value = payload->getLongitude()) {
		result.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*value)));
	}
	if (boost::optional<float> value = payload->getError()) {
		result.addNode(boost::make_shared<XMLElement>("error", "", boost::lexical_cast<std::string>(*value)));
	}
	if (boost::optional<std::string> value = payload->getPostalCode()) {
		result.addNode(boost::make_shared<XMLElement>("postalcode", "", *value));
	}
	if (boost::optional<float> value = payload->getBearing()) {
		result.addNode(boost::make_shared<XMLElement>("bearing", "", boost::lexical_cast<std::string>(*value)));
	}
	if (boost::optional<std::string> value = payload->getText()) {
		result.addNode(boost::make_shared<XMLElement>("text", "", *value));
	}
	if (boost::optional<std::string> value = payload->getDatum()) {
		result.addNode(boost::make_shared<XMLElement>("datum", "", *value));
	}
	if (boost::optional<std::string> value = payload->getStreet()) {
		result.addNode(boost::make_shared<XMLElement>("street", "", *value));
	}
	if (boost::optional<float> value = payload->getSpeed()) {
		result.addNode(boost::make_shared<XMLElement>("speed", "", boost::lexical_cast<std::string>(*value)));
	}
	return result.serialize();
}

}