]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/tag.cpp
Make Tags convertible back to the original string in debug builds
[libs/gl.git] / source / render / tag.cpp
index c5824aec4e114d60b04c53acd00ae2b54072f7fe..b5f860334e8a3792b7d8f4fe88f47e2dcd9a4e31 100644 (file)
@@ -1,17 +1,54 @@
 #include <cstring>
+#include <map>
 #include <msp/core/hash.h>
+#include <msp/strings/format.h>
 #include "tag.h"
 
+using namespace std;
+
+namespace {
+
+#ifdef DEBUG
+map<Msp::GL::Tag, string> tag_names;
+#endif
+
+}
+
 namespace Msp {
 namespace GL {
 
 Tag::Tag(const char *s):
        id((s && *s) ? hash32(s, strlen(s)) : 0)
-{ }
+{
+#ifdef DEBUG
+       if(s)
+               tag_names.insert(make_pair(*this, string(s)));
+#endif
+}
 
 Tag::Tag(const std::string &s):
        id(s.empty() ? 0 : hash32(s))
-{ }
+{
+#ifdef DEBUG
+       if(!s.empty())
+               tag_names.insert(make_pair(*this, s));
+#endif
+}
+
+string Tag::str() const
+{
+#ifdef DEBUG
+       map<Tag, string>::const_iterator i=tag_names.find(*this);
+       if(i!=tag_names.end())
+               return i->second;
+#endif
+       return format("Tag(%d)", id);
+}
+
+void operator<<(LexicalConverter &conv, Tag tag)
+{
+       conv.result(tag.str());
+}
 
 } // namespace GL
 } // namespace Msp