From 577fc0845718ed8ad5bebf02a277c0579a817f77 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 17 May 2024 17:58:38 +0200 Subject: wanda: restructure source layout --- source/lib/proto/src/command.cpp | 47 ----------------------- source/lib/proto/src/message.cpp | 82 ---------------------------------------- 2 files changed, 129 deletions(-) delete mode 100644 source/lib/proto/src/command.cpp delete mode 100644 source/lib/proto/src/message.cpp (limited to 'source/lib/proto/src') diff --git a/source/lib/proto/src/command.cpp b/source/lib/proto/src/command.cpp deleted file mode 100644 index 5a669f5..0000000 --- a/source/lib/proto/src/command.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "wanda/proto/command.hpp" - -namespace wanda::proto -{ - 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::proto::message{"C", command, argument_string}; - } - - std::optional 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::proto \ No newline at end of file diff --git a/source/lib/proto/src/message.cpp b/source/lib/proto/src/message.cpp deleted file mode 100644 index f44ca06..0000000 --- a/source/lib/proto/src/message.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "wanda/proto/message.hpp" - -#include - -#include -#include -#include - -namespace wanda::proto -{ - message::operator std::string() const - { - std::ostringstream buffer{}; - buffer << source - << ':' - << command; - if (argument.has_value()) - { - buffer << ':' << *argument; - } - return buffer.str(); - } - - std::size_t message::size() const - { - return static_cast(*this).size(); - } - - template - OutputIt copy_until(InputIt first, InputIt last, OutputIt out, UnaryPredicate predicate) - { - while (first != last && !predicate(*first)) - { - *out++ = *first++; - } - return out; - } - - std::istream & operator>>(std::istream & in, message & message) - { - auto pos = std::istream_iterator{in}; - auto end = std::istream_iterator{}; - auto buffer = std::string{}; - - copy_until(pos, end, std::back_inserter(buffer), [](auto const & c) { return c == ':'; }); - if (in.eof() || buffer.size() != 1) - { - in.setstate(std::ios_base::failbit); - return in; - } - message.source = buffer; - - buffer.clear(); - copy_until(++pos, end, std::back_inserter(buffer), [](auto const & c) { return c == ':'; }); - if (in.eof()) - { - in.setstate(std::ios_base::failbit); - } - message.command = buffer; - - buffer.clear(); - copy(++pos, end, std::back_inserter(buffer)); - if (buffer.size()) - { - message.argument = std::optional{std::move(buffer)}; - } - - in.clear(in.rdstate() ^ std::ios_base::failbit); - return in; - } - - std::ostream & operator<<(std::ostream & out, message const & message) - { - return out << static_cast(message); - } - -} // namespace wanda::proto - -auto spdlog::fmt_lib::formatter::format(wanda::proto::message const & message, format_context & context) const -> decltype(context.out()) -{ - return formatter::format(static_cast(message), context); -} -- cgit v1.2.3