Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
attempt of a function searching all zones of a given type
[simgrid.git] / src / s4u / s4u_engine.cpp
index f991b12..9913599 100644 (file)
@@ -154,6 +154,21 @@ NetZone* Engine::getNetzoneByNameOrNull(const char* name)
   return netzoneByNameRecursive(getNetRoot(), name);
 }
 
+template <class T> void netzoneByTypeRecursive(s4u::NetZone* current, std::vector<T*>* whereto)
+{
+  for (auto const& elem : *(current->getChildren())) {
+    netzoneByTypeRecursive(elem, whereto);
+    if (elem == dynamic_cast<T*>(elem))
+      whereto->push_back(elem);
+  }
+}
+
+/** @brief Retrieve all existing NetZones of the subtype of the whereto vector */
+template <class T> void Engine::getNetzoneByType(std::vector<T*>* whereto)
+{
+  netzoneByTypeRecursive(getNetRoot(), whereto);
+}
+
 /** @brief Retrieve the netpoint of the given name (or nullptr if not found) */
 simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(std::string name)
 {