Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils Namespace Reference

String utilities. More...

Namespaces

namespace  compression
 Compression utilities.
namespace  exceptions
 Exception handling utilities.
namespace  math
 Math utils.
namespace  version_keys
 Key constants for version JSON serialization.

Data Structures

class  AppSettings
class  AudioFileWriter
class  Backtrace
class  ConstBidirectionalMap
 A read-only bidirectional map that maintains key-value and value-key mappings. More...
class  Color
class  Debouncer
 Generic debouncer that delays execution of a callback until a specified time period has elapsed without the debounce being called again. More...
class  ExpandableTickRange
class  FilePathList
class  IObjectRegistry
 Abstract interface for a UUID-keyed object registry. More...
class  ISettingsBackend
 Interface for an app settings provider. More...
class  MonotonicTimeProvider
class  QElapsedTimeProvider
class  ObjectRegistry
 Concrete IObjectRegistry with QObject parent-child ownership and reference counting. More...
struct  OptionalRef
 Wrapper around std::optional<std::reference_wrapper<T>> that provides a more convenient API. More...
class  PlaybackCacheScheduler
 Cache request handler for a tick range, with built-in debouncing and expanding of the range. More...
class  QSettingsBackend
 Interface for an app settings provider. More...
class  QObjectUniquePtr
 A unique pointer for QObject objects that also works with QObject-based ownership. More...
struct  is_derived_from_template
struct  dependent_false
struct  remove_smart_pointer
struct  remove_smart_pointer< std::unique_ptr< T, Deleter > >
struct  remove_smart_pointer< std::shared_ptr< T > >
struct  remove_smart_pointer< std::weak_ptr< T > >
struct  is_unique_ptr
struct  is_unique_ptr< std::unique_ptr< T > >
struct  is_shared_ptr
struct  is_shared_ptr< std::shared_ptr< T > >
class  TypedUuidReference
 Typed, reference-counted UUID reference into an IObjectRegistry. More...
class  Utf8String
 Lightweight UTF-8 string wrapper with safe conversions. More...
class  CStringRAII
 C string RAII wrapper. More...
class  UuidIdentifiableBase
 QObject-based base for all UUID-identifiable objects. More...
class  UuidIdentifiableObject
 CRTP base that adds a typed UUID strong-typedef to a class hierarchy. More...
class  UuidReference
 Untyped, reference-counted UUID reference into an IObjectRegistry. More...
struct  is_in_variant
struct  is_in_variant< T, std::variant< Ts... >, std::void_t< decltype(std::variant< Ts... >())> >
struct  merge_variants
struct  merge_variants< Variant >
struct  merge_variants< std::variant< Types1... >, std::variant< Types2... >, Rest... >
struct  to_reference_variant_impl
 Helper struct to convert a variant to a variant of references. More...
struct  to_reference_variant_impl< std::variant< Ts... > >
 Specialization for std::variant. More...
struct  to_const_reference_variant_impl
struct  to_const_reference_variant_impl< std::variant< Ts... > >
struct  to_unique_ptr_variant_impl
 Helper struct to convert a variant to a variant of unique_ptr's. More...
struct  to_unique_ptr_variant_impl< std::variant< Ts... > >
 Specialization for std::variant. More...
struct  to_pointer_variant_impl
 Helper struct to convert a variant to a variant of pointers. More...
struct  to_pointer_variant_impl< std::variant< Ts... > >
 Specialization for std::variant. More...
struct  overload
 Overload pattern. More...
struct  wrap_variant_impl
 Helper struct to convert a variant to a variant of ArrangerObjectOwner<T>. More...
struct  wrap_variant_impl< std::variant< Ts... >, Wrapper >
 Specialization for std::variant. More...
struct  Version
 Represents a semantic version with major, minor, and optional patch. More...
class  TestObject
 Simple QObject test object with a name, for testing UuidReference and TypedUuidReference. More...
class  DerivedTestObject
class  MockObjectRegistry
 Mock IObjectRegistry for testing reference behavior in isolation. More...
class  ContainerTestObject
 Test object that holds a TypedUuidReference to another object. More...

Concepts

concept  CloneableObject
 Concept that checks if a type is cloneable.
concept  CloneableDefaultInitializableObject
 Concept that checks if a type is cloneable.
concept  InheritsFromBase
 Concept to check if a type inherits from a base class.
concept  AllInheritFromBase
 Concept to ensure all types in a variant inherit from a base class.
