Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils::OwningObjectRegistry< VariantT, BaseT > Class Template Reference

A registry that owns and manages objects identified by a UUID. More...

#include <src/utils/uuid_identifiable_object.h>

Inheritance diagram for zrythm::utils::OwningObjectRegistry< VariantT, BaseT >:
Collaboration diagram for zrythm::utils::OwningObjectRegistry< VariantT, BaseT >:

Public Types

using UuidType = typename UuidIdentifiableObject<BaseT>::Uuid
using VariantType = VariantT
using BaseType = BaseT

Public Member Functions

 OwningObjectRegistry (QObject *parent=nullptr)
template<typename CreateType, typename... Args>
requires std::derived_from<CreateType, BaseT>
auto create_object (Args &&... args) -> UuidReference< OwningObjectRegistry >
template<typename CreateType, typename... Args>
requires std::derived_from<CreateType, BaseT>
auto clone_object (const CreateType &other, Args &&... args) -> UuidReference< OwningObjectRegistry >
auto get_iterator_for_id (const UuidType &id) const
auto get_iterator_for_id (const UuidType &id)
std::optional< VariantT > find_by_id (const UuidType &id) const noexcept
 Returns an object by id.
auto find_by_id_or_throw (const UuidType &id) const
BaseT * find_by_id_as_base_or_throw (const UuidType &id) const
bool contains (const UuidType &id) const
void register_object (VariantT obj_ptr)
 Registers an object.
template<typename ObjectT>
requires std::derived_from<ObjectT, BaseT>
void register_object (ObjectT &obj)
auto reference_count (const UuidType &id) const
 Returns the reference count of an object.
void acquire_reference (const UuidType &id)
void release_reference (const UuidType &id)
auto & get_hash_map () const
auto get_uuids () const
 Returns a list of all UUIDs of the objects in the registry.
size_t size () const

Friends

void to_json (nlohmann::json &j, const OwningObjectRegistry &obj)
template<ObjectBuilder BuilderT>
void from_json_with_builder (const nlohmann::json &j, OwningObjectRegistry &obj, const BuilderT &builder)

Detailed Description

template<typename VariantT, UuidIdentifiable BaseT>
class zrythm::utils::OwningObjectRegistry< VariantT, BaseT >

A registry that owns and manages objects identified by a UUID.

This class provides methods to register, unregister, and find objects by their UUID. When an object is registered, this class takes ownership of it and sets the parent to this. When an object is unregistered, the ownership is released and the caller is responsible for deleting the object.

Intended to be used with variants of pointers to QObjects.

Note
The registry API is not thread-safe. Registry construction, object registration and deregistration, etc., must only be done from the main thread.
Template Parameters
VariantTA variant of raw pointers to QObject-derived classes.
BaseTThe common base class of the objects in the variant.

Definition at line 325 of file uuid_identifiable_object.h.

Member Typedef Documentation

◆ BaseType

template<typename VariantT, UuidIdentifiable BaseT>
using zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::BaseType = BaseT

Definition at line 330 of file uuid_identifiable_object.h.

◆ UuidType

template<typename VariantT, UuidIdentifiable BaseT>
using zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::UuidType = typename UuidIdentifiableObject<BaseT>::Uuid

Definition at line 328 of file uuid_identifiable_object.h.

◆ VariantType

template<typename VariantT, UuidIdentifiable BaseT>
using zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::VariantType = VariantT

Definition at line 329 of file uuid_identifiable_object.h.

Constructor & Destructor Documentation

◆ OwningObjectRegistry()

template<typename VariantT, UuidIdentifiable BaseT>
zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::OwningObjectRegistry ( QObject * parent = nullptr)
inline

Definition at line 332 of file uuid_identifiable_object.h.

Member Function Documentation

◆ acquire_reference()

template<typename VariantT, UuidIdentifiable BaseT>
void zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::acquire_reference ( const UuidType & id)
inline

Definition at line 471 of file uuid_identifiable_object.h.

◆ clone_object()

template<typename VariantT, UuidIdentifiable BaseT>
template<typename CreateType, typename... Args>
requires std::derived_from<CreateType, BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::clone_object ( const CreateType & other,
Args &&... args )->UuidReference< OwningObjectRegistry >
inline

