OpenShaderDesigner
0.0.1
Loading...
Searching...
No Matches
Include
Utility
UniqueID.h
1
// =====================================================================================================================
2
// Copyright 2024 Medusa Slockbower
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// =====================================================================================================================
15
16
#ifndef ENGINE_UNIQUEID_H
17
#define ENGINE_UNIQUEID_H
18
19
#include <cstdint>
20
21
#ifdef _MSC_VER
22
#define COUNTER __declspec(selectany)
23
#endif
24
25
namespace
OpenShaderDesigner
26
{
27
template
<
typename
Base> uint64_t _Increment()
28
{
29
static
uint64_t current = 0;
30
return
current++;
31
}
32
33
// Unfortunately adds a little bit of overhead at runtime
34
template
<
typename
Base,
typename
Type> uint64_t UniqueID()
35
{
36
static
bool
initialized =
false
;
37
static
uint64_t
id
= 0;
38
39
if
(initialized)
return
id;
40
initialized =
true
;
41
return
id
= _Increment<Base>();
42
}
43
}
44
45
#endif
//ENGINE_UNIQUEID_H
Generated by
1.11.0