aboutsummaryrefslogtreecommitdiff
path: root/source/lib/src/command.cpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2022-09-16 23:28:09 +0200
committerFelix Morgner <felix.morgner@gmail.com>2022-09-16 23:28:09 +0200
commitf4d9880d3c9555b48affad727589ef5c093b1841 (patch)
treea5552b5a33000a527748ac1c72ca366476af0936 /source/lib/src/command.cpp
parent64922e213ac731279cf3341253e67509adb2dfc8 (diff)
downloadwanda-f4d9880d3c9555b48affad727589ef5c093b1841.tar.xz
wanda-f4d9880d3c9555b48affad727589ef5c093b1841.zip
source: clean up structure
Diffstat (limited to 'source/lib/src/command.cpp')
-rw-r--r--source/lib/src/command.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/source/lib/src/command.cpp b/source/lib/src/command.cpp
new file mode 100644
index 0000000..83c6b73
--- /dev/null
+++ b/source/lib/src/command.cpp
@@ -0,0 +1,47 @@
+#include "wanda/command.hpp"
+
+namespace wanda
+{
+ std::optional<message> 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};
+ }
+
+ std::optional<command> make_command(message message)
+ {
+ if (message.command == "CHANGE")
+ {
+ return {{command_id::change}};
+ }
+
+ return std::nullopt;
+ }
+
+ command make_change_command()
+ {
+ return {command_id::change};
+ }
+
+} // namespace wanda \ No newline at end of file