summaryrefslogtreecommitdiff
path: root/src/logging.h
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2011-10-28 17:18:29 -0700
committer Elliott Hughes <enh@google.com> 2011-10-28 17:34:47 -0700
commite0918556e7551de638870dcad3f2023f94f85a50 (patch)
treeb866a2b267124354ff2f46815d9870db7e093882 /src/logging.h
parent6a5bd495ff2f614f1495f652c86f3902d3bde537 (diff)
Provide a convenience for logging types that don't have an operator<<.
Change-Id: I650b852ded67576dc5ec7c8e57732cfb49f1ecd6
Diffstat (limited to 'src/logging.h')
-rw-r--r--src/logging.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/logging.h b/src/logging.h
index 2e7856ef28..b65393174d 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -171,6 +171,32 @@ class LogMessage {
void HexDump(const void* address, size_t byte_count, bool show_actual_address = false);
+// A convenience to allow any class with a "Dump(std::ostream& os)" member function
+// but without an operator<< to be used as if it had an operator<<. Use like this:
+//
+// os << Dumpable<MyType>(my_type_instance);
+//
+template<typename T>
+class Dumpable {
+ public:
+ explicit Dumpable(T& value) : value_(value) {
+ }
+
+ void Dump(std::ostream& os) const {
+ value_.Dump(os);
+ }
+
+ private:
+ T& value_;
+ DISALLOW_COPY_AND_ASSIGN(Dumpable);
+};
+
+template<typename T>
+std::ostream& operator<<(std::ostream& os, const Dumpable<T>& rhs) {
+ rhs.Dump(os);
+ return os;
+}
+
} // namespace art
#endif // ART_SRC_LOGGING_H_