13 class AbstractSystem3;
25 : subcontext_num(subcontext_num), port_num(port_num), entry(entry) {}
56 : subcontext_num(subcontext_num), location(location), entry(entry) {
71 location = source.location;
95 std::unique_ptr<AbstractContext3>
Clone()
const {
96 return std::unique_ptr<AbstractContext3>(DoClone());
104 inputs_.resize(num_ports);
112 outputs_.resize(num_ports);
117 DRAKESYSTEMFRAMEWORK_EXPORT
122 DRAKESYSTEMFRAMEWORK_EXPORT
133 return get_input_entry_finder(port_num).entry;
140 return get_input_entry_finder(port_num).entry;
144 return *get_output_entry_finder(port_num).entry;
148 return get_output_entry_finder(port_num).entry;
159 subcontext->set_owner(
this, subcontext_num);
160 subcontexts_.push_back(std::move(subcontext));
173 return *subcontexts_[index];
180 return subcontexts_[index].get();
208 return const_cast<AbstractSystem3*
>(&find_my_subsystem(*some_subsystem));
216 if (!get_parent_context())
return *
this;
236 : inputs_(source.inputs_),
237 outputs_(source.outputs_),
238 cache_(source.cache_) {
272 void ClearInputPorts() { inputs_.clear(); }
277 void ClearOutputPorts() { outputs_.clear(); }
286 int start = 0)
const {
287 if (start == (
int)path.size())
return *
this;
288 return get_subcontext(path[start]).find_subcontext(path, start + 1);
304 std::vector<int> get_path_from_root_context()
const {
305 std::vector<int> path;
306 if (get_parent_context()) {
307 path = get_parent_context()->get_path_from_root_context();
309 path.push_back(get_subcontext_num());
321 std::vector<InputEntryFinder> inputs_;
324 std::vector<OutputEntryFinder> outputs_;
329 mutable std::vector<CacheEntry> cache_;
334 std::vector<std::unique_ptr<AbstractContext3>> subcontexts_;
339 int subcontext_num_{-1};
345 template <
typename T>
370 template <
typename T>
377 const T&
get_time()
const {
return get_step_info().time_sec; }
381 get_mutable_step_info()->time_sec = time_sec;
394 std::unique_ptr<Context3<T>>
Clone()
const {
395 return std::unique_ptr<Context3<T>>(DoClone());
442 const StepInfo<T>& get_step_info()
const {
return step_info_; }
448 StepInfo<T>* get_mutable_step_info() {
return &step_info_; }
An abstract superclass for the Context3 objects for dynamical systems, encapsulating functionality th...
Definition: context3.h:87
int subcontext_num
-1 means this context.
Definition: context3.h:76
virtual ~AbstractContext3()
Definition: context3.h:89
int get_subcontext_num() const
If this context is a subcontext of a parent context, return the subcontext number by which that paren...
Definition: context3.h:194
const AbstractContext3 & get_root_context() const
Find the root context of the tree of which this subcontext is a member.
Definition: context3.h:215
int get_num_subcontexts() const
Returns the current number of subcontexts contained in this context.
Definition: context3.h:167
Definition: constants.h:3
InputEntryFinder()=default
OutputEntryFinder(OutputEntryFinder &&source)
Move constructor preserves all values and clears the source.
Definition: context3.h:67
int location
Port number for subcontext, or entry if local.
Definition: context3.h:77
Context3()
Definition: context3.h:373
Context3(const Context3 &source)
Copy constructor makes a deep copy of the source Context3, and also copies the current values of time...
Definition: context3.h:402
InputEntryFinder & operator=(InputEntryFinder &&source)
Move assignment preserves all values and clears the source.
Definition: context3.h:36
const AbstractContext3 * get_parent_context() const
Returns a const pointer to the parent context that owns this one, or nullptr if this is a root contex...
Definition: context3.h:185
CacheEntry * get_mutable_input_entry(int port_num) const
Return a mutable pointer to the cache entry that is providing the value for the given input port...
Definition: context3.h:139
int get_num_output_ports() const
Definition: context3.h:126
const AbstractContext3 & get_subcontext(int index) const
Returns a const reference to one of the contained subcontexts, using the index reflecting the order i...
Definition: context3.h:172
int AddSubcontext(std::unique_ptr< AbstractContext3 > subcontext)
Add a subcontext as a child of this context.
Definition: context3.h:157
const CacheEntry & get_output_entry(int port_num) const
Definition: context3.h:143
int get_num_cache_entries() const
Definition: context3.h:127
There is one of these corresponding to every OutputPort3 in the System3 that created the containing C...
Definition: context3.h:53
std::unique_ptr< Context3< T > > Clone() const
Returns writable access to the State.
Definition: context3.h:394
There is one of these corresponding to every InputPort3 in the System3 that created the containing Co...
Definition: context3.h:22
#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
~Context3() override
Definition: context3.h:374
Provides Drake'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
AbstractContext3 * get_mutable_parent_context()
Returns a mutable pointer to the parent context that owns this one, or nullptr if this is a root cont...
Definition: context3.h:189
InputEntryFinder(InputEntryFinder &&source)
Move constructor preserves all values and clears the source.
Definition: context3.h:34
InputEntryFinder & operator=(const InputEntryFinder &source)
Definition: context3.h:27
OutputEntryFinder & operator=(const OutputEntryFinder &source)
Definition: context3.h:60
int port_num
Port number as understood by the subcontext.
Definition: context3.h:44
An abstract superclass for dynamical systems, encapsulating functionality that is independent of the ...
Definition: system3.h:68
void SetNumInputPorts(int num_ports)
Allocate input port entries corresponding to a System3's InputPort3 objects.
Definition: context3.h:101
std::unique_ptr< AbstractContext3 > Clone() const
Returns a deep copy of this Context3.
Definition: context3.h:95
int get_num_input_ports() const
Definition: context3.h:125
Context3< T > * DoClone() const override
The Context implementation for Diagrams must override this method, since the state of a Diagram will ...
Definition: context3.h:412
const CacheEntry * get_input_entry(int port_num) const
Return a const pointer to the cache entry that is providing the value for the given input port...
Definition: context3.h:132
OutputEntryFinder(int subcontext_num, int location, CacheEntry *entry)
Definition: context3.h:55
void set_time(const T &time_sec)
Set the current time in seconds.
Definition: context3.h:380
int subcontext_num
-1 means this context.
Definition: context3.h:43
CacheEntry * get_mutable_output_entry(int port_num) const
Definition: context3.h:147
The context is a container for all data necessary to uniquely determine the results of computations p...
Definition: context3.h:371
Contains information about the independent variable including time and step number.
Definition: context.h:19
InputEntryFinder(int subcontext_num, int port_num, CacheEntry *entry)
Definition: context3.h:24
AbstractContext3 * get_mutable_root_context()
Get a mutable pointer to the root context of the tree of which this subcontext is a member...
Definition: context3.h:223
OutputEntryFinder(const OutputEntryFinder &source)
Definition: context3.h:59
const T & get_time() const
Returns the current time in seconds.
Definition: context3.h:377
AbstractContext3(const AbstractContext3 &source)
Copy the base class data members and preserve the input and parameter port values.
Definition: context3.h:235
AbstractSystem3 * find_my_mutable_subsystem(AbstractSystem3 *some_subsystem) const
Get mutable access to this subcontext's subsystem given mutable access to any other subcontext's subs...
Definition: context3.h:206
void SetNumOutputPorts(int num_ports)
Allocate output port entries corresponding to a System3's OutputPort3 objects.
Definition: context3.h:109
AbstractContext3 * get_mutable_subcontext(int index)
Returns a mutable pointer to one of the contained subcontexts, using the index reflecting the order i...
Definition: context3.h:179
CacheEntry * entry
Convenience pointer to output if connected.
Definition: context3.h:45
OutputEntryFinder & operator=(OutputEntryFinder &&source)
Move assignment preserves all values and clears the source.
Definition: context3.h:69
InputEntryFinder(const InputEntryFinder &source)
Definition: context3.h:26
Each cache entry contains:
Definition: cache3.h:29