concept  QObjectDerived
concept  ContainerType
concept  FinalClass
concept  CompleteType
concept  IsRawPointer
concept  StdVariant
concept  VariantOfPointers
concept  OptionalType
concept  StrongTypedef
concept  StdArray
concept  SmartPtr
concept  DerivedButNotBase
concept  DerivedFromCRTPBase
concept  RangeOf
concept  ObjectBuilder
 Concept that checks if a type is a builder for objects.
concept  EnumType
concept  UuidIdentifiable
 Concept: T has a UUID identity from a UuidIdentifiableObject hierarchy.
concept  IsInVariant

Typedefs

using MonotonicTime = qint64
template<typename... Ts>
using dependent_false_t = typename dependent_false<Ts...>::type
template<typename T>
using remove_smart_pointer_t = typename remove_smart_pointer<T>::type
template<typename T>
using base_type
 An improved version of std::decay_t that also removes raw and smart pointers.
template<typename... Variants>
using merge_variants_t = typename merge_variants<Variants...>::type
template<typename Variant>
using to_reference_variant = typename to_reference_variant_impl<Variant>::type
 Converts a variant to a variant of reference_wrappers.
template<typename Variant>
using to_const_reference_variant
template<typename Variant>
using to_unique_ptr_variant = typename to_unique_ptr_variant_impl<Variant>::type
 Converts a variant to a variant of reference_wrappers.
template<typename Variant>
using to_pointer_variant = typename to_pointer_variant_impl<Variant>::type
 Converts a variant to a variant of pointers.
template<typename Variant, template< typename > class Wrapper>
using wrap_variant_t = typename wrap_variant_impl<Variant, Wrapper>::type
 Converts a variant to a variant where each type is wrapped by Wrapper<T>.

Enumerations

enum class  ObjectCloneType { Snapshot , NewIdentity }
enum class  LoggerType { GUI , Test }
enum class  LogLevel {
  Trace = 0 , Debug = 1 , Info = 2 , Warning = 3 ,
  Error = 4 , Critical = 5
}

Functions

auto format_as (const ExpandableTickRange &range) -> std::string
template<CloneableObject Derived, typename... Args>
std::unique_ptr< Derived > clone_unique (const Derived &obj, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args)
template<CloneableObject Derived, typename... Args>
std::shared_ptr< Derived > clone_shared (const Derived &obj, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args)
template<CloneableObject Derived, typename... Args>
Derived * clone_raw_ptr (const Derived &obj, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args)
template<CloneableObject Derived, typename... Args>
requires utils::QObjectDerived<Derived>
Derived * clone_qobject (const Derived &obj, QObject *parent, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args)
template<CloneableObject Derived, typename... Args>
requires utils::QObjectDerived<Derived>
utils::QObjectUniquePtr< Derived > clone_unique_qobject (const Derived &obj, QObject *parent, ObjectCloneType clone_type=ObjectCloneType::Snapshot, Args &&... args)
template<typename T, std::size_t N>
void clone_unique_ptr_array (std::array< std::unique_ptr< T >, N > &dest, const std::array< std::unique_ptr< T >, N > &src, ObjectCloneType clone_type=ObjectCloneType::Snapshot)
 Clones the elements of a std::array of std::unique_ptr into the destination array.
template<typename T, template< typename... > class Ptr>
void clone_ptr_vector (std::vector< Ptr< T > > &dest, const std::vector< Ptr< T > > &src, ObjectCloneType clone_type=ObjectCloneType::Snapshot)
 Clones the elements of a std::vector of std::unique_ptr or std::shared_ptr into the destination vector.
template<typename Container>
void clone_unique_ptr_container (Container &dest, const Container &src, ObjectCloneType clone_type=ObjectCloneType::Snapshot)
 Clones the elements of a container of std::unique_ptr into the destination container.
template<typename Container, typename Variant, typename Base>
void clone_variant_container (Container &dest, const Container &src, ObjectCloneType clone_type=ObjectCloneType::Snapshot)
template<typename Variant, typename Container>
void clone_variant_container (Container &dest, const Container &src, ObjectCloneType clone_type=ObjectCloneType::Snapshot)
 Clones a container of variants.
void init_logging (LoggerType type)
bool is_logging_initialized ()
std::vector< Utf8Stringget_last_log_entries (size_t count)
std::filesystem::path get_log_file_path ()
template<typename... Args>
void log_trace (std::source_location loc, fmt::format_string< Args... > fmt, Args &&... args)
template<typename... Args>
void log_debug (std::source_location loc, fmt::format_string< Args... > fmt, Args &&... args)
template<typename... Args>
void log_info (std::source_location loc, fmt::format_string< Args... > fmt, Args &&... args)
template<typename... Args>
void log_warning (std::source_location loc, fmt::format_string< Args... > fmt, Args &&... args)
template<typename... Args>
void log_error (std::source_location loc, fmt::format_string< Args... > fmt, Args &&... args)
template<typename... Args>
void log_critical (std::source_location loc, fmt::format_string< Args... > fmt, Args &&... args)
template<class T>
constexpr bool values_equal_for_qproperty_type (const T &a, const T &b)
 Helper that checks if 2 values are equal.
