37 checkMessageType(message);
47 checkMessageType(message);
57 checkMessageType(message);
67 checkMessageType(message);
78 checkMessageType(message);
89 checkMessageType(message);
99 checkMessageType(message);
108 virtual void updateImpl([[maybe_unused]]
MessageType message, [[maybe_unused]]
int val1,
const std::string& val2) {};
114 if (MessageType::END == message)
115 DUNE_THROW(Dune::InvalidStateException,
"The END enum type should not be used");
116 if (MessageType::BEGIN == message)
117 DUNE_THROW(Dune::InvalidStateException,
"The BEGIN enum type should not be used");
127template <
typename MessageType>
132 for (MessageType msg = MessageType::BEGIN; msg != MessageType::END;
Ikarus::increment(msg))
133 messages_.push_back(msg);
175 template <std::
floating_po
int ScalarType>
176 void notify(MessageType message, ScalarType val);
183 void notify(MessageType message,
int val);
190 void notify(MessageType message,
const std::string& val);
198 void notify(MessageType message,
int val1,
double val2);
206 void notify(MessageType message,
int val1,
const std::string& val2);
214 template <std::
floating_po
int ScalarType>
215 void notify(MessageType message, Eigen::VectorX<ScalarType> vec);
218 using ObserverVector = std::vector<std::shared_ptr<IObserver<MessageType>>>;
219 using ObserverMap = std::map<MessageType, ObserverVector>;
220 ObserverMap observers_;
221 std::vector<MessageType> messages_;
224template <
typename MT>
227 auto&& vectorOfObserversOfASpecificMessage = observers_[message];
228 vectorOfObserversOfASpecificMessage.push_back(observer);
231template <
typename MT>
233 for (
auto& msg : messages_)
234 subscribe(msg, observer);
237template <
typename MT>
239 for (
auto& observer : observers)
240 for (
auto& msg : messages_)
241 subscribe(msg, observer);
244template <
typename MT>
246 auto vectorOfObserversOfASpecificMessage = observers_[message];
247 std::ranges::remove_if(vectorOfObserversOfASpecificMessage, [&observer](
auto&& obs) {
return obs == observer; });
250template <
typename MT>
252 for (
auto& msg : messages_)
253 unSubscribe(msg, observer);
256template <
typename MT>
258 auto vectorOfObserversOfASpecificMessage = observers_[message];
259 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
260 obs->update(message);
263template <
typename MT>
264template <std::
floating_po
int ScalarType>
266 auto vectorOfObserversOfASpecificMessage = observers_[message];
267 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
268 obs->update(message, val);
271template <
typename MT>
273 auto vectorOfObserversOfASpecificMessage = observers_[message];
274 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
275 obs->update(message, val);
278template <
typename MT>
280 auto vectorOfObserversOfASpecificMessage = observers_[message];
281 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
282 obs->update(message, val);
285template <
typename MT>
287 auto vectorOfObserversOfASpecificMessage = observers_[message];
288 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
289 obs->update(message, val1, val2);
292template <
typename MT>
294 auto vectorOfObserversOfASpecificMessage = observers_[message];
295 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
296 obs->update(message, val1, val2);
299template <
typename MT>
300template <std::
floating_po
int ScalarType>
302 auto vectorOfObserversOfASpecificMessage = observers_[message];
303 for (
auto&& obs : vectorOfObserversOfASpecificMessage)
304 obs->update(message, vec);
Implementation of the make enum macro.
MessageType & increment(MessageType &e)
Increments the given enum value.
Definition: makeenum.hh:68
Definition: assemblermanipulatorbuildingblocks.hh:22
Generic observer interface for the Observer design pattern. See for a description of the design patt...
Definition: observer.hh:26
void update(MessageType message, int val1, const std::string &val2)
Update method for receiving notifications with a message, an integer value, and a string value.
Definition: observer.hh:88
void update(MessageType message, const Eigen::VectorXd &vec)
Update method for receiving notifications with a message and an Eigen::VectorXd.
Definition: observer.hh:98
virtual ~IObserver()=default
Virtual destructor for the observer interface.
void update(MessageType message, double val)
Update method for receiving notifications with a message and a double value.
Definition: observer.hh:46
virtual void updateImpl(MessageType message, const std::string &val)
Definition: observer.hh:107
virtual void updateImpl(MessageType message, const Eigen::VectorXd &vec)
Definition: observer.hh:110
virtual void updateImpl(MessageType message, int val1, const std::string &val2)
Definition: observer.hh:108
virtual void updateImpl(MessageType message, double val)
Definition: observer.hh:105
virtual void updateImpl(MessageType message, int val)
Definition: observer.hh:106
void update(MessageType message, int val1, double val2)
Update method for receiving notifications with a message and two values (integer and double).
Definition: observer.hh:77
void update(MessageType message, int val)
Update method for receiving notifications with a message and an integer value.
Definition: observer.hh:56
void update(MessageType message, const std::string &val)
Update method for receiving notifications with a message and a string value.
Definition: observer.hh:66
void update(MessageType message)
Update method for receiving notifications with a message.
Definition: observer.hh:36
virtual void updateImpl(MessageType message)
Definition: observer.hh:104
MT MessageType
Definition: observer.hh:28
virtual void updateImpl(MessageType message, int val1, double val2)
Definition: observer.hh:109
Generic observable interface for the Observer design pattern. See for a description of the design pa...
Definition: observer.hh:129
void subscribeAll(std::initializer_list< std::shared_ptr< IObserver< MessageType > > > observers)
Subscribe multiple observers to receive notifications for all message types.
void subscribeAll(std::shared_ptr< IObserver< MessageType > > observer)
Subscribe an observer to receive notifications for all message types.
void notify(MessageType message, const std::string &val)
Notify observers about a specific message type with a string value.
void unSubscribeAll(std::shared_ptr< IObserver< MessageType > > observer)
Unsubscribe an observer from receiving notifications for all message types.
Definition: observer.hh:251
void unSubscribe(MessageType message, std::shared_ptr< IObserver< MessageType > > observer)
Unsubscribe an observer from receiving notifications for a specific message type.
Definition: observer.hh:245
void notify(MessageType message, int val)
Notify observers about a specific message type with an integer value.
void notify(MessageType message)
Notify observers about a specific message type.
void notify(MessageType message, int val1, const std::string &val2)
Notify observers about a specific message type with an integer value and a string value.
void notify(MessageType message, ScalarType val)
Notify observers about a specific message type with a floating-point value.
void notify(MessageType message, Eigen::VectorX< ScalarType > vec)
Notify observers about a specific message type with an Eigen::VectorX.
IObservable()
Definition: observer.hh:131
virtual ~IObservable()=default
void subscribe(MessageType message, std::shared_ptr< IObserver< MessageType > > observer)
Subscribe an observer to receive notifications for a specific message type.
Definition: observer.hh:225
void notify(MessageType message, int val1, double val2)
Notify observers about a specific message type with an integer and a double value.