HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes
v1::polymorphic_optional< BaseType, Size, Alignment > Class Template Reference

#include <hikogui/container/polymorphic_optional.hpp>

Public Types

using base_type = BaseType
 
using pointer = base_type *
 
using const_pointer = base_type const *
 

Public Member Functions

constexpr polymorphic_optional (std::nullopt_t) noexcept
 
template<std::derived_from< base_type > Other>
constexpr polymorphic_optional (std::unique_ptr< Other, std::default_delete< Other > > &&other) noexcept
 
template<std::derived_from< base_type > Other>
polymorphic_optionaloperator= (std::unique_ptr< Other, std::default_delete< Other > > &&other) noexcept
 
template<std::derived_from< base_type > Other>
 polymorphic_optional (Other &&other) noexcept
 
template<std::derived_from< base_type > Other>
requires (sizeof(Other) <= capacity and alignof(Other) <= alignment)
 polymorphic_optional (Other &&other) noexcept
 
template<std::derived_from< base_type > Other>
polymorphic_optionaloperator= (Other &&other) noexcept
 
template<std::derived_from< base_type > Other>
requires (sizeof(Other) <= capacity and alignof(Other) <= alignment)
polymorphic_optionaloperator= (Other &&other) noexcept
 
bool empty (std::memory_order memory_order=std::memory_order::seq_cst) const noexcept
 
 operator bool () const noexcept
 
template<typename Value >
Value & value (std::memory_order memory_order=std::memory_order::seq_cst)
 
template<typename Value >
Value const & value (std::memory_order memory_order=std::memory_order::seq_cst) const
 
base_type * operator-> () noexcept
 
base_type const * operator-> () const noexcept
 
base_type & operator* () noexcept
 
base_type const & operator* () const noexcept
 
hi_force_inline void reset () noexcept
 Destroys the contained value, otherwise has no effect.
 
template<typename Value , typename... Args>
hi_force_inline Value & emplace (Args &&...args) noexcept
 
template<typename Func >
hi_force_inline auto invoke_and_reset (Func &&func) noexcept
 Invoke a function on the value if it exists then reset.
 
template<typename Value , typename Func , typename... Args>
hi_force_inline auto wait_emplace_and_invoke (Func &&func, Args &&...args) noexcept
 Wait until the optional is empty, emplace a value, then invoke a function on it before committing.
 

Static Public Attributes

static constexpr std::size_t capacity = Size - sizeof(std::atomic<pointer>)
 The maximum size of a value that can be placed inside the buffer of this.
 
static constexpr std::size_t alignment = Alignment
 The alignment of this.
 

Detailed Description

template<typename BaseType, std::size_t Size, std::size_t Alignment = alignof(BaseType)>
class v1::polymorphic_optional< BaseType, Size, Alignment >

Polymorphic optional.

This optional container can hold an polymorphic value.

If the assigned sub-class is larger than the internal buffer the object will be allocated on the heap.

Template Parameters
BaseTypeThe base type of the polymorphic value.
SizeTotal size of the polymorphic_optional internal storage.

Member Function Documentation

◆ invoke_and_reset()

template<typename BaseType , std::size_t Size, std::size_t Alignment = alignof(BaseType)>
template<typename Func >
hi_force_inline auto v1::polymorphic_optional< BaseType, Size, Alignment >::invoke_and_reset ( Func && func)
inlinenoexcept

Invoke a function on the value if it exists then reset.

Note
Only one thread should call this function on an object.
Parameters
funcThe function to call with the value as argument if it exists.
Returns
If empty/false the polymorphic_optional was empty, otherwise it contains the return value of the function if any.

◆ reset()

template<typename BaseType , std::size_t Size, std::size_t Alignment = alignof(BaseType)>
hi_force_inline void v1::polymorphic_optional< BaseType, Size, Alignment >::reset ( )
inlinenoexcept

Destroys the contained value, otherwise has no effect.

◆ wait_emplace_and_invoke()

template<typename BaseType , std::size_t Size, std::size_t Alignment = alignof(BaseType)>
template<typename Value , typename Func , typename... Args>
hi_force_inline auto v1::polymorphic_optional< BaseType, Size, Alignment >::wait_emplace_and_invoke ( Func && func,
Args &&... args )
inlinenoexcept

Wait until the optional is empty, emplace a value, then invoke a function on it before committing.

Template Parameters
MessageThe message type derived from value_type to be stored in a free slot.
Parameters
funcThe function to invoke on the message created on the fifo.
argsThe arguments passed to the constructor of Message.
Returns
The result of the invoked function.

Field Documentation

◆ alignment

template<typename BaseType , std::size_t Size, std::size_t Alignment = alignof(BaseType)>
constexpr std::size_t v1::polymorphic_optional< BaseType, Size, Alignment >::alignment = Alignment
staticconstexpr

The alignment of this.

◆ capacity

template<typename BaseType , std::size_t Size, std::size_t Alignment = alignof(BaseType)>
constexpr std::size_t v1::polymorphic_optional< BaseType, Size, Alignment >::capacity = Size - sizeof(std::atomic<pointer>)
staticconstexpr

The maximum size of a value that can be placed inside the buffer of this.


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