template<typename T, typename... Args>
QObjectUniquePtr< T > make_qobject_unique (Args &&... args)
template<UuidIdentifiable T, typename... Args>
auto create_object (IObjectRegistry &registry, Args &&... args)
template<UuidIdentifiable T>
auto clone_object (const T &source, IObjectRegistry &registry, ObjectCloneType clone_type, auto &&... extra_args)
template<UuidIdentifiable T>
T & get_typed (IObjectRegistry &registry, const typename UuidIdentifiableObject< T >::Uuid &id)
template<UuidType T>
bool contains (IObjectRegistry &registry, const T &id)
std::string get_current_thread_name ()
 Returns the name of the current thread as set by the OS or threading library.
template<typename Variant, typename Base>
auto convert_to_variant (const Base *base_ptr) -> Variant
 Converts a base pointer to a variant of pointers using dynamic_cast.
template<typename Variant, typename Base>
auto convert_to_variant_qobj (const Base *base_ptr) -> Variant
 Converts a QObject base pointer to a variant of pointers using qobject_cast.
void to_json (nlohmann::json &j, const Version &v)
void from_json (const nlohmann::json &j, Version &v)

Variables

template<template< typename... > class BaseTemplateT, typename DerivedT>
constexpr bool is_derived_from_template_v
template<typename... Ts>
constexpr auto dependent_false_v = dependent_false<Ts...>::value
template<typename T>
constexpr bool is_unique_ptr_v = is_unique_ptr<T>::value
template<typename T>
constexpr bool is_shared_ptr_v = is_shared_ptr<T>::value

Detailed Description

String utilities.

Typedef Documentation

◆ base_type

template<typename T>
using zrythm::utils::base_type
Initial value:
std::remove_cvref_t<
remove_smart_pointer_t<std::remove_pointer_t<std::decay_t<T>>>>

An improved version of std::decay_t that also removes raw and smart pointers.

Definition at line 156 of file traits.h.

◆ dependent_false_t

template<typename... Ts>
using zrythm::utils::dependent_false_t = typename dependent_false<Ts...>::type

Definition at line 77 of file traits.h.

◆ merge_variants_t

template<typename... Variants>
using zrythm::utils::merge_variants_t = typename merge_variants<Variants...>::type

Definition at line 48 of file variant_helpers.h.

◆ MonotonicTime

using zrythm::utils::MonotonicTime = qint64

Definition at line 10 of file monotonic_time_provider.h.

◆ remove_smart_pointer_t

template<typename T>
using zrythm::utils::remove_smart_pointer_t = typename remove_smart_pointer<T>::type

Definition at line 151 of file traits.h.

◆ to_const_reference_variant

template<typename Variant>
using zrythm::utils::to_const_reference_variant

◆ to_pointer_variant

template<typename Variant>
using zrythm::utils::to_pointer_variant = typename to_pointer_variant_impl<Variant>::type

Converts a variant to a variant of pointers.

Template Parameters
VariantThe original variant type

Definition at line 130 of file variant_helpers.h.

◆ to_reference_variant

template<typename Variant>
using zrythm::utils::to_reference_variant = typename to_reference_variant_impl<Variant>::type

Converts a variant to a variant of reference_wrappers.

Template Parameters
VariantThe original variant type

Definition at line 85 of file variant_helpers.h.

◆ to_unique_ptr_variant

template<typename Variant>
using zrythm::utils::to_unique_ptr_variant = typename to_unique_ptr_variant_impl<Variant>::type

Converts a variant to a variant of reference_wrappers.

Template Parameters
VariantThe original variant type

Definition at line 113 of file variant_helpers.h.

◆ wrap_variant_t

template<typename Variant, template< typename > class Wrapper>
using zrythm::utils::wrap_variant_t = typename wrap_variant_impl<Variant, Wrapper>::type

Converts a variant to a variant where each type is wrapped by Wrapper<T>.

Template Parameters
VariantThe original variant type
WrapperThe template class to wrap each type with

Definition at line 240 of file variant_helpers.h.

Enumeration Type Documentation

◆ LoggerType

enum class zrythm::utils::LoggerType
strong

Definition at line 33 of file logger.h.

◆ LogLevel

enum class zrythm::utils::LogLevel
strong

Definition at line 39 of file logger.h.

