Drake
input_port_descriptor.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace drake {
9 namespace systems {
10 
11 template <typename T>
12 class System;
13 
20 template <typename T>
22  public:
32  InputPortDescriptor(const System<T>* system, int index,
33  PortDataType data_type, int size,
34  const optional<RandomDistribution>& random_type)
35  : system_(system),
36  index_(index),
37  data_type_(data_type),
38  size_(size),
39  random_type_(random_type) {
40  if (size_ == kAutoSize) {
41  DRAKE_ABORT_MSG("Auto-size ports are not yet implemented.");
42  }
43  if (is_random() && data_type_ != kVectorValued) {
44  DRAKE_ABORT_MSG("Random input ports must be vector valued.");
45  }
46  }
47 
51  //
52  // Implementation note: This class aliases a pointer to the system that
53  // contains it and captures its own index within that system's port vector,
54  // so we must be careful not to allow C++ copying to extend the lifetime of
55  // the system alias or duplicate our claim to the index. Thus, this class is
56  // `MoveConstructible` but neither copyable nor assignable: it supports move
57  // to populate a vector, but is non-copyable in order remain the "one true
58  // descriptor" after construction and non-assignable in order to remain
59  // const. Code that wishes to refer to this descriptor after insertion into
60  // the vector should use a reference (not copy) of this descriptor.
61  InputPortDescriptor() = delete;
62  InputPortDescriptor(InputPortDescriptor&& other) = default;
66  ~InputPortDescriptor() = default;
68 
69  const System<T>* get_system() const { return system_; }
70  int get_index() const { return index_; }
71  PortDataType get_data_type() const { return data_type_; }
72  int size() const { return size_; }
73  bool is_random() const { return static_cast<bool>(random_type_); }
74  optional<RandomDistribution> get_random_type() const { return random_type_; }
75 
76  private:
77  const System<T>* const system_;
78  const int index_;
79  const PortDataType data_type_;
80  const int size_;
81  const optional<RandomDistribution> random_type_;
82 };
83 
84 } // namespace systems
85 } // namespace drake
optional< RandomDistribution > get_random_type() const
Definition: input_port_descriptor.h:74
Definition: automotive_demo.cc:88
InputPortDescriptor(const System< T > *system, int index, PortDataType data_type, int size, const optional< RandomDistribution > &random_type)
Definition: input_port_descriptor.h:32
#define DRAKE_ABORT_MSG(message)
Aborts the program (via ::abort) with a message showing at least the given message (macro argument)...
Definition: drake_assert.h:53
InputPortDescriptor is a notation for specifying the kind of input a System accepts, on a given port.
Definition: input_port_descriptor.h:21
stx::optional< T > optional
Definition: drake_optional.h:15
Definition: system_common.h:11
Provides Drake&#39;s assertion implementation.
Provides drake::optional as an alias for the appropriate implementation of std::optional or std::expe...
A superclass template for systems that receive input, maintain state, and produce output of a given m...
Definition: input_port_descriptor.h:12
bool is_random() const
Definition: input_port_descriptor.h:73
constexpr int kAutoSize
Definition: system_common.h:6
const System< T > * get_system() const
Definition: input_port_descriptor.h:69
int size() const
Definition: input_port_descriptor.h:72
PortDataType
All system ports are either vectors of Eigen scalars, or black-box AbstractValues which may contain a...
Definition: system_common.h:10
int get_index() const
Definition: input_port_descriptor.h:70
InputPortDescriptor & operator=(InputPortDescriptor &&)=delete
PortDataType get_data_type() const
Definition: input_port_descriptor.h:71