9 #include "drake/drakeSystemFramework_export.h" 28 virtual void Invalidate() = 0;
48 dependents_.insert(dependent);
53 dependents_.erase(dependent);
65 dependent->Invalidate();
80 double sample_time_sec_{0.};
84 std::set<OutputPortListenerInterface*> dependents_;
87 long long version_{0};
104 return vector_data_.get();
113 NoteValueModification();
114 return vector_data_.get();
125 std::unique_ptr<VectorInterface<T>> vector_data_;
132 template <
typename T>
142 void set_port(
int port_num, std::unique_ptr<OutputPort> port) {
143 RangeCheck(port_num,
"reset_port");
144 ports_[port_num] = std::move(port);
155 RangeCheck(port_num,
"empty_port");
156 return !ports_[port_num];
165 RangeCheck(port_num,
"is_vector_port");
166 const OutputPort* port = ports_[port_num].get();
167 if (port ==
nullptr)
return false;
174 RangeCheck(port_num,
"get_port");
175 return *ports_[port_num];
180 RangeCheck(port_num,
"get_port");
181 return ports_[port_num].get();
189 if (vector_port ==
nullptr) {
190 throw std::logic_error(
"SystemOutput::get_vector_port(): Port " +
192 " is not a VectorOutputPort.");
205 void RangeCheck(
int port_num,
const char* name)
const {
206 if (0 <= port_num && port_num < get_num_ports())
return;
207 throw std::out_of_range(GetMethod(name) +
"output port " +
209 " is out of range (there are " +
212 void RangeNullCheck(
int port_num,
const char* name)
const {
213 RangeCheck(port_num, name);
214 if (!ports_[port_num])
215 throw std::logic_error(GetMethod(name) +
"output port " +
218 static std::string GetMethod(
const char* name) {
219 using namespace std::string_literals;
220 return "SystemOutput::"s + std::string(name) +
"(): "s;
223 std::vector<std::unique_ptr<OutputPort>> ports_;
VectorInterface is a pure abstract interface that real-valued signals between Systems must satisfy...
Definition: vector_interface.h:25
SystemOutput(int num_ports)
Construct a SystemOutput with room for num_ports OutputPort objects, initially empty.
Definition: system_output.h:137
bool is_empty_port(int port_num) const
Returns true if the indicated port slot is unoccupied.
Definition: system_output.h:154
const VectorInterface< T > * get_vector_data() const
Returns the vector of data in this output port, or nullptr if this is an abstract-valued port...
Definition: system_output.h:103
virtual ~OutputPortListenerInterface()
Definition: system_output.h:24
Definition: constants.h:3
OutputPort * get_mutable_port(int port_num)
Returns a mutable pointer to the indicated port.
Definition: system_output.h:179
VectorOutputPort< T > * get_mutable_vector_port(int port_num)
Returns a mutable pointer to the indicated VectorOutputPort.
Definition: system_output.h:199
const OutputPort & get_port(int port_num) const
Returns a const reference to the indicated port, which must be in range and not empty.
Definition: system_output.h:173
void set_port(int port_num, std::unique_ptr< OutputPort > port)
Sets or replaces the indicated OutputPort with the given port and takes over ownership.
Definition: system_output.h:142
VectorOutputPort(std::unique_ptr< VectorInterface< T >> data)
Takes ownership of data.
Definition: system_output.h:98
void add_dependent(OutputPortListenerInterface *dependent)
Registers dependent to receive invalidation notifications whenever this output port's value changes...
Definition: system_output.h:47
An OutputPort represents a data output from a System.
Definition: system_output.h:41
VectorInterface< T > * GetMutableVectorData()
Returns a pointer providing mutable access to the data inside this VectorOutputPort, and updates the version so that Contexts depending on this OutputPort know to invalidate their caches.
Definition: system_output.h:112
bool is_vector_port(int port_num) const
Check whether the indicated port is of type VectorOutputPort<T>; otherwise it is an AbstractOutputPor...
Definition: system_output.h:164
void remove_dependent(OutputPortListenerInterface *dependent)
Unregisters dependent from invalidation notifications.
Definition: system_output.h:52
OutputPort()
Definition: system_output.h:69
std::string to_string(const Eigen::MatrixBase< Derived > &a)
Definition: testUtil.h:29
OutputPortListenerInterface is an interface that consumers of an output port must satisfy to receive ...
Definition: system_output.h:22
A container for all the output ports of a System.
Definition: system_output.h:133
const VectorOutputPort< T > & get_vector_port(int port_num) const
Returns a const reference to the indicated VectorOutputPort.
Definition: system_output.h:186
The OutputPort represents a data output from a System.
Definition: system_output.h:95
long long get_version() const
Returns a positive and monotonically increasing number that is guaranteed to change whenever GetMutab...
Definition: system_output.h:58
void NoteValueModification()
Notify any dependents that the value on this OutputPort has changed, and update the value version her...
Definition: system_output.h:62
int get_num_ports() const
Returns the number of OutputPort objects which may be contained here.
Definition: system_output.h:149