Blender V5.3
blender::AnyDerived< Base, InlineBufferCapacity > Struct Template Reference

#include <BLI_any_derived.hh>

Public Member Functions

 AnyDerived ()=default
 AnyDerived (const AnyDerived &other)
 AnyDerived (AnyDerived &&other) noexcept
 AnyDerived (Base *impl)
 AnyDerived (std::shared_ptr< Base > impl)
AnyDerived & operator= (const AnyDerived &other)
AnyDerived & operator= (AnyDerived &&other) noexcept
template<typename ImplT, typename... Args>
requires std::is_base_of_v<Base, ImplT>
void emplace (Args &&...args)
 operator bool () const
Base & operator* () const
Base * operator-> () const
Base * get () const

Protected Member Functions

Base * impl_from_storage () const

Detailed Description

template<typename Base, int64_t InlineBufferCapacity = 24>
struct blender::AnyDerived< Base, InlineBufferCapacity >

This allows storing or passing around derived classes of a common base class. Typically, this always requires allocating the value on the heap and passing it around e.g. as unique_ptr. AnyDerived has small buffer optimization. So if the type is small, it can be stored directly without an additional allocation.

If all derived types are known where the type is used, it can be more efficient to use std::variant<Derived1, Derived2, ...> instead. AnyDerived uses type erasure through the use of Any and therefore works even when not all used derived types are known.

This is used extensively for virtual arrays. Each type of virtual array is implemented as subclass of VArrayImpl while VArray actually stores a specific implementation.

Note: If the value is not stored inline, it's currently stored as a shared_ptr which is shared when the AnyDerived is copied. This behavior is fine and efficient for all current uses but it may need to be generalized if AnyDerived is supposed to be used in more places.

Definition at line 70 of file BLI_any_derived.hh.

Constructor & Destructor Documentation

◆ AnyDerived() [1/5]

template<typename Base, int64_t InlineBufferCapacity = 24>
blender::AnyDerived< Base, InlineBufferCapacity >::AnyDerived ( )
default

◆ AnyDerived() [2/5]

template<typename Base, int64_t InlineBufferCapacity = 24>
blender::AnyDerived< Base, InlineBufferCapacity >::AnyDerived ( const AnyDerived< Base, InlineBufferCapacity > & other)
inline

Definition at line 88 of file BLI_any_derived.hh.

References AnyDerived(), and impl_from_storage().

◆ AnyDerived() [3/5]

template<typename Base, int64_t InlineBufferCapacity = 24>
blender::AnyDerived< Base, InlineBufferCapacity >::AnyDerived ( AnyDerived< Base, InlineBufferCapacity > && other)
inlinenoexcept

Definition at line 93 of file BLI_any_derived.hh.

References AnyDerived(), and impl_from_storage().

◆ AnyDerived() [4/5]

template<typename Base, int64_t InlineBufferCapacity = 24>
blender::AnyDerived< Base, InlineBufferCapacity >::AnyDerived ( Base * impl)
inlineexplicit

Definition at line 100 of file BLI_any_derived.hh.

◆ AnyDerived() [5/5]

template<typename Base, int64_t InlineBufferCapacity = 24>
blender::AnyDerived< Base, InlineBufferCapacity >::AnyDerived ( std::shared_ptr< Base > impl)
inlineexplicit

Definition at line 105 of file BLI_any_derived.hh.

References get().

Member Function Documentation

◆ emplace()

template<typename Base, int64_t InlineBufferCapacity = 24>
template<typename ImplT, typename... Args>
requires std::is_base_of_v<Base, ImplT>
void blender::AnyDerived< Base, InlineBufferCapacity >::emplace ( Args &&... args)
inline

Definition at line 136 of file BLI_any_derived.hh.

References emplace().

Referenced by emplace(), blender::tests::TEST(), blender::tests::TEST(), and blender::tests::TEST().

◆ get()

template<typename Base, int64_t InlineBufferCapacity = 24>
Base * blender::AnyDerived< Base, InlineBufferCapacity >::get ( ) const
inline

◆ impl_from_storage()

template<typename Base, int64_t InlineBufferCapacity = 24>
Base * blender::AnyDerived< Base, InlineBufferCapacity >::impl_from_storage ( ) const
inlineprotected

Definition at line 173 of file BLI_any_derived.hh.

Referenced by AnyDerived(), AnyDerived(), operator=(), and operator=().

◆ operator bool()

template<typename Base, int64_t InlineBufferCapacity = 24>
blender::AnyDerived< Base, InlineBufferCapacity >::operator bool ( ) const
inline

Definition at line 152 of file BLI_any_derived.hh.

◆ operator*()

template<typename Base, int64_t InlineBufferCapacity = 24>
Base & blender::AnyDerived< Base, InlineBufferCapacity >::operator* ( ) const
inline

Definition at line 157 of file BLI_any_derived.hh.

◆ operator->()

template<typename Base, int64_t InlineBufferCapacity = 24>
Base * blender::AnyDerived< Base, InlineBufferCapacity >::operator-> ( ) const
inline

Definition at line 162 of file BLI_any_derived.hh.

◆ operator=() [1/2]

template<typename Base, int64_t InlineBufferCapacity = 24>
AnyDerived & blender::AnyDerived< Base, InlineBufferCapacity >::operator= ( AnyDerived< Base, InlineBufferCapacity > && other)
inlinenoexcept

Definition at line 122 of file BLI_any_derived.hh.

References AnyDerived(), and impl_from_storage().

◆ operator=() [2/2]

template<typename Base, int64_t InlineBufferCapacity = 24>
AnyDerived & blender::AnyDerived< Base, InlineBufferCapacity >::operator= ( const AnyDerived< Base, InlineBufferCapacity > & other)
inline

Definition at line 112 of file BLI_any_derived.hh.

References AnyDerived(), and impl_from_storage().


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