Loading...
Searching...
No Matches
Unsubscribable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4//
5// Unsubscribable.h
6//
7
8#ifndef MALENA_UNSUBSCRIBABLE_H
9#define MALENA_UNSUBSCRIBABLE_H
10
11#pragma once
12
13
16namespace ml
17{
18 class Core; // fwd: Unsubscribable stores the Core identity (see _selfCore)
51 {
52 public:
65 template<typename EnumType>
66 void unsubscribe(EnumType event)
67 {
68 static_assert(std::is_enum_v<EnumType>,
69 "[Malena] unsubscribe — argument must be an enum value.");
70 doUnsubscribe(EnumKey::get(event));
71 }
72
73
84
85 virtual ~Unsubscribable() = default;
86 private:
87 void doUnsubscribe(const std::string& key);
88
89 // Core's own identity, stamped by Core's constructor.
90 //
91 // Why not just dynamic_cast<Core*>(this) at the point of use: widgets
92 // call unsubscribeAll() from INSIDE their own constructor (ml::Panel
93 // does, and several app scenes do) to drop the empty click/hover
94 // subscriptions ComponentCore auto-registers. At that moment the object
95 // is still under construction, so RTTI on it is undefined — Clang
96 // tolerates it, MSVC hard-fails the process (0xC0000409). Core sets this
97 // pointer before any derived constructor runs, so it is always valid by
98 // then and needs no RTTI at all.
99 Core* _selfCore = nullptr;
100 friend class Core;
101 };
102
103} // namespace ml
104
105#endif // MALENA_UNSUBSCRIBABLE_H
Virtual base class for all Malena framework objects.
Definition Core.h:97
Trait that gives components the ability to unsubscribe from events.
void unsubscribe(EnumType event)
Unsubscribe from a single event by enum value.
void unsubscribeAll()
Remove all event subscriptions for this component.
virtual ~Unsubscribable()=default
#define MALENA_API
Definition Animate.h:25
static std::string get(EnumType value)
Generate a unique string key for an enum value.
Definition EnumKey.h:67