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:
2026-10-07 11:31:16 +02:00
co-authored by Qwen 3.8 27B
parent 11b96e4410
commit a65e84e796
7 changed files with 277 additions and 244 deletions
+28 -28
View File
@@ -1,28 +1,28 @@
#ifndef POLE_H
#define POLE_H
#include "Light.h"
#include "Observer.h"
#include "Pelican.h"
class Pole : public Observer {
public:
Pole(int x, int y, Pelican &p);
~Pole();
void setTrafficLights(Pelican::PelicanState state);
void setWaitLight(bool pressed);
void update();
private:
Pelican &myPelican;
enum LightName { RED_LIGHT, YELLOW_LIGHT, GREEN_LIGHT, GREEN_MAN, RED_MAN };
Light *lights[RED_MAN + 1];
Light *waitLight;
};
#endif
#ifndef POLE_H
#define POLE_H
#include "Light.h"
#include "Observer.h"
#include "Pelican.h"
class Pole : public Observer {
public:
Pole(int x, int y, Pelican &p);
~Pole();
void setTrafficLights(Pelican::PelicanState state);
void setWaitLight(bool pressed);
void update(const Hint& hint);
private:
Pelican &myPelican;
enum LightName { RED_LIGHT, YELLOW_LIGHT, GREEN_LIGHT, GREEN_MAN, RED_MAN };
Light *lights[RED_MAN + 1];
Light *waitLight;
};
#endif