#pragma once #include #include #include #include #include "crow.h" namespace Handler { typedef crow::json::wvalue json; typedef std::function handler_function; struct CommandHandler { CommandHandler(std::string command, handler_function func, std::queue *description, void *payload = nullptr) : command{std::move(command)}, func{std::move(func)}, description{description}, payload{payload} {} ~CommandHandler() { delete description; description = nullptr; } CommandHandler(CommandHandler &&o) noexcept { func = o.func; description = o.description; o.description = nullptr; payload = o.payload; } [[nodiscard]] json exec(std::string const &arguments, std::string const &session) const { return func(arguments, session, payload); } std::string command; handler_function func{nullptr}; // handler takes ownership of the description, using it after passing is unsafe std::queue *description{nullptr}; void *payload{nullptr}; }; std::vector tokenizeArguments(std::string const &arguments, std::string const &delimiter = " "); }