summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/ElementConvertors')
-rw-r--r--Sluift/ElementConvertors/CommandConvertor.cpp6
-rw-r--r--Sluift/ElementConvertors/DOMElementConvertor.cpp3
-rw-r--r--Sluift/ElementConvertors/FormConvertor.cpp14
-rw-r--r--Sluift/ElementConvertors/ForwardedConvertor.cpp1
-rw-r--r--Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp6
-rw-r--r--Sluift/ElementConvertors/PubSubItemConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubItemsConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubPublishConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubRetractConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/SecurityLabelConvertor.cpp4
-rw-r--r--Sluift/ElementConvertors/StanzaConvertor.h3
16 files changed, 22 insertions, 51 deletions
diff --git a/Sluift/ElementConvertors/CommandConvertor.cpp b/Sluift/ElementConvertors/CommandConvertor.cpp
index 1e2f8e3..de7a439 100644
--- a/Sluift/ElementConvertors/CommandConvertor.cpp
+++ b/Sluift/ElementConvertors/CommandConvertor.cpp
@@ -1,46 +1,44 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/CommandConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/Lua/Check.h>
#include <Sluift/Lua/Value.h>
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
static Command::Action convertActionFromString(const std::string& action) {
if (action == "cancel") { return Command::Cancel; }
else if (action == "execute") { return Command::Execute; }
else if (action == "complete") { return Command::Complete; }
else if (action == "prev") { return Command::Prev; }
else if (action == "next") { return Command::Next; }
return Command::NoAction;
}
static std::string convertActionToString(Command::Action action) {
switch (action) {
case Command::Cancel: return "cancel";
case Command::Execute: return "execute";
case Command::Complete: return "complete";
case Command::Prev: return "prev";
case Command::Next: return "next";
case Command::NoAction: assert(false); return "";
}
assert(false);
return "";
}
CommandConvertor::CommandConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<Command>("command"),
@@ -127,71 +125,71 @@ std::shared_ptr<Command> CommandConvertor::doConvertFromLua(lua_State* L) {
lua_pop(L, 1);
lua_getfield(L, -1, "form");
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<Form> form = std::dynamic_pointer_cast<Form>(convertors->convertFromLuaUntyped(L, -1, "form"))) {
result->setForm(form);
}
}
lua_pop(L, 1);
return result;
}
void CommandConvertor::doConvertToLua(lua_State* L, std::shared_ptr<Command> payload) {
Lua::Table result;
if (!payload->getNode().empty()) {
result["node"] = Lua::valueRef(payload->getNode());
}
if (!payload->getSessionID().empty()) {
result["session_id"] = Lua::valueRef(payload->getSessionID());
}
switch (payload->getStatus()) {
case Command::Executing: result["status"] = Lua::valueRef("executing"); break;
case Command::Completed: result["status"] = Lua::valueRef("completed"); break;
case Command::Canceled: result["status"] = Lua::valueRef("canceled"); break;
case Command::NoStatus: break;
}
if (!payload->getNotes().empty()) {
std::vector<Lua::Value> notes;
- foreach (const Command::Note& note, payload->getNotes()) {
+ for (const auto& note : payload->getNotes()) {
Lua::Table noteTable;
if (!note.note.empty()) {
noteTable["note"] = Lua::valueRef(note.note);
}
switch (note.type) {
case Command::Note::Info: noteTable["type"] = Lua::valueRef("info"); break;
case Command::Note::Warn: noteTable["type"] = Lua::valueRef("warn"); break;
case Command::Note::Error: noteTable["type"] = Lua::valueRef("error"); break;
}
notes.push_back(noteTable);
}
result["notes"] = Lua::valueRef(notes);
}
if (payload->getAction() != Command::NoAction) {
result["action"] = Lua::valueRef(convertActionToString(payload->getAction()));
}
if (payload->getExecuteAction() != Command::NoAction) {
result["execute_action"] = Lua::valueRef(convertActionToString(payload->getAction()));
}
if (!payload->getAvailableActions().empty()) {
std::vector<Lua::Value> availableActions;
- foreach (const Command::Action& action, payload->getAvailableActions()) {
+ for (const auto& action : payload->getAvailableActions()) {
if (action != Command::NoAction) {
availableActions.push_back(convertActionToString(action));
}
}
result["available_actions"] = Lua::valueRef(availableActions);
}
Lua::pushValue(L, result);
if (payload->getForm()) {
bool result = convertors->convertToLuaUntyped(L, payload->getForm());
assert(result);
lua_setfield(L, -2, "form");
}
}
diff --git a/Sluift/ElementConvertors/DOMElementConvertor.cpp b/Sluift/ElementConvertors/DOMElementConvertor.cpp
index c03eb8c..b957686 100644
--- a/Sluift/ElementConvertors/DOMElementConvertor.cpp
+++ b/Sluift/ElementConvertors/DOMElementConvertor.cpp
@@ -1,81 +1,80 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/DOMElementConvertor.h>
#include <memory>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/RawXMLPayload.h>
#include <Swiften/Parser/Attribute.h>
#include <Swiften/Parser/AttributeMap.h>
#include <Swiften/Parser/XMLParser.h>
#include <Swiften/Parser/XMLParserClient.h>
#include <Swiften/Serializer/PayloadSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
#include <Swiften/Serializer/XML/XMLTextNode.h>
#include <Sluift/Lua/Check.h>
#include <Sluift/Lua/Debug.h>
#include <Sluift/Lua/LuaUtils.h>
using namespace Swift;
namespace {
class ParserClient : public XMLParserClient {
public:
ParserClient(lua_State* L) : L(L), currentIndex(1) {
}
virtual void handleStartElement(
const std::string& element, const std::string& ns,
const AttributeMap& attributes) SWIFTEN_OVERRIDE {
lua_checkstack(L, 6);
lua_pushnumber(L, currentIndex);
lua_newtable(L);
lua_pushstring(L, element.c_str());
lua_setfield(L, -2, "tag");
if (!ns.empty()) {
lua_pushstring(L, ns.c_str());
lua_setfield(L, -2, "ns");
}
if (!attributes.getEntries().empty()) {
lua_newtable(L);
int i = 1;
- foreach(const AttributeMap::Entry& entry, attributes.getEntries()) {
+ for (const auto& entry : attributes.getEntries()) {
lua_pushnumber(L, i);
lua_newtable(L);
lua_pushstring(L, entry.getAttribute().getName().c_str());
lua_setfield(L, -2, "name");
if (!entry.getAttribute().getNamespace().empty()) {
lua_pushstring(L, entry.getAttribute().getNamespace().c_str());
lua_setfield(L, -2, "ns");
}
lua_pushstring(L, entry.getValue().c_str());
lua_setfield(L, -2, "value");
lua_settable(L, -3);
++i;
}
lua_setfield(L, -2, "attributes");
}
indexStack.push_back(currentIndex);
currentIndex = 1;
lua_newtable(L);
}
virtual void handleEndElement(
const std::string&, const std::string&) SWIFTEN_OVERRIDE {
lua_setfield(L, -2, "children");
lua_settable(L, -3);
currentIndex = indexStack.back();
indexStack.pop_back();
currentIndex++;
}
diff --git a/Sluift/ElementConvertors/FormConvertor.cpp b/Sluift/ElementConvertors/FormConvertor.cpp
index 85f40a1..90fd9fe 100644
--- a/Sluift/ElementConvertors/FormConvertor.cpp
+++ b/Sluift/ElementConvertors/FormConvertor.cpp
@@ -1,48 +1,46 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/FormConvertor.h>
#include <memory>
#include <sstream>
#include <boost/assign/list_of.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/Lua/Check.h>
#include <Sluift/Lua/Value.h>
using namespace Swift;
namespace {
int formIndex(lua_State* L) {
lua_getfield(L, 1, "fields");
if (lua_type(L, -1) != LUA_TTABLE) {
return 0;
}
int index = Lua::absoluteOffset(L, -1);
lua_pushnil(L);
for (lua_pushnil(L); lua_next(L, index) != 0; ) {
lua_getfield(L, -1, "name");
if (lua_equal(L, -1, 2)) {
lua_pop(L, 1);
return 1;
}
lua_pop(L, 2);
}
return 0;
}
int formNewIndex(lua_State* L) {
lua_getfield(L, 1, "fields");
bool foundField = false;
if (lua_type(L, -1) == LUA_TTABLE) {
for (lua_pushnil(L); lua_next(L, -2) != 0; ) {
lua_getfield(L, -1, "name");
@@ -78,74 +76,74 @@ namespace {
case FormField::TextMultiType: type = "text-multi"; break;
case FormField::TextPrivateType: type = "text-private"; break;
case FormField::TextSingleType: type = "text-single"; break;
case FormField::JIDSingleType: type = "jid-single"; break;
case FormField::JIDMultiType: type = "jid-multi"; break;
case FormField::ListMultiType: type = "list-multi"; break;
}
if (!type.empty()) {
luaField["type"] = Lua::valueRef(type);
}
if (!field->getLabel().empty()) {
luaField["label"] = Lua::valueRef(field->getLabel());
}
if (field->getRequired()) {
luaField["required"] = Lua::boolRef(field->getRequired());
}
if (!field->getDescription().empty()) {
luaField["description"] = Lua::valueRef(field->getDescription());
}
if (field->getType() == FormField::BooleanType) {
luaField["value"] = Lua::boolRef(field->getBoolValue());
}
else if (field->getValues().size() > 1) {
luaField["value"] = Lua::valueRef(Lua::Array(field->getValues().begin(), field->getValues().end()));
}
else if (field->getValues().size() == 1) {
luaField["value"] = Lua::valueRef(field->getValues()[0]);
}
if (!field->getOptions().empty()) {
Lua::Array options;
- foreach(const FormField::Option& option, field->getOptions()) {
+ for (const auto& option : field->getOptions()) {
Lua::Table luaOption = boost::assign::map_list_of
("label", Lua::valueRef(option.label))
("value", Lua::valueRef(option.value));
options.push_back(luaOption);
}
luaField["options"] = valueRef(options);
}
return luaField;
}
Lua::Array convertFieldListToLua(const std::vector< std::shared_ptr<FormField> >& fieldList) {
Lua::Array fields;
- foreach(std::shared_ptr<FormField> field, fieldList) {
+ for (auto&& field : fieldList) {
fields.push_back(convertFieldToLua(field));
}
return fields;
}
std::shared_ptr<FormField> convertFieldFromLua(lua_State* L) {
std::shared_ptr<FormField> result = std::make_shared<FormField>();
FormField::Type fieldType = FormField::UnknownType;
boost::optional<std::string> type = Lua::getStringField(L, -1, "type");
if (type) {
if (*type == "boolean") {
fieldType = FormField::BooleanType;
}
if (*type == "fixed") {
fieldType = FormField::FixedType;
}
if (*type == "hidden") {
fieldType = FormField::HiddenType;
}
if (*type == "list-single") {
fieldType = FormField::ListSingleType;
}
if (*type == "text-multi") {
fieldType = FormField::TextMultiType;
}
if (*type == "text-private") {
fieldType = FormField::TextPrivateType;
}
if (*type == "text-single") {
@@ -218,138 +216,138 @@ namespace {
result.push_back(convertFieldFromLua(L));
lua_pop(L, 1);
}
return result;
}
std::shared_ptr<Form> convertFormFromLua(lua_State* L) {
std::shared_ptr<Form> result = std::make_shared<Form>();
if (boost::optional<std::string> title = Lua::getStringField(L, -1, "title")) {
result->setTitle(*title);
}
if (boost::optional<std::string> instructions = Lua::getStringField(L, -1, "instructions")) {
result->setInstructions(*instructions);
}
if (boost::optional<std::string> type = Lua::getStringField(L, -1, "type")) {
Form::Type formType = Form::FormType;
if (*type == "submit") {
formType = Form::SubmitType;
}
else if (*type == "cancel") {
formType = Form::CancelType;
}
else if (*type == "result") {
formType = Form::ResultType;
}
result->setType(formType);
}
lua_getfield(L, -1, "fields");
if (lua_istable(L, -1)) {
- foreach (std::shared_ptr<FormField> formField, convertFieldListFromLua(L)) {
+ for (auto&& formField : convertFieldListFromLua(L)) {
result->addField(formField);
}
}
lua_pop(L, 1);
lua_getfield(L, -1, "reported_fields");
if (lua_istable(L, -1)) {
- foreach (std::shared_ptr<FormField> formField, convertFieldListFromLua(L)) {
+ for (auto&& formField : convertFieldListFromLua(L)) {
result->addReportedField(formField);
}
}
lua_pop(L, 1);
lua_getfield(L, -1, "items");
if (lua_istable(L, -1)) {
for (lua_pushnil(L); lua_next(L, -2);) {
result->addItem(convertFieldListFromLua(L));
lua_pop(L, 1);
}
}
lua_pop(L, 1);
return result;
}
void convertFormToLua(lua_State* L, std::shared_ptr<Form> payload) {
std::string type;
switch (payload->getType()) {
case Form::FormType: type = "form"; break;
case Form::SubmitType: type = "submit"; break;
case Form::CancelType: type = "cancel"; break;
case Form::ResultType: type = "result"; break;
}
Lua::Table result = boost::assign::map_list_of("type", Lua::valueRef(type));
if (!payload->getTitle().empty()) {
result["title"] = Lua::valueRef(payload->getTitle());
}
if (!payload->getInstructions().empty()) {
result["instructions"] = Lua::valueRef(payload->getInstructions());
}
result["fields"] = valueRef(convertFieldListToLua(payload->getFields()));
if (!payload->getReportedFields().empty()) {
result["reported_fields"] = valueRef(convertFieldListToLua(payload->getReportedFields()));
}
if (!payload->getItems().empty()) {
Lua::Array luaItems;
- foreach(const Form::FormItem& item, payload->getItems()) {
+ for (const auto& item : payload->getItems()) {
if (!item.empty()) {
luaItems.push_back(convertFieldListToLua(item));
}
}
result["items"] = valueRef(luaItems);
}
Lua::pushValue(L, result);
lua_newtable(L);
lua_pushcfunction(L, formIndex);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, formNewIndex);
lua_setfield(L, -2, "__newindex");
lua_setmetatable(L, -2);
}
int createSubmission(lua_State* L) {
std::shared_ptr<Form> form = convertFormFromLua(L);
// Remove all redundant elements
form->setInstructions("");
form->setTitle("");
form->clearItems();
form->clearReportedFields();
std::vector< std::shared_ptr<FormField> > fields(form->getFields());
form->clearFields();
- foreach (std::shared_ptr<FormField> field, fields) {
+ for (auto&& field : fields) {
if (field->getType() == FormField::FixedType) {
continue;
}
field->clearOptions();
field->setLabel("");
field->setType(FormField::UnknownType);
field->setDescription("");
form->addField(field);
}
form->setType(Form::SubmitType);
// Convert back
convertFormToLua(L, form);
Lua::registerTableToString(L, -1);
return 1;
}
}
FormConvertor::FormConvertor() : GenericLuaElementConvertor<Form>("form") {
}
FormConvertor::~FormConvertor() {
}
std::shared_ptr<Form> FormConvertor::doConvertFromLua(lua_State* L) {
return convertFormFromLua(L);
}
void FormConvertor::doConvertToLua(lua_State* L, std::shared_ptr<Form> payload) {
diff --git a/Sluift/ElementConvertors/ForwardedConvertor.cpp b/Sluift/ElementConvertors/ForwardedConvertor.cpp
index 8474252..b353eea 100644
--- a/Sluift/ElementConvertors/ForwardedConvertor.cpp
+++ b/Sluift/ElementConvertors/ForwardedConvertor.cpp
@@ -1,45 +1,44 @@
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/ForwardedConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/Delay.h>
#include <Swiften/Elements/IQ.h>
#include <Swiften/Elements/Message.h>
#include <Swiften/Elements/Presence.h>
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
ForwardedConvertor::ForwardedConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<Forwarded>("forwarded"),
convertors(convertors) {
}
ForwardedConvertor::~ForwardedConvertor() {
}
std::shared_ptr<Forwarded> ForwardedConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<Forwarded> result = std::make_shared<Forwarded>();
lua_getfield(L, -1, "delay");
if (!lua_isnil(L, -1)) {
std::shared_ptr<Delay> delay = std::dynamic_pointer_cast<Delay>(convertors->convertFromLuaUntyped(L, -1, "delay"));
if (!!delay) {
result->setDelay(delay);
}
}
lua_pop(L, 1);
lua_getfield(L, -1, "stanza");
if (!lua_isnil(L, -1)) {
std::shared_ptr<Stanza> stanza = std::dynamic_pointer_cast<Stanza>(convertors->convertFromLua(L, -1));
diff --git a/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp b/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp
index 8eae795..c6ba09e 100644
--- a/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubAffiliationsConvertor.cpp
@@ -1,80 +1,78 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubAffiliationsConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubAffiliationsConvertor::PubSubAffiliationsConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubAffiliations>("pubsub_affiliations"),
convertors(convertors) {
}
PubSubAffiliationsConvertor::~PubSubAffiliationsConvertor() {
}
std::shared_ptr<PubSubAffiliations> PubSubAffiliationsConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubAffiliations> result = std::make_shared<PubSubAffiliations>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubAffiliation> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubAffiliation> payload = std::dynamic_pointer_cast<PubSubAffiliation>(convertors->convertFromLuaUntyped(L, -1, "pubsub_affiliation"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setAffiliations(items);
}
return result;
}
void PubSubAffiliationsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubAffiliations> payload) {
lua_createtable(L, 0, 0);
if (payload->getNode()) {
lua_pushstring(L, (*payload->getNode()).c_str());
lua_setfield(L, -2, "node");
}
if (!payload->getAffiliations().empty()) {
{
int i = 0;
- foreach(std::shared_ptr<PubSubAffiliation> item, payload->getAffiliations()) {
+ for (auto&& item : payload->getAffiliations()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubAffiliationsConvertor::getDocumentation() const {
return Documentation(
"PubSubAffiliations",
"This table has the following fields:\n\n"
"- `node`: string (Optional)\n"
"- `affiliations`: array<@{PubSubAffiliation}>\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp b/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
index e8ba5b5..ac86024 100644
--- a/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubEventItemConvertor.cpp
@@ -1,46 +1,44 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubEventItemConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubEventItemConvertor::PubSubEventItemConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubEventItem>("pubsub_event_item"),
convertors(convertors) {
}
PubSubEventItemConvertor::~PubSubEventItemConvertor() {
}
std::shared_ptr<PubSubEventItem> PubSubEventItemConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubEventItem> result = std::make_shared<PubSubEventItem>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "publisher");
if (lua_isstring(L, -1)) {
result->setPublisher(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "data");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<Payload> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
@@ -50,55 +48,55 @@ std::shared_ptr<PubSubEventItem> PubSubEventItemConvertor::doConvertFromLua(lua_
}
}
lua_pop(L, 1);
}
result->setData(items);
}
lua_pop(L, 1);
lua_getfield(L, -1, "id");
if (lua_isstring(L, -1)) {
result->setID(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
return result;
}
void PubSubEventItemConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubEventItem> payload) {
lua_createtable(L, 0, 0);
if (payload->getNode()) {
lua_pushstring(L, (*payload->getNode()).c_str());
lua_setfield(L, -2, "node");
}
if (payload->getPublisher()) {
lua_pushstring(L, (*payload->getPublisher()).c_str());
lua_setfield(L, -2, "publisher");
}
if (!payload->getData().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getData().size()), 0);
{
int i = 0;
- foreach(std::shared_ptr<Payload> item, payload->getData()) {
+ for (auto&& item : payload->getData()) {
if (convertors->convertToLua(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "data");
}
if (payload->getID()) {
lua_pushstring(L, (*payload->getID()).c_str());
lua_setfield(L, -2, "id");
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubEventItemConvertor::getDocumentation() const {
return Documentation(
"PubSubEventItem",
"This table has the following fields:\n\n"
"- `node`: string (Optional)\n"
"- `publisher`: string (Optional)\n"
"- `data`: array<element (table)>\n"
"- `id`: string (Optional)\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp b/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp
index c89c4a6..7a3cde1 100644
--- a/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubEventItemsConvertor.cpp
@@ -1,46 +1,44 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubEventItemsConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubEventItemsConvertor::PubSubEventItemsConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubEventItems>("pubsub_event_items"),
convertors(convertors) {
}
PubSubEventItemsConvertor::~PubSubEventItemsConvertor() {
}
std::shared_ptr<PubSubEventItems> PubSubEventItemsConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubEventItems> result = std::make_shared<PubSubEventItems>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "items");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubEventItem> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubEventItem> payload = std::dynamic_pointer_cast<PubSubEventItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_item"))) {
items.push_back(payload);
}
}
@@ -51,63 +49,63 @@ std::shared_ptr<PubSubEventItems> PubSubEventItemsConvertor::doConvertFromLua(lu
}
lua_pop(L, 1);
lua_getfield(L, -1, "retracts");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubEventRetract> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubEventRetract> payload = std::dynamic_pointer_cast<PubSubEventRetract>(convertors->convertFromLuaUntyped(L, -1, "pubsub_event_retract"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setRetracts(items);
}
lua_pop(L, 1);
return result;
}
void PubSubEventItemsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubEventItems> payload) {
lua_createtable(L, 0, 0);
lua_pushstring(L, payload->getNode().c_str());
lua_setfield(L, -2, "node");
if (!payload->getItems().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getItems().size()), 0);
{
int i = 0;
- foreach(std::shared_ptr<PubSubEventItem> item, payload->getItems()) {
+ for (auto&& item : payload->getItems()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "items");
}
if (!payload->getRetracts().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getRetracts().size()), 0);
{
int i = 0;
- foreach(std::shared_ptr<PubSubEventRetract> item, payload->getRetracts()) {
+ for (auto&& item : payload->getRetracts()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "retracts");
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubEventItemsConvertor::getDocumentation() const {
return Documentation(
"PubSubEventItems",
"This table has the following fields:\n\n"
"- `node`: string\n"
"- `items`: array<@{PubSubEventItem}>\n"
"- `retracts`: array<@{PubSubEventRetract}>\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubItemConvertor.cpp b/Sluift/ElementConvertors/PubSubItemConvertor.cpp
index 99802bf..27fd4a3 100644
--- a/Sluift/ElementConvertors/PubSubItemConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubItemConvertor.cpp
@@ -1,82 +1,80 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubItemConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubItemConvertor::PubSubItemConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubItem>("pubsub_item"),
convertors(convertors) {
}
PubSubItemConvertor::~PubSubItemConvertor() {
}
std::shared_ptr<PubSubItem> PubSubItemConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubItem> result = std::make_shared<PubSubItem>();
lua_getfield(L, -1, "data");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<Payload> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<Payload> payload = std::dynamic_pointer_cast<Payload>(convertors->convertFromLua(L, -1))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setData(items);
}
lua_pop(L, 1);
lua_getfield(L, -1, "id");
if (lua_isstring(L, -1)) {
result->setID(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
return result;
}
void PubSubItemConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubItem> payload) {
lua_createtable(L, 0, 0);
if (!payload->getData().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getData().size()), 0);
{
int i = 0;
- foreach(std::shared_ptr<Payload> item, payload->getData()) {
+ for (auto&& item : payload->getData()) {
if (convertors->convertToLua(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "data");
}
lua_pushstring(L, payload->getID().c_str());
lua_setfield(L, -2, "id");
}
boost::optional<LuaElementConvertor::Documentation> PubSubItemConvertor::getDocumentation() const {
return Documentation(
"PubSubItem",
"This table has the following fields:\n\n"
"- `data`: array<element (table)>\n"
"- `id`: string\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubItemsConvertor.cpp b/Sluift/ElementConvertors/PubSubItemsConvertor.cpp
index 8e1f08d..5fa1bd3 100644
--- a/Sluift/ElementConvertors/PubSubItemsConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubItemsConvertor.cpp
@@ -1,98 +1,96 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubItemsConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubItemsConvertor::PubSubItemsConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubItems>("pubsub_items"),
convertors(convertors) {
}
PubSubItemsConvertor::~PubSubItemsConvertor() {
}
std::shared_ptr<PubSubItems> PubSubItemsConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubItems> result = std::make_shared<PubSubItems>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubItem> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubItem> payload = std::dynamic_pointer_cast<PubSubItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_item"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setItems(items);
}
lua_getfield(L, -1, "maximum_items");
if (lua_isnumber(L, -1)) {
result->setMaximumItems(boost::numeric_cast<unsigned int>(lua_tonumber(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "subscription_id");
if (lua_isstring(L, -1)) {
result->setSubscriptionID(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
return result;
}
void PubSubItemsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubItems> payload) {
lua_createtable(L, 0, 0);
lua_pushstring(L, payload->getNode().c_str());
lua_setfield(L, -2, "node");
if (!payload->getItems().empty()) {
{
int i = 0;
- foreach(std::shared_ptr<PubSubItem> item, payload->getItems()) {
+ for (auto&& item : payload->getItems()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
}
if (payload->getMaximumItems()) {
lua_pushnumber(L, (*payload->getMaximumItems()));
lua_setfield(L, -2, "maximum_items");
}
if (payload->getSubscriptionID()) {
lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
lua_setfield(L, -2, "subscription_id");
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubItemsConvertor::getDocumentation() const {
return Documentation(
"PubSubItems",
"This table has the following fields:\n\n"
"- `node`: string\n"
"- `items`: array<@{PubSubItem}>\n"
"- `maximum_items`: number (Optional)\n"
"- `subscription_id`: string (Optional)\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp
index b66443f..ee8a8cb 100644
--- a/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.cpp
@@ -1,78 +1,76 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubOwnerAffiliationsConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubOwnerAffiliationsConvertor::PubSubOwnerAffiliationsConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubOwnerAffiliations>("pubsub_owner_affiliations"),
convertors(convertors) {
}
PubSubOwnerAffiliationsConvertor::~PubSubOwnerAffiliationsConvertor() {
}
std::shared_ptr<PubSubOwnerAffiliations> PubSubOwnerAffiliationsConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubOwnerAffiliations> result = std::make_shared<PubSubOwnerAffiliations>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubOwnerAffiliation> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubOwnerAffiliation> payload = std::dynamic_pointer_cast<PubSubOwnerAffiliation>(convertors->convertFromLuaUntyped(L, -1, "pubsub_owner_affiliation"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setAffiliations(items);
}
return result;
}
void PubSubOwnerAffiliationsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubOwnerAffiliations> payload) {
lua_createtable(L, 0, 0);
lua_pushstring(L, payload->getNode().c_str());
lua_setfield(L, -2, "node");
if (!payload->getAffiliations().empty()) {
{
int i = 0;
- foreach(std::shared_ptr<PubSubOwnerAffiliation> item, payload->getAffiliations()) {
+ for (auto&& item : payload->getAffiliations()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubOwnerAffiliationsConvertor::getDocumentation() const {
return Documentation(
"PubSubOwnerAffiliations",
"This table has the following fields:\n\n"
"- `node`: string\n"
"- `affiliations`: array<@{PubSubOwnerAffiliation}>\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp b/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp
index 50cfb9b..88085b5 100644
--- a/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.cpp
@@ -1,78 +1,76 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubOwnerSubscriptionsConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubOwnerSubscriptionsConvertor::PubSubOwnerSubscriptionsConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubOwnerSubscriptions>("pubsub_owner_subscriptions"),
convertors(convertors) {
}
PubSubOwnerSubscriptionsConvertor::~PubSubOwnerSubscriptionsConvertor() {
}
std::shared_ptr<PubSubOwnerSubscriptions> PubSubOwnerSubscriptionsConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubOwnerSubscriptions> result = std::make_shared<PubSubOwnerSubscriptions>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubOwnerSubscription> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubOwnerSubscription> payload = std::dynamic_pointer_cast<PubSubOwnerSubscription>(convertors->convertFromLuaUntyped(L, -1, "pubsub_owner_subscription"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setSubscriptions(items);
}
return result;
}
void PubSubOwnerSubscriptionsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubOwnerSubscriptions> payload) {
lua_createtable(L, 0, 0);
lua_pushstring(L, payload->getNode().c_str());
lua_setfield(L, -2, "node");
if (!payload->getSubscriptions().empty()) {
{
int i = 0;
- foreach(std::shared_ptr<PubSubOwnerSubscription> item, payload->getSubscriptions()) {
+ for (auto&& item : payload->getSubscriptions()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubOwnerSubscriptionsConvertor::getDocumentation() const {
return Documentation(
"PubSubOwnerSubscriptions",
"This table has the following fields:\n\n"
"- `node`: string\n"
"- `subscriptions`: array<@{PubSubOwnerSubscription}>\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubPublishConvertor.cpp b/Sluift/ElementConvertors/PubSubPublishConvertor.cpp
index 38aca0a..63c97bc 100644
--- a/Sluift/ElementConvertors/PubSubPublishConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubPublishConvertor.cpp
@@ -1,82 +1,80 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubPublishConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubPublishConvertor::PubSubPublishConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubPublish>("pubsub_publish"),
convertors(convertors) {
}
PubSubPublishConvertor::~PubSubPublishConvertor() {
}
std::shared_ptr<PubSubPublish> PubSubPublishConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubPublish> result = std::make_shared<PubSubPublish>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "items");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubItem> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubItem> payload = std::dynamic_pointer_cast<PubSubItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_item"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setItems(items);
}
lua_pop(L, 1);
return result;
}
void PubSubPublishConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubPublish> payload) {
lua_createtable(L, 0, 0);
lua_pushstring(L, payload->getNode().c_str());
lua_setfield(L, -2, "node");
if (!payload->getItems().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getItems().size()), 0);
{
int i = 0;
- foreach(std::shared_ptr<PubSubItem> item, payload->getItems()) {
+ for (auto&& item : payload->getItems()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "items");
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubPublishConvertor::getDocumentation() const {
return Documentation(
"PubSubPublish",
"This table has the following fields:\n\n"
"- `node`: string\n"
"- `items`: array<@{PubSubItem}>\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubRetractConvertor.cpp b/Sluift/ElementConvertors/PubSubRetractConvertor.cpp
index 38e15a1..c070ad6 100644
--- a/Sluift/ElementConvertors/PubSubRetractConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubRetractConvertor.cpp
@@ -1,92 +1,90 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubRetractConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubRetractConvertor::PubSubRetractConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubRetract>("pubsub_retract"),
convertors(convertors) {
}
PubSubRetractConvertor::~PubSubRetractConvertor() {
}
std::shared_ptr<PubSubRetract> PubSubRetractConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubRetract> result = std::make_shared<PubSubRetract>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "items");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubItem> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubItem> payload = std::dynamic_pointer_cast<PubSubItem>(convertors->convertFromLuaUntyped(L, -1, "pubsub_item"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setItems(items);
}
lua_pop(L, 1);
lua_getfield(L, -1, "notify");
if (lua_isboolean(L, -1)) {
result->setNotify(lua_toboolean(L, -1));
}
lua_pop(L, 1);
return result;
}
void PubSubRetractConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubRetract> payload) {
lua_createtable(L, 0, 0);
lua_pushstring(L, payload->getNode().c_str());
lua_setfield(L, -2, "node");
if (!payload->getItems().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getItems().size()), 0);
{
int i = 0;
- foreach(std::shared_ptr<PubSubItem> item, payload->getItems()) {
+ for (auto&& item : payload->getItems()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "items");
}
if (payload->isNotify().is_initialized()) {
lua_pushboolean(L, payload->isNotify().get_value_or(false));
lua_setfield(L, -2, "notify");
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubRetractConvertor::getDocumentation() const {
return Documentation(
"PubSubRetract",
"This table has the following fields:\n\n"
"- `node`: string\n"
"- `items`: array<@{PubSubItem}>\n"
"- `notify`: boolean\n"
);
}
diff --git a/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp b/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp
index 4cc5686..3712192 100644
--- a/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp
+++ b/Sluift/ElementConvertors/PubSubSubscriptionsConvertor.cpp
@@ -1,80 +1,78 @@
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/PubSubSubscriptionsConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
#include <Sluift/LuaElementConvertors.h>
using namespace Swift;
PubSubSubscriptionsConvertor::PubSubSubscriptionsConvertor(LuaElementConvertors* convertors) :
GenericLuaElementConvertor<PubSubSubscriptions>("pubsub_subscriptions"),
convertors(convertors) {
}
PubSubSubscriptionsConvertor::~PubSubSubscriptionsConvertor() {
}
std::shared_ptr<PubSubSubscriptions> PubSubSubscriptionsConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<PubSubSubscriptions> result = std::make_shared<PubSubSubscriptions>();
lua_getfield(L, -1, "node");
if (lua_isstring(L, -1)) {
result->setNode(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::shared_ptr<PubSubSubscription> > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
if (std::shared_ptr<PubSubSubscription> payload = std::dynamic_pointer_cast<PubSubSubscription>(convertors->convertFromLuaUntyped(L, -1, "pubsub_subscription"))) {
items.push_back(payload);
}
}
lua_pop(L, 1);
}
result->setSubscriptions(items);
}
return result;
}
void PubSubSubscriptionsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubSubscriptions> payload) {
lua_createtable(L, 0, 0);
if (payload->getNode()) {
lua_pushstring(L, (*payload->getNode()).c_str());
lua_setfield(L, -2, "node");
}
if (!payload->getSubscriptions().empty()) {
{
int i = 0;
- foreach(std::shared_ptr<PubSubSubscription> item, payload->getSubscriptions()) {
+ for (auto&& item : payload->getSubscriptions()) {
if (convertors->convertToLuaUntyped(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
}
}
boost::optional<LuaElementConvertor::Documentation> PubSubSubscriptionsConvertor::getDocumentation() const {
return Documentation(
"PubSubSubscriptions",
"This table has the following fields:\n\n"
"- `node`: string (Optional)\n"
"- `subscriptions`: array<@{PubSubSubscription}>\n"
);
}
diff --git a/Sluift/ElementConvertors/SecurityLabelConvertor.cpp b/Sluift/ElementConvertors/SecurityLabelConvertor.cpp
index 133b123..21d9a8f 100644
--- a/Sluift/ElementConvertors/SecurityLabelConvertor.cpp
+++ b/Sluift/ElementConvertors/SecurityLabelConvertor.cpp
@@ -1,100 +1,98 @@
/*
* Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Sluift/ElementConvertors/SecurityLabelConvertor.h>
#include <memory>
#include <boost/numeric/conversion/cast.hpp>
#include <lua.hpp>
-#include <Swiften/Base/foreach.h>
-
using namespace Swift;
SecurityLabelConvertor::SecurityLabelConvertor() :
GenericLuaElementConvertor<SecurityLabel>("security_label") {
}
SecurityLabelConvertor::~SecurityLabelConvertor() {
}
std::shared_ptr<SecurityLabel> SecurityLabelConvertor::doConvertFromLua(lua_State* L) {
std::shared_ptr<SecurityLabel> result = std::make_shared<SecurityLabel>();
lua_getfield(L, -1, "equivalent_labels");
if (lua_type(L, -1) == LUA_TTABLE) {
std::vector< std::string > items;
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (lua_isstring(L, -1)) {
items.push_back(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
}
result->setEquivalentLabels(items);
}
lua_pop(L, 1);
lua_getfield(L, -1, "foreground_color");
if (lua_isstring(L, -1)) {
result->setForegroundColor(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "display_marking");
if (lua_isstring(L, -1)) {
result->setDisplayMarking(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "background_color");
if (lua_isstring(L, -1)) {
result->setBackgroundColor(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
lua_getfield(L, -1, "label");
if (lua_isstring(L, -1)) {
result->setLabel(std::string(lua_tostring(L, -1)));
}
lua_pop(L, 1);
return result;
}
void SecurityLabelConvertor::doConvertToLua(lua_State* L, std::shared_ptr<SecurityLabel> payload) {
lua_createtable(L, 0, 0);
if (!payload->getEquivalentLabels().empty()) {
lua_createtable(L, boost::numeric_cast<int>(payload->getEquivalentLabels().size()), 0);
{
int i = 0;
- foreach(const std::string& item, payload->getEquivalentLabels()) {
+ for (const auto& item : payload->getEquivalentLabels()) {
lua_pushstring(L, item.c_str());
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
lua_setfield(L, -2, "equivalent_labels");
}
lua_pushstring(L, payload->getForegroundColor().c_str());
lua_setfield(L, -2, "foreground_color");
lua_pushstring(L, payload->getDisplayMarking().c_str());
lua_setfield(L, -2, "display_marking");
lua_pushstring(L, payload->getBackgroundColor().c_str());
lua_setfield(L, -2, "background_color");
lua_pushstring(L, payload->getLabel().c_str());
lua_setfield(L, -2, "label");
}
boost::optional<LuaElementConvertor::Documentation> SecurityLabelConvertor::getDocumentation() const {
return Documentation(
"SecurityLabel",
"This table has the following fields:\n\n"
"- `equivalent_labels`: array<string>\n"
"- `foreground_color`: string\n"
"- `display_marking`: string\n"
"- `background_color`: string\n"
"- `label`: string\n"
);
}
diff --git a/Sluift/ElementConvertors/StanzaConvertor.h b/Sluift/ElementConvertors/StanzaConvertor.h
index e1d0cb3..bdaaad3 100644
--- a/Sluift/ElementConvertors/StanzaConvertor.h
+++ b/Sluift/ElementConvertors/StanzaConvertor.h
@@ -1,41 +1,40 @@
/*
* Copyright (c) 2014-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma once
#include <boost/numeric/conversion/cast.hpp>
-#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/IQ.h>
#include <Swiften/Elements/Message.h>
#include <Swiften/Elements/Payload.h>
#include <Swiften/Elements/Presence.h>
#include <Sluift/GenericLuaElementConvertor.h>
#include <Sluift/Lua/Exception.h>
#include <Sluift/LuaElementConvertors.h>
namespace Swift {
template <typename T> class StanzaConvertor : public GenericLuaElementConvertor<T> {
public:
StanzaConvertor(const std::string& tag)
: GenericLuaElementConvertor<T>(tag) {
}
virtual ~StanzaConvertor() {
}
std::shared_ptr<T> getStanza(lua_State* L, LuaElementConvertors* convertors) {
std::shared_ptr<T> result = std::make_shared<T>();
lua_getfield(L, -1, "id");
if (lua_isstring(L, -1)) {
result->setID(lua_tostring(L, -1));
}
lua_pop(L, 1);
lua_getfield(L, -1, "from");
if (lua_isstring(L, -1)) {
result->setFrom(lua_tostring(L, -1));
}
@@ -48,42 +47,42 @@ namespace Swift {
lua_getfield(L, -1, "payloads");
if (lua_type(L, -1) == LUA_TTABLE) {
for(size_t i = 0; i < lua_objlen(L, -1); ++i) {
lua_pushnumber(L, i + 1);
lua_gettable(L, -2);
if (!lua_isnil(L, -1)) {
std::shared_ptr<Payload> payload = std::dynamic_pointer_cast<Payload>(convertors->convertFromLua(L, -1));
if (!!payload) {
result->addPayload(payload);
}
}
lua_pop(L, 1);
}
}
lua_pop(L, 1);
return result;
}
void pushStanza(lua_State* L, const std::shared_ptr<T> stanza, LuaElementConvertors* convertors) {
lua_createtable(L, 0, 0);
lua_pushstring(L, stanza->getID().c_str());
lua_setfield(L, -2, "id");
lua_pushstring(L, stanza->getFrom().toString().c_str());
lua_setfield(L, -2, "from");
lua_pushstring(L, stanza->getTo().toString().c_str());
lua_setfield(L, -2, "to");
if (!stanza->getPayloads().empty()) {
lua_createtable(L, boost::numeric_cast<int>(stanza->getPayloads().size()), 0);
{
int i = 0;
- foreach(const std::shared_ptr<Payload> &item, stanza->getPayloads()) {
+ for (const auto& item : stanza->getPayloads()) {
if (convertors->convertToLua(L, item) > 0) {
lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
++i;
}
}
}
lua_setfield(L, -2, "payloads");
}
}
};
}