]> git.tdb.fi Git - libs/gl.git/blob - source/core/tag.cpp
Compute correct size for SPIR-V structs if the last member is an array
[libs/gl.git] / source / core / tag.cpp
1 #include <cstring>
2 #include <map>
3 #include <msp/core/hash.h>
4 #include <msp/strings/format.h>
5 #include "tag.h"
6
7 using namespace std;
8
9 namespace {
10
11 #ifdef DEBUG
12 map<Msp::GL::Tag, string> &get_tag_names()
13 {
14         static map<Msp::GL::Tag, string> names;
15         return names;
16 }
17 #endif
18
19 }
20
21 namespace Msp {
22 namespace GL {
23
24 Tag::Tag(const char *s):
25         id((s && *s) ? hash32(s, strlen(s)) : 0)
26 {
27 #ifdef DEBUG
28         if(s)
29                 get_tag_names().insert(make_pair(*this, string(s)));
30 #endif
31 }
32
33 Tag::Tag(const string &s):
34         id(s.empty() ? 0 : hash32(s))
35 {
36 #ifdef DEBUG
37         if(!s.empty())
38                 get_tag_names().insert(make_pair(*this, s));
39 #endif
40 }
41
42 string Tag::str() const
43 {
44 #ifdef DEBUG
45         const auto &names = get_tag_names();
46         auto i = names.find(*this);
47         if(i!=names.end())
48                 return i->second;
49 #endif
50         return format("Tag(%d)", id);
51 }
52
53 void operator<<(LexicalConverter &conv, Tag tag)
54 {
55         conv.result(tag.str());
56 }
57
58 } // namespace GL
59 } // namespace Msp