Add GetNodesWithTag
This makes tags much easier to work with. It is common to want to find
all the matching nodes for a tag/function.
Change-Id: Ibe2876fc825dea1ffee5686f7e40dce85ebc8793
diff --git a/aos/configuration.cc b/aos/configuration.cc
index 1d39f27..67d2b96 100644
--- a/aos/configuration.cc
+++ b/aos/configuration.cc
@@ -956,6 +956,31 @@
return nodes;
}
+std::vector<const Node *> GetNodesWithTag(const Configuration *config,
+ std::string_view tag) {
+ std::vector<const Node *> nodes;
+ if (!MultiNode(config)) {
+ nodes.emplace_back(nullptr);
+ } else {
+ for (const Node *node : *config->nodes()) {
+ if (!node->has_tags()) {
+ continue;
+ }
+ bool did_found_tag = false;
+ for (const flatbuffers::String *found_tag : *node->tags()) {
+ if (found_tag->string_view() == tag) {
+ did_found_tag = true;
+ break;
+ }
+ }
+ if (did_found_tag) {
+ nodes.emplace_back(node);
+ }
+ }
+ }
+ return nodes;
+}
+
bool MultiNode(const Configuration *config) { return config->has_nodes(); }
bool ChannelIsSendableOnNode(const Channel *channel, const Node *node) {