summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/LogSerializers.cpp68
-rw-r--r--Swiften/Base/LogSerializers.h47
-rw-r--r--Swiften/Base/SConscript1
3 files changed, 116 insertions, 0 deletions
diff --git a/Swiften/Base/LogSerializers.cpp b/Swiften/Base/LogSerializers.cpp
new file mode 100644
index 0000000..ccc8437
--- /dev/null
+++ b/Swiften/Base/LogSerializers.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Base/LogSerializers.h>
+
+#include <Swiften/Elements/Presence.h>
+
+namespace Swift {
+
+std::ostream& operator<<(std::ostream& stream, const Presence& presence) {
+ std::string typeString;
+ switch (presence.getType()) {
+ case Presence::Available:
+ typeString = "Available";
+ break;
+ case Presence::Error:
+ typeString = "Error";
+ break;
+ case Presence::Probe:
+ typeString = "Probe";
+ break;
+ case Presence::Subscribe:
+ typeString = "Subscribe";
+ break;
+ case Presence::Subscribed:
+ typeString = "Subscribed";
+ break;
+ case Presence::Unavailable:
+ typeString = "Unavailable";
+ break;
+ case Presence::Unsubscribe:
+ typeString = "Unsubscribe";
+ break;
+ case Presence::Unsubscribed:
+ typeString = "Unsubscribed";
+ break;
+ }
+
+ std::string showTypeString;
+ switch (presence.getShow()) {
+ case StatusShow::Online:
+ showTypeString = "Online";
+ break;
+ case StatusShow::Away:
+ showTypeString = "Away";
+ break;
+ case StatusShow::FFC:
+ showTypeString = "FFC";
+ break;
+ case StatusShow::DND:
+ showTypeString = "DND";
+ break;
+ case StatusShow::XA:
+ showTypeString = "XA";
+ break;
+ case StatusShow::None:
+ showTypeString = "None";
+ break;
+ }
+
+ stream << "Presence(" << "from: " << presence.getFrom() << ", to: " << presence.getTo() << ", type: " << typeString << ", status: " << showTypeString << ", priority: " << presence.getPriority() << ", '" << presence.getStatus() << "'" << " )";
+ return stream;
+}
+
+};
diff --git a/Swiften/Base/LogSerializers.h b/Swiften/Base/LogSerializers.h
new file mode 100644
index 0000000..3d60426
--- /dev/null
+++ b/Swiften/Base/LogSerializers.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <memory>
+#include <ostream>
+#include <string>
+#include <vector>
+
+namespace Swift {
+
+class Presence;
+
+template <typename T>
+std::ostream& operator<<(std::ostream& stream, const std::shared_ptr<T>& ptr) {
+ if (ptr) {
+ stream << *ptr;
+ }
+ else {
+ stream << "nullptr";
+ }
+ return stream;
+}
+
+template <typename T>
+std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vec) {
+ stream << "[";
+ if (!vec.empty()) {
+ auto it = std::begin(vec);
+ stream << *it;
+
+ ++it;
+ for (auto end = std::end(vec); it != end; ++it) {
+ stream << ", " << *it;
+ }
+ }
+ stream << "]";
+ return stream;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Presence& presence);
+
+};
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index 62e5117..92e3da8 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -7,6 +7,7 @@ objects = swiften_env.SwiftenObject([
"SafeAllocator.cpp",
"Error.cpp",
"Log.cpp",
+ "LogSerializers.cpp",
"Path.cpp",
"Paths.cpp",
"String.cpp",