Definition at line 362 of file uuid_identifiable_object.h.

◆ contains()

template<typename VariantT, UuidIdentifiable BaseT>
bool zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::contains ( const UuidType & id) const
inline

Definition at line 422 of file uuid_identifiable_object.h.

◆ create_object()

template<typename VariantT, UuidIdentifiable BaseT>
template<typename CreateType, typename... Args>
requires std::derived_from<CreateType, BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::create_object ( Args &&... args) ->UuidReference< OwningObjectRegistry >
inline

Definition at line 347 of file uuid_identifiable_object.h.

◆ find_by_id()

template<typename VariantT, UuidIdentifiable BaseT>
std::optional< VariantT > zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::find_by_id ( const UuidType & id) const
inlinenoexcept

Returns an object by id.

Returns
A non-owning pointer to the object.

Definition at line 395 of file uuid_identifiable_object.h.

◆ find_by_id_as_base_or_throw()

template<typename VariantT, UuidIdentifiable BaseT>
BaseT * zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::find_by_id_as_base_or_throw ( const UuidType & id) const
inline

Definition at line 416 of file uuid_identifiable_object.h.

◆ find_by_id_or_throw()

template<typename VariantT, UuidIdentifiable BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::find_by_id_or_throw ( const UuidType & id) const
inline

Definition at line 405 of file uuid_identifiable_object.h.

◆ get_hash_map()

template<typename VariantT, UuidIdentifiable BaseT>
auto & zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::get_hash_map ( ) const
inline

Definition at line 488 of file uuid_identifiable_object.h.

◆ get_iterator_for_id() [1/2]

template<typename VariantT, UuidIdentifiable BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::get_iterator_for_id ( const UuidType & id)
inline

Definition at line 382 of file uuid_identifiable_object.h.

◆ get_iterator_for_id() [2/2]

template<typename VariantT, UuidIdentifiable BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::get_iterator_for_id ( const UuidType & id) const
inline

Definition at line 374 of file uuid_identifiable_object.h.

◆ get_uuids()

template<typename VariantT, UuidIdentifiable BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::get_uuids ( ) const
inline

Returns a list of all UUIDs of the objects in the registry.

Definition at line 493 of file uuid_identifiable_object.h.

◆ reference_count()

template<typename VariantT, UuidIdentifiable BaseT>
auto zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::reference_count ( const UuidType & id) const
inline

Returns the reference count of an object.

Mainly intended for debugging.

Definition at line 464 of file uuid_identifiable_object.h.

◆ register_object() [1/2]

template<typename VariantT, UuidIdentifiable BaseT>
template<typename ObjectT>
requires std::derived_from<ObjectT, BaseT>
void zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::register_object ( ObjectT & obj)
inline

Definition at line 453 of file uuid_identifiable_object.h.

◆ register_object() [2/2]

template<typename VariantT, UuidIdentifiable BaseT>
void zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::register_object ( VariantT obj_ptr)
inline

Registers an object.

This takes ownership of the object.

Definition at line 434 of file uuid_identifiable_object.h.

◆ release_reference()

template<typename VariantT, UuidIdentifiable BaseT>
void zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::release_reference ( const UuidType & id)
inline

Definition at line 478 of file uuid_identifiable_object.h.

◆ size()

template<typename VariantT, UuidIdentifiable BaseT>
size_t zrythm::utils::OwningObjectRegistry< VariantT, BaseT >::size ( ) const
inline

Definition at line 500 of file uuid_identifiable_object.h.

◆ from_json_with_builder

template<typename VariantT, UuidIdentifiable BaseT>
template<ObjectBuilder BuilderT>
void from_json_with_builder ( const nlohmann::json & j,
OwningObjectRegistry< VariantT, BaseT > & obj,
const BuilderT & builder )
friend

Definition at line 517 of file uuid_identifiable_object.h.

◆ to_json

template<typename VariantT, UuidIdentifiable BaseT>
void to_json ( nlohmann::json & j,
const OwningObjectRegistry< VariantT, BaseT > & obj )
friend

Definition at line 507 of file uuid_identifiable_object.h.


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