SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Object.hpp
Go to the documentation of this file.
1#ifndef _OBJECT_H_
2#define _OBJECT_H_
3
4#include <cstdint>
5#include <string>
6#include <atomic>
7
8namespace Sleak {
9 /// Base for anything needing a stable identity: a name and a
10 /// process-unique, atomically assigned ID.
11 /// @ingroup core
12 class Object {
13 public:
14 Object(const std::string& name = "Object")
15 : m_uniqueID(s_nextUniqueID.fetch_add(1, std::memory_order_relaxed)),
16 m_name(name)
17 {
18 SetName(m_name + "-" + std::to_string(m_uniqueID));
19 }
20
21 virtual ~Object() = default;
22
23 uint64_t GetUniqueID() const { return m_uniqueID; }
24
25 const std::string& GetName() const { return m_name; }
26
27 inline void SetName(const std::string& value) { m_name = value; }
28
29 private:
30 std::string m_name;
31 uint64_t m_uniqueID;
32 static inline std::atomic<uint64_t> s_nextUniqueID = 0;
33 };
34}
35
36#endif
virtual ~Object()=default
void SetName(const std::string &value)
Definition Object.hpp:27
const std::string & GetName() const
Definition Object.hpp:25
Object(const std::string &name="Object")
Definition Object.hpp:14
uint64_t GetUniqueID() const
Definition Object.hpp:23
Root namespace for everything the engine exposes.
Definition Camera.hpp:10