diff options
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r-- | Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp | 53 | ||||
-rw-r--r-- | Sluift/ElementConvertors/CarbonsReceivedConvertor.h | 30 | ||||
-rw-r--r-- | Sluift/ElementConvertors/CarbonsSentConvertor.cpp | 52 | ||||
-rw-r--r-- | Sluift/ElementConvertors/CarbonsSentConvertor.h | 30 | ||||
-rw-r--r-- | Sluift/ElementConvertors/SConscript | 2 |
5 files changed, 167 insertions, 0 deletions
diff --git a/Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp b/Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp new file mode 100644 index 0000000..cfd55f3 --- /dev/null +++ b/Sluift/ElementConvertors/CarbonsReceivedConvertor.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Sluift/ElementConvertors/CarbonsReceivedConvertor.h> + +#include <memory> +#include <lua.hpp> + +#include <Swiften/Elements/Forwarded.h> + +#include <Sluift/LuaElementConvertors.h> + +using namespace Swift; + +CarbonsReceivedConvertor::CarbonsReceivedConvertor(LuaElementConvertors* convertors) : + GenericLuaElementConvertor<CarbonsReceived>("carbons_received"), + convertors(convertors) { +} + +CarbonsReceivedConvertor::~CarbonsReceivedConvertor() { +} + +std::shared_ptr<CarbonsReceived> CarbonsReceivedConvertor::doConvertFromLua(lua_State* L) { + std::shared_ptr<CarbonsReceived> result = std::make_shared<CarbonsReceived>(); + lua_getfield(L, -1, "payload"); + if (!lua_isnil(L, -1)) { + std::shared_ptr<Forwarded> payload = std::dynamic_pointer_cast<Forwarded>(convertors->convertFromLuaUntyped(L, -1, "payload")); + if (!!payload) { + result->setForwarded(payload); + } + } + lua_pop(L, 1); + return result; +} + +void CarbonsReceivedConvertor::doConvertToLua(lua_State* L, std::shared_ptr<CarbonsReceived> payload) { + lua_createtable(L, 0, 0); + if (convertors->convertToLuaUntyped(L, payload->getForwarded()) > 0) { + lua_setfield(L, -2, "payload"); + + } +} + +boost::optional<LuaElementConvertor::Documentation> CarbonsReceivedConvertor::getDocumentation() const { + return Documentation( + "CarbonsReceived", + "This table has the following fields:\n\n" + "- `payload`: @{Forwarded}\n" + ); +} diff --git a/Sluift/ElementConvertors/CarbonsReceivedConvertor.h b/Sluift/ElementConvertors/CarbonsReceivedConvertor.h new file mode 100644 index 0000000..f18f699 --- /dev/null +++ b/Sluift/ElementConvertors/CarbonsReceivedConvertor.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/CarbonsReceived.h> + +#include <Sluift/GenericLuaElementConvertor.h> + +namespace Swift { + class LuaElementConvertors; + + class CarbonsReceivedConvertor : public GenericLuaElementConvertor<CarbonsReceived> { + public: + CarbonsReceivedConvertor(LuaElementConvertors* convertors); + virtual ~CarbonsReceivedConvertor(); + + virtual std::shared_ptr<CarbonsReceived> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; + virtual void doConvertToLua(lua_State*, std::shared_ptr<CarbonsReceived>) SWIFTEN_OVERRIDE; + virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE; + + private: + LuaElementConvertors* convertors; + }; +} + diff --git a/Sluift/ElementConvertors/CarbonsSentConvertor.cpp b/Sluift/ElementConvertors/CarbonsSentConvertor.cpp new file mode 100644 index 0000000..45851d2 --- /dev/null +++ b/Sluift/ElementConvertors/CarbonsSentConvertor.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Sluift/ElementConvertors/CarbonsSentConvertor.h> + +#include <memory> +#include <lua.hpp> + +#include <Swiften/Elements/Forwarded.h> + +#include <Sluift/LuaElementConvertors.h> + +using namespace Swift; + +CarbonsSentConvertor::CarbonsSentConvertor(LuaElementConvertors* convertors) : + GenericLuaElementConvertor<CarbonsSent>("carbons_sent"), + convertors(convertors) { +} + +CarbonsSentConvertor::~CarbonsSentConvertor() { +} + +std::shared_ptr<CarbonsSent> CarbonsSentConvertor::doConvertFromLua(lua_State* L) { + std::shared_ptr<CarbonsSent> result = std::make_shared<CarbonsSent>(); + lua_getfield(L, -1, "payload"); + if (!lua_isnil(L, -1)) { + std::shared_ptr<Forwarded> payload = std::dynamic_pointer_cast<Forwarded>(convertors->convertFromLuaUntyped(L, -1, "payload")); + if (!!payload) { + result->setForwarded(payload); + } + } + lua_pop(L, 1); + return result; +} + +void CarbonsSentConvertor::doConvertToLua(lua_State* L, std::shared_ptr<CarbonsSent> payload) { + lua_createtable(L, 0, 0); + if (convertors->convertToLuaUntyped(L, payload->getForwarded()) > 0) { + lua_setfield(L, -2, "payload"); + } +} + +boost::optional<LuaElementConvertor::Documentation> CarbonsSentConvertor::getDocumentation() const { + return Documentation( + "CarbonsSent", + "This table has the following fields:\n\n" + "- `payload`: @{Forwarded}\n" + ); +} diff --git a/Sluift/ElementConvertors/CarbonsSentConvertor.h b/Sluift/ElementConvertors/CarbonsSentConvertor.h new file mode 100644 index 0000000..a36a6a8 --- /dev/null +++ b/Sluift/ElementConvertors/CarbonsSentConvertor.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/CarbonsSent.h> + +#include <Sluift/GenericLuaElementConvertor.h> + +namespace Swift { + class LuaElementConvertors; + + class CarbonsSentConvertor : public GenericLuaElementConvertor<CarbonsSent> { + public: + CarbonsSentConvertor(LuaElementConvertors* convertors); + virtual ~CarbonsSentConvertor(); + + virtual std::shared_ptr<CarbonsSent> doConvertFromLua(lua_State*) SWIFTEN_OVERRIDE; + virtual void doConvertToLua(lua_State*, std::shared_ptr<CarbonsSent>) SWIFTEN_OVERRIDE; + virtual boost::optional<Documentation> getDocumentation() const SWIFTEN_OVERRIDE; + + private: + LuaElementConvertors* convertors; + }; +} + diff --git a/Sluift/ElementConvertors/SConscript b/Sluift/ElementConvertors/SConscript index b67c65b..0bf8022 100644 --- a/Sluift/ElementConvertors/SConscript +++ b/Sluift/ElementConvertors/SConscript @@ -48,6 +48,8 @@ convertors = [ env.File("MAMResultConvertor.cpp"), env.File("MAMQueryConvertor.cpp"), env.File("MAMFinConvertor.cpp"), + env.File("CarbonsReceivedConvertor.cpp"), + env.File("CarbonsSentConvertor.cpp"), env.File("SubjectConvertor.cpp"), env.File("IsodeIQDelegationConvertor.cpp") ] |