Drake
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
value_listener3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <vector>
5 
7 #include "drake/drakeSystemFramework_export.h"
8 
9 namespace drake {
10 namespace systems {
11 
20  public:
22 
25  virtual void Invalidate() = 0;
26 };
27 
35 public:
39  // This check is too expensive for Release builds.
40  DRAKE_ASSERT(std::find(listeners_.begin(), listeners_.end(), listener)
41  == listeners_.end());
42  listeners_.push_back(listener);
43  }
44 
50  auto found = std::find(listeners_.begin(), listeners_.end(), listener);
51  DRAKE_ABORT_UNLESS(found != listeners_.end());
52  listeners_.erase(found);
53  }
54 
56  void NotifyListeners() {
57  for (auto listener : listeners_)
58  listener->Invalidate();
59  }
60 private:
61  // Raw pointers to listeners; no ownership implied.
62  std::vector<ValueListenerInterface*> listeners_;
63 };
64 
65 } // namespace systems
66 } // namespace drake
virtual void Invalidate()=0
Mark this dependent computation "not current", and propagate that to downstream dependents of this li...
Definition: constants.h:3
void add_listener(ValueListenerInterface *listener)
Add a new listener to this list.
Definition: value_listener3.h:38
A ValueListenerList object maintains a list of value listeners that have registered to receive notifi...
Definition: value_listener3.h:34
ValueListenerInterface is an interface that dependent computations must implement so that they can re...
Definition: value_listener3.h:19
void NotifyListeners()
Notify all dependents of this value that the value has changed.
Definition: value_listener3.h:56
#define DRAKE_ASSERT(condition)
DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cas...
Definition: drake_assert.h:35
Provides Drake&#39;s assertion implementation.
#define DRAKE_ABORT_UNLESS(condition)
Evaluates condition and iff the value is false will ::abort() the program with a message showing at l...
Definition: drake_assert.h:39
void RemoveListener(ValueListenerInterface *listener)
Remove a listener from the list.
Definition: value_listener3.h:49
virtual ~ValueListenerInterface()
Definition: value_listener3.h:21