EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
echomap::Object< Derived > Class Template Reference

A participant in a runtime object model with a numerically unique identifier and display name. More...

#include <Object.hpp>

Classes

struct  CopyTag
 Tag despatch discriminator for copying the base object, preserving uniqueness of IDs. More...

Public Member Functions

 ~Object ()=default
 Non-virtual base destructor.
id_type get_id () const noexcept
bool is_valid () const noexcept
void set_name (const std::string_view new_name)
std::string_view get_name () const noexcept
const char * get_imgui_name () const noexcept
 Object (const Object &)=delete
Object & operator= (const Object &)=delete
Object & operator= (Object &&)=delete
bool operator== (const Object &other) const noexcept
 Determine shallow equality between two Object instances.

Static Public Member Functions

static std::string_view get_class_name () noexcept

Protected Member Functions

 Object ()
 Create a new Object with an auto-allocated ID and default display name.
 Object (const std::string_view object_name)
 Create a new Object with an auto-allocated ID and custom display name.
 Object (Object &&other) noexcept
 Object (CopyTag tag, const Object &old)
 Copy an existing Object.
 Object (CopyTag tag, const Object &old, const std::string_view new_name)
 Copy an existing Object.
void move_identity_from (Object &&other) noexcept
 Helper for derived classes to provide move-assignment operations.

Private Attributes

id_type id
 Primary numerical ID.
std::size_t copy_count = 0
 Number of times the object has been copied; used only for display names.
std::string name
 Display name for the object.

Static Private Attributes

static constexpr std::string_view class_name = "Object"
 Display name for objects of the type determined by the templated class.

Detailed Description

template<typename Derived>
class echomap::Object< Derived >

A participant in a runtime object model with a numerically unique identifier and display name.

A design invariant, which is not realistically possible to enforce, requires that no two objects of the same class co-exist for any non-trivial duration with matching IDs. In this context, a "non-trivial lifetime" would be any state that outlives a function as a member or global variable.

In general, users should refer to objects by their stable numerical ID as opposed to iterators, pointers, or references. Transparent hashing on ordered and unordered STL containers allows fast and convenient lookup in the ID.

Template Parameters
DerivedThe concrete derived type, used for CRTP static polymorphism.

Definition at line 35 of file Object.hpp.

Constructor & Destructor Documentation

◆ ~Object()

template<typename Derived>
echomap::Object< Derived >::~Object ( )
default

Non-virtual base destructor.

We don't want vtables for Object instances. Object uses CRTP, so deleting an Object through Object* is not a concern.

◆ Object() [1/5]

template<typename Derived>
echomap::Object< Derived >::Object ( )
inlineprotected

Create a new Object with an auto-allocated ID and default display name.

Definition at line 111 of file Object.hpp.

111 :
114 {
115 }
A participant in a runtime object model with a numerically unique identifier and display name.
Definition Object.hpp:36
id_type id
Primary numerical ID.
Definition Object.hpp:237
std::string name
Display name for the object.
Definition Object.hpp:239
static constexpr std::string_view class_name
Display name for objects of the type determined by the templated class.
Definition Object.hpp:235

◆ Object() [2/5]

template<typename Derived>
echomap::Object< Derived >::Object ( const std::string_view object_name)
inlineexplicitprotected

Create a new Object with an auto-allocated ID and custom display name.

Parameters
object_nameThe display name of the object. If empty, uses a sensible default based on the ID.

Definition at line 122 of file Object.hpp.

124 :
127 {
128 }

◆ Object() [3/5]

template<typename Derived>
echomap::Object< Derived >::Object ( Object< Derived > && other)
inlineprotectednoexcept

Definition at line 130 of file Object.hpp.

132 :
134 other.id,
136 )),
140 0
141 )
142 ),
144 {
145 }
std::size_t copy_count
Number of times the object has been copied; used only for display names.
Definition Object.hpp:238

◆ Object() [4/5]

template<typename Derived>
echomap::Object< Derived >::Object ( CopyTag tag,
const Object< Derived > & old )
inlineprotected

Copy an existing Object.

The new Object receives a newly allocated ID and a sensible default display name.

Parameters
tagCopyTag despatch tag.
oldThe existing Object to copy.

