Handle null node in SimulatedEventLoopFactory better
Our tools need to deal with both a world with and without nodes. The
easy way to do that is to allow nullptr as a node in more places to
signal that we are in a single node world.
Change-Id: I6dcbe5c1bd721d6417d30e74b79f861d741970df
diff --git a/aos/events/simulated_event_loop.cc b/aos/events/simulated_event_loop.cc
index af0c02b..1dfb3af 100644
--- a/aos/events/simulated_event_loop.cc
+++ b/aos/events/simulated_event_loop.cc
@@ -739,29 +739,25 @@
SimulatedEventLoopFactory::SimulatedEventLoopFactory(
const Configuration *configuration, std::string_view node_name)
- : configuration_(CHECK_NOTNULL(configuration)),
- node_(configuration::GetNode(configuration, node_name)) {
- CHECK(configuration_->has_nodes())
- << ": Got a configuration with no nodes and node \"" << node_name
- << "\" was selected.";
- CHECK(node_ != nullptr) << ": Can't find node \"" << node_name
- << "\" in the configuration.";
-}
+ : SimulatedEventLoopFactory(
+ configuration, configuration::GetNode(configuration, node_name)) {}
SimulatedEventLoopFactory::SimulatedEventLoopFactory(
const Configuration *configuration, const Node *node)
: configuration_(CHECK_NOTNULL(configuration)), node_(node) {
- CHECK(configuration_->has_nodes())
- << ": Got a configuration with no nodes and node \""
- << node->name()->string_view() << "\" was selected.";
- bool found = false;
- for (const Node *node : *configuration_->nodes()) {
- if (node == node_) {
- found = true;
- break;
+ if (node != nullptr) {
+ CHECK(configuration_->has_nodes())
+ << ": Got a configuration with no nodes and node \""
+ << node->name()->string_view() << "\" was selected.";
+ bool found = false;
+ for (const Node *node : *configuration_->nodes()) {
+ if (node == node_) {
+ found = true;
+ break;
+ }
}
+ CHECK(found) << ": node must be a pointer in the configuration.";
}
- CHECK(found) << ": node must be a pointer in the configuration.";
}
SimulatedEventLoopFactory::~SimulatedEventLoopFactory() {}