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< std::reference_wrapper< const VariantT > > find_by_id (const UuidType &id) const
 Returns an object by id.
 
auto & find_by_id_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)
 
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
Object registration and deregistration 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 276 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 281 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 279 of file uuid_identifiable_object.h.

◆ VariantType

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

Definition at line 280 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 283 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 393 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 310 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 359 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 287 of file uuid_identifiable_object.h.

◆ find_by_id()

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

Returns an object by id.

Returns
A non-owning pointer to the object.

Definition at line 338 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 348 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 408 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 326 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 320 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 413 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 387 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 370 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 399 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 421 of file uuid_identifiable_object.h.

Friends And Related Symbol Documentation

◆ 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 433 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 423 of file uuid_identifiable_object.h.


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