Simulant  21.12-1197
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
uniquely_identifiable.h
1 #pragma once
2 
3 #include "../threads/atomic.h"
4 
5 /* Adds a uuid() method to objects which is distinct
6  * across objects of this type. Copying / assigning the object will
7  * generate a new uuid! */
8 
9 namespace smlt {
10 
11 typedef uint64_t uuid64;
12 
13 template<typename T>
15 public:
17  uuid_(generate_uuid()) {}
18 
20  uuid_(generate_uuid()) {}
21 
22  UniquelyIdentifiable& operator=(const UniquelyIdentifiable& rhs) {
23  if(&rhs == this) {
24  return *this;
25  }
26 
27  uuid_ = generate_uuid();
28  return *this;
29  }
30 
31  uuid64 uuid() const {
32  return uuid_;
33  }
34 
35 private:
36  /* FIXME: Do something better */
37  static uuid64 generate_uuid() {
38  static thread::Atomic<uuid64> counter(~0);
39  return --counter;
40  }
41 
42  uuid64 uuid_;
43 };
44 
45 }
smlt::UniquelyIdentifiable
Definition: uniquely_identifiable.h:14
smlt
Definition: animation.cpp:25
smlt::thread::Atomic
Definition: atomic.h:10