◆ ObjectCloneType

enum class zrythm::utils::ObjectCloneType
strong
Enumerator
Snapshot 

Creates a snapshot of the object with the same identity.

NewIdentity 

Creates a separately identified object.

To be used only when duplicating objects as part of a user action.

Definition at line 18 of file icloneable.h.

Function Documentation

◆ clone_object()

template<UuidIdentifiable T>
auto zrythm::utils::clone_object ( const T & source,
IObjectRegistry & registry,
ObjectCloneType clone_type,
auto &&... extra_args )
nodiscard

Definition at line 26 of file registry_utils.h.

◆ clone_ptr_vector()

template<typename T, template< typename... > class Ptr>
void zrythm::utils::clone_ptr_vector ( std::vector< Ptr< T > > & dest,
const std::vector< Ptr< T > > & src,
ObjectCloneType clone_type = ObjectCloneType::Snapshot )

Clones the elements of a std::vector of std::unique_ptr or std::shared_ptr into the destination vector.

Template Parameters
TThe type of the elements in the vector.
PtrThe pointer type (std::unique_ptr or std::shared_ptr).
Parameters
destThe destination vector to clone into.
srcThe source vector to clone from.

Definition at line 178 of file icloneable.h.

◆ clone_qobject()

template<CloneableObject Derived, typename... Args>
requires utils::QObjectDerived<Derived>
Derived * zrythm::utils::clone_qobject ( const Derived & obj,
QObject * parent,
ObjectCloneType clone_type = ObjectCloneType::Snapshot,
Args &&... args )

Definition at line 82 of file icloneable.h.

◆ clone_raw_ptr()

template<CloneableObject Derived, typename... Args>
Derived * zrythm::utils::clone_raw_ptr ( const Derived & obj,
ObjectCloneType clone_type = ObjectCloneType::Snapshot,
Args &&... args )

Definition at line 71 of file icloneable.h.

◆ clone_shared()

template<CloneableObject Derived, typename... Args>
std::shared_ptr< Derived > zrythm::utils::clone_shared ( const Derived & obj,
ObjectCloneType clone_type = ObjectCloneType::Snapshot,
Args &&... args )

Definition at line 58 of file icloneable.h.

◆ clone_unique()

template<CloneableObject Derived, typename... Args>
std::unique_ptr< Derived > zrythm::utils::clone_unique ( const Derived & obj,
ObjectCloneType clone_type = ObjectCloneType::Snapshot,
Args &&... args )

Definition at line 45 of file icloneable.h.

◆ clone_unique_ptr_array()

template<typename T, std::size_t N>
void zrythm::utils::clone_unique_ptr_array ( std::array< std::unique_ptr< T >, N > & dest,
const std::array< std::unique_ptr< T >, N > & src,
ObjectCloneType clone_type = ObjectCloneType::Snapshot )

Clones the elements of a std::array of std::unique_ptr into the destination array.

Template Parameters
TThe type of the elements in the array.
NThe size of the array.
Parameters
destThe destination array to clone into.
srcThe source array to clone from.

Definition at line 142 of file icloneable.h.

◆ clone_unique_ptr_container()

template<typename Container>
void zrythm::utils::clone_unique_ptr_container ( Container & dest,
const Container & src,
ObjectCloneType clone_type = ObjectCloneType::Snapshot )

Clones the elements of a container of std::unique_ptr into the destination container.

Template Parameters
ContainerThe type of the container.
Parameters
destThe destination container to clone into.
srcThe source container to clone from.

Definition at line 231 of file icloneable.h.

◆ clone_unique_qobject()

template<CloneableObject Derived, typename... Args>
requires utils::QObjectDerived<Derived>
utils::QObjectUniquePtr< Derived > zrythm::utils::clone_unique_qobject ( const Derived & obj,
QObject * parent,
ObjectCloneType clone_type = ObjectCloneType::Snapshot,
Args &&... args )

Definition at line 99 of file icloneable.h.

◆ clone_variant_container() [1/2]

template<typename Variant, typename Container>
void zrythm::utils::clone_variant_container ( Container & dest,
const Container & src,
ObjectCloneType clone_type = ObjectCloneType::Snapshot )

Clones a container of variants.

Template Parameters
VariantThe variant type containing possible derived classes.
ContainerThe container type (deduced automatically).

Definition at line 298 of file icloneable.h.

◆ clone_variant_container() [2/2]

template<typename Container, typename Variant, typename Base>
void zrythm::utils::clone_variant_container ( Container & dest,
const Container & src,
ObjectCloneType clone_type = ObjectCloneType::Snapshot )

