MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Nodes::HookList Class Reference

Stores, fires and clears the hooks of one node channel. More...

#include <NodeUtils.hpp>

+ Collaboration diagram for MayaFlux::Nodes::HookList:

Classes

struct  Retired
 
class  Snapshot
 The entries of a list at one instant, kept alive while this object exists. More...
 

Public Member Functions

HookId add (NodeHook hook, const std::type_info &key, uint8_t tag=0, std::array< double, 2 > params={})
 Appends a hook with no duplicate check and returns its id.
 
HookId add_conditional (NodeHook hook, NodeCondition condition, const std::type_info &key, uint8_t tag=0)
 Appends a hook that fires only while condition holds.
 
HookId add_conditional_unique (NodeHook hook, NodeCondition condition, const std::type_info &key, uint8_t tag=0)
 As add_conditional, returning the existing id when the same hook and condition types exist.
 
HookId add_unique (NodeHook hook, const std::type_info &key, uint8_t tag=0, std::array< double, 2 > params={})
 Appends unless an entry with the same key and params exists, in which case that entry's id is returned.
 
void clear ()
 
bool empty () const
 
void fire (NodeContext &ctx) const
 Calls every entry whose condition, if any, holds.
 
 HookList (const HookList &)=delete
 
 HookList (HookList &&)=delete
 
 HookList (Node &owner)
 
HookList & operator= (const HookList &)=delete
 
HookList & operator= (HookList &&)=delete
 
bool remove (HookId id)
 Removes the registration with this id.
 
bool remove_by_condition_key (const std::type_info &key)
 Removes every entry whose condition has this callable type.
 
bool remove_by_key (const std::type_info &key)
 Removes every entry registered with this callable type.
 
bool remove_by_tag (uint8_t tag)
 Removes every entry carrying this tag.
 
bool remove_first_by_key (const std::type_info &key)
 Removes the first entry registered with this callable type.
 
size_t size () const
 
Snapshot snapshot () const
 The current entries, held stable for the lifetime of the returned object.
 
 ~HookList ()
 

Private Member Functions

bool mutate (const std::function< bool(std::vector< HookEntry > &)> &edit)
 
HookId next_id () const
 
void reclaim ()
 
void retire (const std::vector< HookEntry > *old)
 

Private Attributes

std::atomic< const std::vector< HookEntry > * > m_head { nullptr }
 
Node * m_owner
 
std::atomic< uint32_t > m_readers { 0 }
 
std::atomic< Retired * > m_retired { nullptr }
 

Detailed Description

Stores, fires and clears the hooks of one node channel.

A HookList registers itself with the Node that owns it, so Node::remove_all_hooks and Node::unhook reach every list without any node class overriding them. Ids are unique within the owning node.

Reading and writing are safe across threads without locks. The entries are an immutable snapshot that writers replace with a compare-exchange, so fire() and snapshot() never block and a hook may add or remove hooks, including itself, while it runs. A fire in progress finishes over the entries it started with. Replaced snapshots are freed once no reader holds one.

Definition at line 93 of file NodeUtils.hpp.


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