summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-04-29 08:57:17 (GMT)
committerRichard Maudsley <richard.maudsley@isode.com>2014-04-30 12:35:31 (GMT)
commit481f33cdee8a907c98f1b87dd1b65418b096c4f6 (patch)
tree7a53d23cc300f2aeecd5e3ea73b86bc09f318bce /Sluift/ElementConvertors
parentc4b64106e7b9493c7b28cc653797457d5f7fbdda (diff)
downloadswift-481f33cdee8a907c98f1b87dd1b65418b096c4f6.zip
swift-481f33cdee8a907c98f1b87dd1b65418b096c4f6.tar.bz2
Update LuaElementConvertor interface to work with Element instead of Payload.
Change-Id: I4f8b69b1a13fff21c605011f45763e01f03259cf
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r--Sluift/ElementConvertors/DOMElementConvertor.cpp9
-rw-r--r--Sluift/ElementConvertors/DOMElementConvertor.h4
-rw-r--r--Sluift/ElementConvertors/DefaultElementConvertor.cpp6
-rw-r--r--Sluift/ElementConvertors/DefaultElementConvertor.h4
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemConvertor.cpp2
-rw-r--r--Sluift/ElementConvertors/PubSubItemConvertor.cpp2
-rw-r--r--Sluift/ElementConvertors/RawXMLElementConvertor.cpp8
-rw-r--r--Sluift/ElementConvertors/RawXMLElementConvertor.h4
8 files changed, 24 insertions, 15 deletions
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.cpp b/Sluift/ElementConvertors/DOMElementConvertor.cpp
index bb4256d..fb1f658 100644
--- a/Sluift/ElementConvertors/DOMElementConvertor.cpp
+++ b/Sluift/ElementConvertors/DOMElementConvertor.cpp
@@ -160,7 +160,7 @@ DOMElementConvertor::DOMElementConvertor() {
DOMElementConvertor::~DOMElementConvertor() {
}
-boost::shared_ptr<Payload> DOMElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
+boost::shared_ptr<Element> DOMElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
if (!lua_istable(L, index) || type != "dom") {
return boost::shared_ptr<Payload>();
}
@@ -168,8 +168,13 @@ boost::shared_ptr<Payload> DOMElementConvertor::convertFromLua(lua_State* L, int
}
boost::optional<std::string> DOMElementConvertor::convertToLua(
- lua_State* L, boost::shared_ptr<Payload> payload) {
+ lua_State* L, boost::shared_ptr<Element> element) {
// Serialize payload to XML
+ boost::shared_ptr<Payload> payload = boost::dynamic_pointer_cast<Payload>(element);
+ if (!payload) {
+ return boost::optional<std::string>();
+ }
+
PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
assert(serializer);
std::string serializedPayload = serializer->serialize(payload);
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.h b/Sluift/ElementConvertors/DOMElementConvertor.h
index 94d0669..fdd7304 100644
--- a/Sluift/ElementConvertors/DOMElementConvertor.h
+++ b/Sluift/ElementConvertors/DOMElementConvertor.h
@@ -18,8 +18,8 @@ namespace Swift {
DOMElementConvertor();
virtual ~DOMElementConvertor();
- virtual boost::shared_ptr<Payload> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
- virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+ virtual boost::shared_ptr<Element> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
+ virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Element>) SWIFTEN_OVERRIDE;
private:
PlatformXMLParserFactory parsers;
diff --git a/Sluift/ElementConvertors/DefaultElementConvertor.cpp b/Sluift/ElementConvertors/DefaultElementConvertor.cpp
index 62c799b..cc326df 100644
--- a/Sluift/ElementConvertors/DefaultElementConvertor.cpp
+++ b/Sluift/ElementConvertors/DefaultElementConvertor.cpp
@@ -18,12 +18,12 @@ DefaultElementConvertor::DefaultElementConvertor() {
DefaultElementConvertor::~DefaultElementConvertor() {
}
-boost::shared_ptr<Payload> DefaultElementConvertor::convertFromLua(lua_State*, int, const std::string& type) {
+boost::shared_ptr<Element> DefaultElementConvertor::convertFromLua(lua_State*, int, const std::string& type) {
std::cerr << "Warning: Unable to convert type '" << type << "'" << std::endl;
- return boost::shared_ptr<Payload>();
+ return boost::shared_ptr<Element>();
}
-boost::optional<std::string> DefaultElementConvertor::convertToLua(lua_State*, boost::shared_ptr<Payload>) {
+boost::optional<std::string> DefaultElementConvertor::convertToLua(lua_State*, boost::shared_ptr<Element>) {
// Should have been handled by the raw XML convertor
assert(false);
return NO_RESULT;
diff --git a/Sluift/ElementConvertors/DefaultElementConvertor.h b/Sluift/ElementConvertors/DefaultElementConvertor.h
index ad8fe75..5a2975b 100644
--- a/Sluift/ElementConvertors/DefaultElementConvertor.h
+++ b/Sluift/ElementConvertors/DefaultElementConvertor.h
@@ -16,7 +16,7 @@ namespace Swift {
DefaultElementConvertor();
virtual ~DefaultElementConvertor();
- virtual boost::shared_ptr<Payload> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
- virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+ virtual boost::shared_ptr<Element> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
+ virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Element>) SWIFTEN_OVERRIDE;
};
}
diff --git a/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp b/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
index 4b150c4..9905df3 100644
--- a/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
@@ -44,7 +44,7 @@ boost::shared_ptr<PubSubEventItem> PubSubEventItemConvertor::doConvertFromLua(lu
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
- if (boost::shared_ptr<Payload> payload = convertors->convertFromLua(L, -1)) {
+ if (boost::shared_ptr<Payload> payload = boost::dynamic_pointer_cast<Payload>(convertors->convertFromLua(L, -1))) {
items.push_back(payload);
}
}
diff --git a/Sluift/ElementConvertors/PubSubItemConvertor.cpp b/Sluift/ElementConvertors/PubSubItemConvertor.cpp
index e9ed753..dcaa600 100644
--- a/Sluift/ElementConvertors/PubSubItemConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubItemConvertor.cpp
@@ -34,7 +34,7 @@ boost::shared_ptr<PubSubItem> PubSubItemConvertor::doConvertFromLua(lua_State* L
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
- if (boost::shared_ptr<Payload> payload = convertors->convertFromLua(L, -1)) {
+ if (boost::shared_ptr<Payload> payload = boost::dynamic_pointer_cast<Payload>(convertors->convertFromLua(L, -1))) {
items.push_back(payload);
}
}
diff --git a/Sluift/ElementConvertors/RawXMLElementConvertor.cpp b/Sluift/ElementConvertors/RawXMLElementConvertor.cpp
index 35a53ca..e4cfe05 100644
--- a/Sluift/ElementConvertors/RawXMLElementConvertor.cpp
+++ b/Sluift/ElementConvertors/RawXMLElementConvertor.cpp
@@ -22,14 +22,18 @@ RawXMLElementConvertor::RawXMLElementConvertor() {
RawXMLElementConvertor::~RawXMLElementConvertor() {
}
-boost::shared_ptr<Payload> RawXMLElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
+boost::shared_ptr<Element> RawXMLElementConvertor::convertFromLua(lua_State* L, int index, const std::string& type) {
if (type == "xml") {
return boost::make_shared<RawXMLPayload>(std::string(Lua::checkString(L, index)));
}
return boost::shared_ptr<Payload>();
}
-boost::optional<std::string> RawXMLElementConvertor::convertToLua(lua_State* L, boost::shared_ptr<Payload> payload) {
+boost::optional<std::string> RawXMLElementConvertor::convertToLua(lua_State* L, boost::shared_ptr<Element> element) {
+ boost::shared_ptr<Payload> payload = boost::dynamic_pointer_cast<Payload>(element);
+ if (!payload) {
+ return boost::optional<std::string>();
+ }
PayloadSerializer* serializer = serializers.getPayloadSerializer(payload);
assert(serializer);
lua_pushstring(L, serializer->serialize(payload).c_str());
diff --git a/Sluift/ElementConvertors/RawXMLElementConvertor.h b/Sluift/ElementConvertors/RawXMLElementConvertor.h
index 6087ba0..2ee76c5 100644
--- a/Sluift/ElementConvertors/RawXMLElementConvertor.h
+++ b/Sluift/ElementConvertors/RawXMLElementConvertor.h
@@ -17,8 +17,8 @@ namespace Swift {
RawXMLElementConvertor();
virtual ~RawXMLElementConvertor();
- virtual boost::shared_ptr<Payload> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
- virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Payload>) SWIFTEN_OVERRIDE;
+ virtual boost::shared_ptr<Element> convertFromLua(lua_State*, int index, const std::string& type) SWIFTEN_OVERRIDE;
+ virtual boost::optional<std::string> convertToLua(lua_State*, boost::shared_ptr<Element>) SWIFTEN_OVERRIDE;
private:
FullPayloadSerializerCollection serializers;