summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-08-05 07:08:10 (GMT)
committerTobias Markmann <tm@ayena.de>2016-08-05 07:08:10 (GMT)
commita0f588cad07d1bc31725ac63e38ac25c2530d7ce (patch)
tree2d358d0b8365bc33749ef6aa375f78b5a721c0bf /Swiften/Base/LogSerializers.h
parentc135724a9daa6e3dca7bf75abc9c4cabdc585e88 (diff)
downloadswift-a0f588cad07d1bc31725ac63e38ac25c2530d7ce.zip
swift-a0f588cad07d1bc31725ac63e38ac25c2530d7ce.tar.bz2
Add a debugging helper for serializing Swiften types to ostream
Test-Information: Tested on OS X 10.11.6. Change-Id: I9ecb60f5c3956d52fd42acd1b0d85725277efc51
Diffstat (limited to 'Swiften/Base/LogSerializers.h')
-rw-r--r--Swiften/Base/LogSerializers.h47
1 files changed, 47 insertions, 0 deletions
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);
+
+};