MIDI Control Surface library for Arduino
|
Go to the documentation of this file.
9 #include <AH/Containers/CRTP.hpp>
13 #include <AH/STL/type_traits>
14 #include <AH/STL/utility>
32 template <
class Derived,
bool ThreadSafe = false>
37 typename std::conditional<ThreadSafe, DefaultMutEx, EmptyMutex>::type;
39 typename std::conditional<ThreadSafe, DefaultLockGuard<Mutex>,
42 #if defined(__GNUC__) && !defined(__clang__)
43 #pragma GCC diagnostic push
44 #pragma GCC diagnostic ignored "-Wattributes"
63 updatables.append(
CRTP(Derived));
70 if (updatables.couldContain(
CRTP(Derived)))
71 updatables.remove(
CRTP(Derived));
74 #if defined(__GNUC__) && !defined(__clang__)
75 #pragma GCC diagnostic pop
84 template <
class... Args>
86 void (Derived::*method)(Args &&...),
88 for (
auto &el : updatables)
89 (el.*method)(std::forward<Args>(args)...);
92 template <
class... Args>
93 static void applyToAll(
void (Derived::*method)(Args &&...),
95 applyToAll(
LockGuard(mutex), method, std::forward<Args>(args)...);
107 if (isEnabled(lock)) {
108 ERROR(
F(
"Error: This element is already enabled."), 0x1212);
111 updatables.append(
CRTP(Derived));
120 if (!isEnabled(lock)) {
121 ERROR(
F(
"Error: This element is already disabled."), 0x1213);
124 updatables.remove(
CRTP(Derived));
137 return updatables.couldContain(
CRTP(
const Derived));
148 template <
class U,
size_t N>
159 template <
class U,
size_t N>
177 template <
class Derived,
bool ThreadSafe>
180 template <
class Derived,
bool ThreadSafe>
194 template <
class T = NormalUpdatable,
bool ThreadSafe = false>
208 static void beginAll() { Updatable::applyToAll(&Updatable::begin); }
212 static void updateAll() { Updatable::applyToAll(&Updatable::update); }
typename std::conditional< ThreadSafe, DefaultLockGuard< Mutex >, EmptyLockGuard< Mutex > >::type LockGuard
A super class for object that have to be updated regularly.
void disable()
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated aut...
virtual ~UpdatableCRTP() __attribute__((no_sanitize("undefined")))
Destructor: remove the updatable from the linked list of instances.
bool isEnabled(const LockGuard &) const
Check if this updatable is enabled.
static void updateAll()
Update all enabled instances of this class.
static Mutex & getMutex()
#define AH_DIAGNOSTIC_POP()
A super class for object that have to be updated regularly.
UpdatableCRTP() __attribute__((no_sanitize("undefined")))
Constructor: create an Updatable and add it to the linked list of instances.
static void enable(UpdatableCRTP &element)
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
static void disable(U(&array)[N])
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated aut...
virtual void begin()=0
Initialize this updatable.
#define ERROR(msg, errc)
Print the error message and error code, and stop the execution if FATAL_ERRORS are enabled.
static void enable(UpdatableCRTP *element)
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
static void beginAll()
Begin all enabled instances of this class.
void enable()
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
static void enable(U(&array)[N])
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
#define CRTP(Derived)
Helper for the Curiously Recurring Template Pattern.
bool isEnabled()
Check if this updatable is enabled.
void disable(const LockGuard &lock)
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated aut...
static void disable(UpdatableCRTP *element)
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated aut...
typename std::conditional< ThreadSafe, DefaultMutEx, EmptyMutex >::type Mutex
Lock guard that doesn't lock it's mutex, used on single-core systems.
A class that can be inherited from to allow inserting into a DoublyLinkedList.
static void disable(UpdatableCRTP &element)
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated aut...
#define AH_DIAGNOSTIC_WERROR()
void enable(const LockGuard &lock)
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
#define BEGIN_AH_NAMESPACE
virtual void update()=0
Update this updatable.
void moveDown()
Move down this element in the list.
static void applyToAll(const LockGuard &, void(Derived::*method)(Args &&...), Args &&... args)
void moveDown(const LockGuard &)
Move down this element in the list.
static void applyToAll(void(Derived::*method)(Args &&...), Args &&... args)
static DoublyLinkedList< Derived > updatables