SleakEngine 0.1.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_name(name),
16 m_uniqueID(s_nextUniqueID.fetch_add(1, std::memory_order_relaxed)) {}
17
18 virtual ~Object() = default;
19
20 uint64_t GetUniqueID() const { return m_uniqueID; }
21
22 const std::string& GetName() const { return m_name; }
23
24 /// Name plus unique ID, for logs where names can repeat.
25 std::string GetDebugName() const {
26 return m_name + "-" + std::to_string(m_uniqueID);
27 }
28
29 inline void SetName(const std::string& value) { m_name = value; }
30
31 private:
32 std::string m_name;
33 uint64_t m_uniqueID;
34 static inline std::atomic<uint64_t> s_nextUniqueID = 0;
35 };
36}
37
38#endif
virtual ~Object()=default
std::string GetDebugName() const
Name plus unique ID, for logs where names can repeat.
Definition Object.hpp:25
void SetName(const std::string &value)
Definition Object.hpp:29
const std::string & GetName() const
Definition Object.hpp:22
Object(const std::string &name="Object")
Definition Object.hpp:14
uint64_t GetUniqueID() const
Definition Object.hpp:20
Root namespace for everything the engine exposes.
Definition Camera.hpp:10