Control Surface  1.2.0
MIDI Control Surface library for Arduino
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
UpdatableCRTP< Derived, ThreadSafe > Class Template Reference

A super class for object that have to be updated regularly. More...

#include <AH/Containers/Updatable.hpp>

+ Inheritance diagram for UpdatableCRTP< Derived, ThreadSafe >:
+ Collaboration diagram for UpdatableCRTP< Derived, ThreadSafe >:

Public Types

using Mutex = typename std::conditional< ThreadSafe, DefaultMutEx, EmptyMutex >::type
 
using LockGuard = typename std::conditional< ThreadSafe, DefaultLockGuard< Mutex >, EmptyLockGuard< Mutex > >::type
 

Public Member Functions

virtual ~UpdatableCRTP () __attribute__((no_sanitize("undefined")))
 Destructor: remove the updatable from the linked list of instances. More...
 

Static Public Member Functions

static MutexgetMutex ()
 

Protected Member Functions

 UpdatableCRTP () __attribute__((no_sanitize("undefined")))
 Constructor: create an Updatable and add it to the linked list of instances. More...
 

Protected Attributes

Derived * next
 
Derived * previous
 

Static Protected Attributes

static DoublyLinkedList< Derived > updatables
 
static Mutex mutex
 

Main initialization and updating methods

template<class... Args>
static void applyToAll (const LockGuard &, void(Derived::*method)(Args &&...), Args &&... args)
 
template<class... Args>
static void applyToAll (void(Derived::*method)(Args &&...), Args &&... args)
 

Enabling and disabling updatables

void enable (const LockGuard &lock)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
void enable ()
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
void disable (const LockGuard &lock)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
void disable ()
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
bool isEnabled (const LockGuard &) const
 Check if this updatable is enabled. More...
 
bool isEnabled ()
 Check if this updatable is enabled. More...
 
void moveDown (const LockGuard &)
 Move down this element in the list. More...
 
void moveDown ()
 Move down this element in the list. More...
 
static void enable (UpdatableCRTP *element)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
static void enable (UpdatableCRTP &element)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
template<class U , size_t N>
static void enable (U(&array)[N])
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
static void disable (UpdatableCRTP *element)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
static void disable (UpdatableCRTP &element)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
template<class U , size_t N>
static void disable (U(&array)[N])
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 

Detailed Description

template<class Derived, bool ThreadSafe = false>
class AH::UpdatableCRTP< Derived, ThreadSafe >

A super class for object that have to be updated regularly.

All instances of this class are kept in a linked list, so it's easy to iterate over all of them to update them.

This version uses static polymorphism using the Curiously Recurring Template Pattern. This requires less virtual function calls.
(Only the destructor is virtual.)

Definition at line 33 of file Updatable.hpp.

Member Typedef Documentation

◆ Mutex

using Mutex = typename std::conditional<ThreadSafe, DefaultMutEx, EmptyMutex>::type

Definition at line 36 of file Updatable.hpp.

◆ LockGuard

using LockGuard = typename std::conditional<ThreadSafe, DefaultLockGuard<Mutex>, EmptyLockGuard<Mutex> >::type

Definition at line 38 of file Updatable.hpp.

Constructor & Destructor Documentation

◆ UpdatableCRTP()

UpdatableCRTP ( )
inlineprotected

Constructor: create an Updatable and add it to the linked list of instances.

Definition at line 61 of file Updatable.hpp.

◆ ~UpdatableCRTP()

virtual ~UpdatableCRTP ( )
inlinevirtual

Destructor: remove the updatable from the linked list of instances.

Definition at line 68 of file Updatable.hpp.

Member Function Documentation

◆ getMutex()

static Mutex& getMutex ( )
inlinestatic

Definition at line 79 of file Updatable.hpp.

◆ applyToAll() [1/2]

static void applyToAll ( const LockGuard ,
void(Derived::*)(Args &&...)  method,
Args &&...  args 
)
inlinestatic

Definition at line 85 of file Updatable.hpp.

◆ applyToAll() [2/2]

static void applyToAll ( void(Derived::*)(Args &&...)  method,
Args &&...  args 
)
inlinestatic

Definition at line 93 of file Updatable.hpp.

◆ enable() [1/5]

void enable ( const LockGuard lock)
inline

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 106 of file Updatable.hpp.

◆ enable() [2/5]

void enable ( )
inline

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 115 of file Updatable.hpp.

◆ disable() [1/5]

void disable ( const LockGuard lock)
inline

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 119 of file Updatable.hpp.

◆ disable() [2/5]

void disable ( )
inline

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 128 of file Updatable.hpp.

◆ isEnabled() [1/2]

bool isEnabled ( const LockGuard ) const
inline

Check if this updatable is enabled.

Note
Assumes that the updatable is not added to a different linked list by the user.

Definition at line 136 of file Updatable.hpp.

◆ isEnabled() [2/2]

bool isEnabled ( )
inline

Check if this updatable is enabled.

Note
Assumes that the updatable is not added to a different linked list by the user.

Definition at line 141 of file Updatable.hpp.

◆ enable() [3/5]

static void enable ( UpdatableCRTP< Derived, ThreadSafe > *  element)
inlinestatic

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 144 of file Updatable.hpp.

◆ enable() [4/5]

static void enable ( UpdatableCRTP< Derived, ThreadSafe > &  element)
inlinestatic

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 146 of file Updatable.hpp.

◆ enable() [5/5]

static void enable ( U(&)  array[N])
inlinestatic

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 149 of file Updatable.hpp.

◆ disable() [3/5]

static void disable ( UpdatableCRTP< Derived, ThreadSafe > *  element)
inlinestatic

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 155 of file Updatable.hpp.

◆ disable() [4/5]

static void disable ( UpdatableCRTP< Derived, ThreadSafe > &  element)
inlinestatic

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 157 of file Updatable.hpp.

◆ disable() [5/5]

static void disable ( U(&)  array[N])
inlinestatic

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 160 of file Updatable.hpp.

◆ moveDown() [1/2]

void moveDown ( const LockGuard )
inline

Move down this element in the list.

Definition at line 166 of file Updatable.hpp.

◆ moveDown() [2/2]

void moveDown ( )
inline

Move down this element in the list.

Definition at line 168 of file Updatable.hpp.

Member Data Documentation

◆ updatables

DoublyLinkedList< Derived > updatables
staticprotected

Definition at line 173 of file Updatable.hpp.

◆ mutex

UpdatableCRTP< Derived, ThreadSafe >::Mutex mutex
staticprotected

Definition at line 174 of file Updatable.hpp.

◆ next

Derived * next
protectedinherited

Definition at line 323 of file LinkedList.hpp.

◆ previous

Derived * previous
protectedinherited

Definition at line 324 of file LinkedList.hpp.


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