diff options
author | Tobias Markmann <tm@ayena.de> | 2016-11-23 07:09:39 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-11-23 11:30:02 (GMT) |
commit | e405ff3561be3d3c0bd79d7d5173923a8828cf02 (patch) | |
tree | 9118ef838ebfaec1df90ec24761944b5d833774c /Sluift/ElementConvertors/CommandConvertor.cpp | |
parent | 8a71b91be885652f37c5aab5e1ecf25af4599fbc (diff) | |
download | swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.zip swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.tar.bz2 |
Migrate remaining Swiften/Base/foreach.h use to range-based for loop
Test-Information:
Build on macOS 10.12.1 and all tests pass.
Change-Id: Iedaa3fa7e7672c77909fd0568bf30e9393cb87e0
Diffstat (limited to 'Sluift/ElementConvertors/CommandConvertor.cpp')
-rw-r--r-- | Sluift/ElementConvertors/CommandConvertor.cpp | 6 |
1 files changed, 2 insertions, 4 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"); } } |