feat(cmat): pass hints to Ex42 observers
Extend the Ex42 observer pattern with Hint objects so each observer receives the reason for the update instead of querying the subject: - Subject::notify() and Observer::update() now take a const Hint& argument. - Add LightHint and WaitHint carrying the traffic light state and WAIT button state, defined in Pelican.h. - Pole dispatches on hint type using dynamic_cast. - The Pole constructor sets its initial lights directly from the Pelican's current state, since no notification is sent at startup. Stopgap until the initial update is handled properly. Co-authored-by: Qwen 3.8 27B <qwen3.8_27b-q3_k_xl@lmstudio.local>
This commit is contained in:
+25
-20
@@ -1,20 +1,25 @@
|
||||
|
||||
|
||||
#ifndef SUBJECT_H
|
||||
#define SUBJECT_H
|
||||
|
||||
class Observer;
|
||||
|
||||
#include <set>
|
||||
|
||||
class Subject {
|
||||
public:
|
||||
typedef std::set<Observer *> ObsList;
|
||||
void attach(Observer &obs);
|
||||
void notify() const;
|
||||
|
||||
private:
|
||||
ObsList myObservers;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SUBJECT_H
|
||||
#define SUBJECT_H
|
||||
|
||||
class Observer;
|
||||
|
||||
#include <set>
|
||||
|
||||
class Hint {
|
||||
public:
|
||||
virtual ~Hint() = default;
|
||||
};
|
||||
|
||||
class Subject {
|
||||
public:
|
||||
typedef std::set<Observer *> ObsList;
|
||||
void attach(Observer &obs);
|
||||
void notify(const Hint&) const;
|
||||
|
||||
private:
|
||||
ObsList myObservers;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user