From e78a940d37e8ab614fd566ee840d00fbaa577c40 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Wed, 26 Aug 2020 12:31:23 +0200 Subject: fix description being an extra field of command annotation --- include/Handler.hpp | 6 +++--- src/SimpleHandlers.cpp | 6 +----- src/main.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/Handler.hpp b/include/Handler.hpp index b84315d..63efa5d 100644 --- a/include/Handler.hpp +++ b/include/Handler.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include @@ -13,7 +13,7 @@ namespace Handler { void *payload)> handler_function; struct CommandHandler { - CommandHandler(std::string command, handler_function func, std::queue *description, void *payload = nullptr) + CommandHandler(std::string command, handler_function func, std::vector *description, void *payload = nullptr) : command{std::move(command)}, func{std::move(func)}, description{description}, payload{payload} {} ~CommandHandler() { @@ -37,7 +37,7 @@ namespace Handler { std::string command; handler_function func{nullptr}; // handler takes ownership of the description, using it after passing is unsafe - std::queue *description{nullptr}; + std::vector *description{nullptr}; void *payload{nullptr}; }; diff --git a/src/SimpleHandlers.cpp b/src/SimpleHandlers.cpp index 40cfa68..0ebdd79 100644 --- a/src/SimpleHandlers.cpp +++ b/src/SimpleHandlers.cpp @@ -36,14 +36,10 @@ Handler::json Handler::helpHandler(std::string const &arguments, std::string con for (auto const &itor : *commands) { std::vector commandAnnotations; - commandAnnotations.emplace_back(create_annotation(Reply::AnnotationType::command)); + commandAnnotations.emplace_back(create_annotation(Reply::AnnotationType::command, std::move(*itor.description))); reply_vec.emplace_back(create_text("- ")); reply_vec.emplace_back(create_text(itor.command, std::move(commandAnnotations))); - while (!itor.description->empty()) { - reply_vec.emplace_back(std::move(itor.description->back())); - itor.description->pop(); - } } reply_vec.emplace_back(create_text( diff --git a/src/main.cpp b/src/main.cpp index 8e0b442..8289584 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,10 +19,10 @@ int main() { crow::SimpleApp app; - auto createPlainDescriptionFromText = [](std::string const &text) -> std::queue * { - auto reply_queue = new std::queue; - reply_queue->emplace(Response::create_text(text)); - return reply_queue; + auto createPlainDescriptionFromText = [](std::string const &text) -> std::vector * { + auto reply_vector = new std::vector; + reply_vector->emplace_back(Response::create_text(text)); + return reply_vector; }; // command --> handler -- cgit v1.2.3-54-g00ecf