1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#ifndef GOOSE_UTIL_STRINGID_H
#define GOOSE_UTIL_STRINGID_H
namespace goose::util
{
class StringId
{
public:
StringId() : StringId( "" ) {}
explicit StringId( const string& str );
explicit StringId( string&& str );
explicit StringId( const char* pString ) :
StringId( string( pString ) )
{}
explicit StringId( const char* pString, size_t size ) :
StringId( string( pString, size ) )
{}
explicit StringId( uint32_t uniqueId );
auto operator<=>( StringId rhs ) const
{
return m_id <=> rhs.m_id;
}
auto operator==( StringId rhs ) const
{
return m_id == rhs.m_id;
}
auto operator<( StringId rhs ) const
{
return m_id < rhs.m_id;
}
const string& str() const;
friend ostream& operator<<( ostream& out, StringId sid )
{
return out << sid.str();
}
bool isNumerical() const { return !( m_id & stringMask ); }
auto id() const { return m_id; }
private:
static constexpr uint32_t stringMask = 1 << 31;
uint32_t m_id = 0;
#ifndef NDEBUG
// To be able to see the name in the debugger
const char* m_dbgName = nullptr;
#endif
static unordered_map< string, uint32_t >& ms_strings();
static unordered_map< uint32_t, string >& ms_IDs();
static uint32_t ms_nextUniqueId();
};
}
namespace std
{
template<> struct hash< goose::util::StringId >
{
size_t operator()( const goose::util::StringId& x ) const
{
if( x.isNumerical() )
return hash< uint32_t >()( x.id() );
return hash< string >()( x.str() );
}
};
}
static inline auto operator "" _sid( const char* pString, std::size_t s )
{
return goose::util::StringId( pString, s );
}
#endif
|
|
|
>
>
>
>
|
|
|
|
<
|
>
>
|
|
<
|
<
|
<
|
<
>
|
>
|
|
<
<
<
|
|
<
<
<
|
|
|
|
|
<
<
|
|
|
|
|
|
|
|
|
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#ifndef GOOSE_UTIL_STRINGID_H
#define GOOSE_UTIL_STRINGID_H
namespace goose::util
{
class StringId
{
public:
StringId() :
StringId( "" )
{
}
explicit StringId( const string& str );
explicit StringId( string&& str );
explicit StringId( const char* pString ) :
StringId( string( pString ) )
{
}
explicit StringId( const char* pString, size_t size ) :
StringId( string( pString, size ) )
{
}
explicit StringId( uint32_t uniqueId );
auto operator<=>( StringId rhs ) const { return m_id <=> rhs.m_id; }
auto operator==( StringId rhs ) const { return m_id == rhs.m_id; }
auto operator<( StringId rhs ) const { return m_id < rhs.m_id; }
const string& str() const;
friend ostream& operator<<( ostream& out, StringId sid ) { return out << sid.str(); }
bool isNumerical() const { return !( m_id & stringMask ); }
auto id() const { return m_id; }
private:
static constexpr uint32_t stringMask = 1 << 31;
uint32_t m_id = 0;
#ifndef NDEBUG
// To be able to see the name in the debugger
const char* m_dbgName = nullptr;
#endif
static unordered_map< string, uint32_t >& ms_strings();
static unordered_map< uint32_t, string >& ms_IDs();
static uint32_t ms_nextUniqueId();
};
} // namespace goose::util
namespace std
{
template<> struct hash< goose::util::StringId >
{
size_t operator()( const goose::util::StringId& x ) const
{
if( x.isNumerical() )
return hash< uint32_t >()( x.id() );
return hash< string >()( x.str() );
}
};
} // namespace std
static inline auto operator"" _sid( const char* pString, std::size_t s )
{
return goose::util::StringId( pString, s );
}
#endif
|