Definition at line 155 of file Object.hpp.

158 :
162 "{} ({})",
163 old.get_name(),
165 ))
166 {
167 ++old.copy_count;
168 }

◆ Object() [5/5]

template<typename Derived>
echomap::Object< Derived >::Object ( CopyTag tag,
const Object< Derived > & old,
const std::string_view new_name )
inlineprotected

Copy an existing Object.

The new Object receives a newly allocated ID.

Parameters
tagCopyTag despatch tag.
oldThe existing Object to copy.
new_nameThe display name of the new Object.

Definition at line 179 of file Object.hpp.

183 :
187 {
188 }

Member Function Documentation

◆ get_class_name()

template<typename Derived>
std::string_view echomap::Object< Derived >::get_class_name ( )
inlinestaticnodiscardnoexcept

Definition at line 77 of file Object.hpp.

78 {
79 return class_name;
80 }

◆ get_id()

template<typename Derived>
id_type echomap::Object< Derived >::get_id ( ) const
inlinenodiscardnoexcept

Definition at line 46 of file Object.hpp.

47 {
48 assert(is_valid());
49 return id;
50 }

◆ get_imgui_name()

template<typename Derived>
const char * echomap::Object< Derived >::get_imgui_name ( ) const
inlinenodiscardnoexcept

Definition at line 71 of file Object.hpp.

72 {
73 assert(is_valid());
74 return name.c_str();
75 }

◆ get_name()

template<typename Derived>
std::string_view echomap::Object< Derived >::get_name ( ) const
inlinenodiscardnoexcept

Definition at line 65 of file Object.hpp.

66 {
67 assert(is_valid());
68 return name;
69 }

◆ is_valid()

template<typename Derived>
bool echomap::Object< Derived >::is_valid ( ) const
inlinenodiscardnoexcept

Definition at line 52 of file Object.hpp.

53 {
55 }

◆ move_identity_from()

template<typename Derived>
void echomap::Object< Derived >::move_identity_from ( Object< Derived > && other)
inlineprotectednoexcept

Helper for derived classes to provide move-assignment operations.

For example,

Sensor& operator=(Sensor&& other) noexcept
{
if (this == &other)
return *this;
Object::move_identity_from(std::move(other));
position = std::move(other.position);
colour = std::move(other.colour);
return *this;
}
void move_identity_from(Object &&other) noexcept
Helper for derived classes to provide move-assignment operations.
Definition Object.hpp:211
Parameters
otherThe Object being moved from, to have its state invalidated.

Definition at line 211 of file Object.hpp.

214 {
215 if (this == &other)
216 return;
217
218 assert(other.is_valid());
219
223 }
T exchange(T... args)

◆ operator==()

template<typename Derived>
bool echomap::Object< Derived >::operator== ( const Object< Derived > & other) const
inlinenodiscardnoexcept

Determine shallow equality between two Object instances.

Equality is solely determined by the primary ID.

Parameters
otherThe Object to compare against.
Returns
Do the IDs indicate that the current Object is equal to the other one?

Definition at line 94 of file Object.hpp.

97 {
98 return id == other.id;
99 }

◆ set_name()

template<typename Derived>
void echomap::Object< Derived >::set_name ( const std::string_view new_name)
inline

Definition at line 57 of file Object.hpp.

60 {
61 assert(is_valid());
62 this->name = std::string(new_name);
63 }

Member Data Documentation

◆ class_name

template<typename Derived>
std::string_view echomap::Object< Derived >::class_name = "Object"
staticconstexprprivate

Display name for objects of the type determined by the templated class.

Inheriting classes should override the class name by doing something equivalent to:

Definition at line 235 of file Object.hpp.

◆ copy_count

template<typename Derived>
std::size_t echomap::Object< Derived >::copy_count = 0
mutableprivate

Number of times the object has been copied; used only for display names.

Definition at line 238 of file Object.hpp.

◆ id

template<typename Derived>
id_type echomap::Object< Derived >::id
private

Primary numerical ID.

Definition at line 237 of file Object.hpp.

◆ name

template<typename Derived>
std::string echomap::Object< Derived >::name
private

Display name for the object.

Definition at line 239 of file Object.hpp.


The documentation for this class was generated from the following file: