-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
port_base.cc
55 lines (45 loc) · 1.69 KB
/
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
52
53
54
55
#include "drake/systems/framework/port_base.h"
#include <utility>
#include <fmt/format.h>
#include "drake/common/drake_assert.h"
#include "drake/common/nice_type_name.h"
namespace drake {
namespace systems {
PortBase::PortBase(
const char* kind_string, internal::SystemMessageInterface* owning_system,
internal::SystemId owning_system_id, std::string name, int index,
DependencyTicket ticket, PortDataType data_type, int size)
: kind_string_(kind_string),
owning_system_(*owning_system),
owning_system_id_(owning_system_id),
index_(index),
ticket_(ticket),
data_type_(data_type),
size_(size),
name_(std::move(name)) {
DRAKE_DEMAND(kind_string != nullptr);
DRAKE_DEMAND(owning_system != nullptr);
DRAKE_DEMAND(owning_system_id.is_valid());
DRAKE_DEMAND(!name_.empty());
}
PortBase::~PortBase() = default;
std::string PortBase::GetFullDescription() const {
return fmt::format(
"{}Port[{}] ({}) of System {} ({})",
kind_string_, index_, name_, get_system_interface().GetSystemPathname(),
NiceTypeName::RemoveNamespaces(get_system_interface().GetSystemType()));
}
void PortBase::ThrowValidateContextMismatch() const {
throw std::logic_error(fmt::format(
"{}Port: The Context given as an argument was not created for this {}",
kind_string_, GetFullDescription()));
}
void PortBase::ThrowBadCast(
const std::string& value_typename, const std::string& eval_typename) const {
throw std::logic_error(fmt::format(
"{}Port::Eval(): wrong value type {} specified; "
"actual type was {} for {}.",
kind_string_, eval_typename, value_typename, GetFullDescription()));
}
} // namespace systems
} // namespace drake