]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/tag.cpp
Use Tag to identify uniforms in Program and ProgramData
[libs/gl.git] / source / core / tag.cpp
diff --git a/source/core/tag.cpp b/source/core/tag.cpp
new file mode 100644 (file)
index 0000000..b5f8603
--- /dev/null
@@ -0,0 +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