-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
input_port_base.cc
51 lines (42 loc) · 1.52 KB
/
input_port_base.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "drake/systems/framework/input_port_base.h"
#include <stdexcept>
#include <utility>
#include <fmt/format.h>
#include "drake/common/drake_assert.h"
namespace drake {
namespace systems {
InputPortBase::InputPortBase(
internal::SystemMessageInterface* owning_system,
internal::SystemId owning_system_id, std::string name,
InputPortIndex index, DependencyTicket ticket,
PortDataType data_type, int size,
const std::optional<RandomDistribution>& random_type,
EvalAbstractCallback eval, ValueProducer::AllocateCallback alloc)
: PortBase("Input", owning_system, owning_system_id, std::move(name),
index, ticket, data_type, size),
eval_(std::move(eval)),
alloc_(std::move(alloc)),
random_type_(random_type) {
if (is_random() && data_type != kVectorValued) {
throw std::logic_error("Random input ports must be vector valued.");
}
DRAKE_DEMAND(eval_ != nullptr);
DRAKE_DEMAND(alloc_ != nullptr);
}
InputPortBase::~InputPortBase() = default;
std::unique_ptr<AbstractValue> InputPortBase::Allocate() const {
std::unique_ptr<AbstractValue> value = alloc_();
if (value == nullptr) {
throw std::logic_error(fmt::format(
"InputPort::Allocate(): allocator returned a nullptr for {}.",
GetFullDescription()));
}
return value;
}
void InputPortBase::ThrowRequiredMissing() const {
throw std::logic_error(fmt::format(
"InputPort::Eval(): required {} is not connected",
GetFullDescription()));
}
} // namespace systems
} // namespace drake