Definition at line 249 of file icloneable.h.

◆ contains()

template<UuidType T>
bool zrythm::utils::contains ( IObjectRegistry & registry,
const T & id )

Definition at line 54 of file registry_utils.h.

◆ convert_to_variant()

template<typename Variant, typename Base>
auto zrythm::utils::convert_to_variant ( const Base * base_ptr) -> Variant

Converts a base pointer to a variant of pointers using dynamic_cast.

If the base pointer is null, returns a default-constructed variant (null pointer of the first alternative type). Throws if no cast succeeds.

Template Parameters
VariantA std::variant of pointer types.
BaseThe base type of the pointer.
Parameters
base_ptrThe base pointer to convert.
Returns
The converted variant type.

Definition at line 182 of file variant_helpers.h.

◆ convert_to_variant_qobj()

template<typename Variant, typename Base>
auto zrythm::utils::convert_to_variant_qobj ( const Base * base_ptr) -> Variant

Converts a QObject base pointer to a variant of pointers using qobject_cast.

If the base pointer is null, returns a default-constructed variant (null pointer of the first alternative type). Throws if no cast succeeds.

Template Parameters
VariantA std::variant of pointer types.
BaseThe base type of the pointer.
Parameters
base_ptrThe base pointer to convert.
Returns
The converted variant type.

Definition at line 199 of file variant_helpers.h.

◆ create_object()

template<UuidIdentifiable T, typename... Args>
auto zrythm::utils::create_object ( IObjectRegistry & registry,
Args &&... args )
nodiscard

Definition at line 15 of file registry_utils.h.

◆ get_current_thread_name()

std::string zrythm::utils::get_current_thread_name ( )

Returns the name of the current thread as set by the OS or threading library.

Falls back to the numeric thread ID if no name is available.

◆ get_typed()

template<UuidIdentifiable T>
T & zrythm::utils::get_typed ( IObjectRegistry & registry,
const typename UuidIdentifiableObject< T >::Uuid & id )

Definition at line 42 of file registry_utils.h.

◆ log_critical()

template<typename... Args>
void zrythm::utils::log_critical ( std::source_location loc,
fmt::format_string< Args... > fmt,
Args &&... args )

Definition at line 170 of file logger.h.

◆ log_debug()

template<typename... Args>
void zrythm::utils::log_debug ( std::source_location loc,
fmt::format_string< Args... > fmt,
Args &&... args )

Definition at line 127 of file logger.h.

◆ log_error()

template<typename... Args>
void zrythm::utils::log_error ( std::source_location loc,
fmt::format_string< Args... > fmt,
Args &&... args )

Definition at line 159 of file logger.h.

◆ log_info()

template<typename... Args>
void zrythm::utils::log_info ( std::source_location loc,
fmt::format_string< Args... > fmt,
Args &&... args )

Definition at line 138 of file logger.h.

◆ log_trace()

template<typename... Args>
void zrythm::utils::log_trace ( std::source_location loc,
fmt::format_string< Args... > fmt,
Args &&... args )

Definition at line 116 of file logger.h.

◆ log_warning()

template<typename... Args>
void zrythm::utils::log_warning ( std::source_location loc,
fmt::format_string< Args... > fmt,
Args &&... args )

Definition at line 148 of file logger.h.

◆ make_qobject_unique()

template<typename T, typename... Args>
QObjectUniquePtr< T > zrythm::utils::make_qobject_unique ( Args &&... args)

Definition at line 103 of file qt.h.

◆ values_equal_for_qproperty_type()

template<class T>
bool zrythm::utils::values_equal_for_qproperty_type ( const T & a,
const T & b )
constexpr

Helper that checks if 2 values are equal.

This is intended used in QObject property setters.

Definition at line 18 of file qt.h.

Variable Documentation

◆ dependent_false_v

template<typename... Ts>
auto zrythm::utils::dependent_false_v = dependent_false<Ts...>::value
constexpr

Definition at line 80 of file traits.h.

◆ is_derived_from_template_v

template<template< typename... > class BaseTemplateT, typename DerivedT>
bool zrythm::utils::is_derived_from_template_v
inlineconstexpr
Initial value:
=
is_derived_from_template<BaseTemplateT, DerivedT>::value

Definition at line 35 of file traits.h.

◆ is_shared_ptr_v

template<typename T>
bool zrythm::utils::is_shared_ptr_v = is_shared_ptr<T>::value
constexpr

Definition at line 187 of file traits.h.

◆ is_unique_ptr_v

template<typename T>
bool zrythm::utils::is_unique_ptr_v = is_unique_ptr<T>::value
constexpr

Definition at line 176 of file traits.h.