mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-03 19:29:57 +00:00
32ac5ac9ae
using @girtsf clang-format prefs settings. This should allow us to turn on auto format in our editors without causing spurious file changes.
42 lines
723 B
C++
42 lines
723 B
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <list>
|
|
|
|
class Observable;
|
|
|
|
class Observer
|
|
{
|
|
Observable *observed;
|
|
|
|
public:
|
|
Observer() : observed(NULL) {}
|
|
|
|
virtual ~Observer();
|
|
|
|
void observe(Observable *o);
|
|
|
|
private:
|
|
friend class Observable;
|
|
|
|
virtual void onNotify(Observable *o) = 0;
|
|
};
|
|
|
|
class Observable
|
|
{
|
|
std::list<Observer *> observers;
|
|
|
|
public:
|
|
void notifyObservers()
|
|
{
|
|
for (std::list<Observer *>::const_iterator iterator = observers.begin(); iterator != observers.end(); ++iterator) {
|
|
(*iterator)->onNotify(this);
|
|
}
|
|
}
|
|
|
|
void addObserver(Observer *o) { observers.push_back(o); }
|
|
|
|
void removeObserver(Observer *o) { observers.remove(o); }
|
|
};
|