summaryrefslogtreecommitdiffstats
path: root/src/event_to_string.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 17:18:34 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 21:09:38 +0100
commit900ff665db0f4d0b591935df9f9b7e1f402f5908 (patch)
tree094de37f5ea7c61b32dabb14eda9dc1c9cc5f089 /src/event_to_string.cpp
parent032b4951d503f7085526ed03f98e8f19b5dea459 (diff)
downloadpatchage-900ff665db0f4d0b591935df9f9b7e1f402f5908.tar.gz
patchage-900ff665db0f4d0b591935df9f9b7e1f402f5908.tar.bz2
patchage-900ff665db0f4d0b591935df9f9b7e1f402f5908.zip
Add utilities for printing events
Diffstat (limited to 'src/event_to_string.cpp')
-rw-r--r--src/event_to_string.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/event_to_string.cpp b/src/event_to_string.cpp
new file mode 100644
index 0000000..e351c28
--- /dev/null
+++ b/src/event_to_string.cpp
@@ -0,0 +1,82 @@
+/* This file is part of Patchage.
+ * Copyright 2007-2020 David Robillard <d@drobilla.net>
+ *
+ * Patchage is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * Patchage is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Patchage. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "event_to_string.hpp"
+
+#include "PatchageEvent.hpp"
+#include "warnings.hpp"
+
+PATCHAGE_DISABLE_FMT_WARNINGS
+#include <fmt/core.h>
+#include <fmt/ostream.h>
+PATCHAGE_RESTORE_WARNINGS
+
+#include <cstdint>
+#include <iostream>
+#include <string>
+
+namespace {
+
+struct EventPrinter
+{
+ using result_type = std::string; ///< For boost::apply_visitor
+
+ std::string operator()(const ClientCreationEvent& event)
+ {
+ return fmt::format("Add client \"{}\"", event.id);
+ }
+
+ std::string operator()(const ClientDestructionEvent& event)
+ {
+ return fmt::format("Remove client \"{}\"", event.id);
+ }
+
+ std::string operator()(const PortCreationEvent& event)
+ {
+ return fmt::format("Add port \"{}\"", event.id);
+ }
+
+ std::string operator()(const PortDestructionEvent& event)
+ {
+ return fmt::format("Remove port \"{}\"", event.id);
+ }
+
+ std::string operator()(const ConnectionEvent& event)
+ {
+ return fmt::format("Connect \"{}\" to \"{}\"", event.tail, event.head);
+ }
+
+ std::string operator()(const DisconnectionEvent& event)
+ {
+ return fmt::format(
+ "Disconnect \"{}\" from \"{}\"", event.tail, event.head);
+ }
+};
+
+} // namespace
+
+std::string
+event_to_string(const PatchageEvent& event)
+{
+ EventPrinter printer;
+ return boost::apply_visitor(printer, event);
+}
+
+std::ostream&
+operator<<(std::ostream& os, const PatchageEvent& event)
+{
+ return os << event_to_string(event);
+}