From: Mikko Rasa Date: Sat, 10 Apr 2021 09:45:50 +0000 (+0300) Subject: Make Tags convertible back to the original string in debug builds X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=20622e74de6753c5e4460a112c11ee913707e8e8;p=libs%2Fgl.git Make Tags convertible back to the original string in debug builds This helps in producing more readable error messages --- diff --git a/source/render/tag.cpp b/source/render/tag.cpp index c5824aec..b5f86033 100644 --- a/source/render/tag.cpp +++ b/source/render/tag.cpp @@ -1,17 +1,54 @@ #include +#include #include +#include #include "tag.h" +using namespace std; + +namespace { + +#ifdef DEBUG +map 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::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 diff --git a/source/render/tag.h b/source/render/tag.h index 93808989..dbc0b3ef 100644 --- a/source/render/tag.h +++ b/source/render/tag.h @@ -2,6 +2,7 @@ #define MSP_GL_TAG_H_ #include +#include namespace Msp { namespace GL { @@ -18,10 +19,15 @@ struct Tag Tag(const char *); Tag(const std::string &s); + std::string str() const; + bool operator<(Tag t) const { return id