From 753c0c35b3fea2e45cd83849afde303eea5ccd24 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 1 Dec 2018 19:22:43 +0100 Subject: core: extract command --- src/command.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/command.cpp (limited to 'src/command.cpp') diff --git a/src/command.cpp b/src/command.cpp new file mode 100644 index 0000000..092d69d --- /dev/null +++ b/src/command.cpp @@ -0,0 +1,33 @@ +#include "command.hpp" + +namespace wanda +{ + +std::optional command::message() const +{ + using namespace std::string_literals; + auto const command = [this] { + switch (id) + { + case command_id::change: + return "CHANGE"s; + default: + return ""s; + } + }(); + + auto argument_string = std::string{}; + for (int index = 0ul; index < arguments.size(); ++index) + { + argument_string += (index) ? "," + arguments[index] : arguments[index]; + } + + if (command.empty()) + { + return std::nullopt; + } + + return wanda::message{"C", command, argument_string}; +} + +} // namespace wanda \ No newline at end of file -- cgit v1.2.3