Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more stringification/privatization
[simgrid.git] / src / instr / instr_paje_containers.cpp
index 32966ff..32b40bf 100644 (file)
@@ -8,15 +8,14 @@
 
 #include "surf/surf.h"
 
-#include "src/instr/instr_private.h"
+#include "src/instr/instr_private.hpp"
 
 #include <unordered_map>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing event system (containers)");
 
 static container_t rootContainer = nullptr;    /* the root container */
-static std::unordered_map<std::string, simgrid::instr::Container*>
-    allContainers;                              /* all created containers indexed by name */
+static std::unordered_map<std::string, container_t> allContainers; /* all created containers indexed by name */
 std::set<std::string> trivaNodeTypes;           /* all host types defined */
 std::set<std::string> trivaEdgeTypes;           /* all link types defined */
 
@@ -126,15 +125,18 @@ simgrid::instr::Container::Container(std::string name, simgrid::instr::e_contain
   //register NODE types for triva configuration
   if (this->kind_ == simgrid::instr::INSTR_HOST || this->kind_ == simgrid::instr::INSTR_LINK ||
       this->kind_ == simgrid::instr::INSTR_ROUTER) {
-    trivaNodeTypes.insert(this->type_->name_);
+    trivaNodeTypes.insert(this->type_->getName());
   }
 }
 simgrid::instr::Container::~Container()
 {
   XBT_DEBUG("destroy container %s", name_.c_str());
+  // Begin with destroying my own children
+  for (auto child : children_) {
+    delete child.second;
+  }
 
-  // obligation to dump previous events because they might
-  // reference the container that is about to be destroyed
+  // obligation to dump previous events because they might reference the container that is about to be destroyed
   TRACE_last_timestamp_to_dump = surf_get_clock();
   TRACE_paje_dump_buffer(1);
 
@@ -144,25 +146,23 @@ simgrid::instr::Container::~Container()
     LogContainerDestruction(this);
   }
 
-  // remove it from allContainers data structure
+  // remove me from the allContainers data structure
   allContainers.erase(name_);
-
-  // free
 }
 
-simgrid::instr::Container* PJ_container_get(const char* name)
+simgrid::instr::Container* simgrid::instr::Container::byNameOrNull(std::string name)
 {
-  container_t ret = PJ_container_get_or_null (name);
-  if (ret == nullptr){
-    THROWF(tracing_error, 1, "container with name %s not found", name);
-  }
-  return ret;
+  auto cont = allContainers.find(name);
+  return cont == allContainers.end() ? nullptr : cont->second;
 }
 
-simgrid::instr::Container* PJ_container_get_or_null(const char* name)
+simgrid::instr::Container* simgrid::instr::Container::byName(std::string name)
 {
-  auto cont = allContainers.find(name);
-  return cont == allContainers.end() ? nullptr : cont->second;
+  container_t ret = simgrid::instr::Container::byNameOrNull(name);
+  if (ret == nullptr)
+    THROWF(tracing_error, 1, "container with name %s not found", name.c_str());
+
+  return ret;
 }
 
 simgrid::instr::Container* PJ_container_get_root()
@@ -182,30 +182,3 @@ void PJ_container_remove_from_parent (container_t child)
     parent->children_.erase(child->name_);
   }
 }
-
-static void recursiveDestroyContainer (container_t container)
-{
-  if (container == nullptr){
-    THROWF (tracing_error, 0, "trying to recursively destroy a nullptr container");
-  }
-  XBT_DEBUG("recursiveDestroyContainer %s", container->name_.c_str());
-  for (auto child : container->children_) {
-    recursiveDestroyContainer(child.second);
-  }
-  delete container;
-}
-
-void PJ_container_free_all ()
-{
-  container_t root = PJ_container_get_root();
-  if (root == nullptr){
-    THROWF (tracing_error, 0, "trying to free all containers, but root is nullptr");
-  }
-  recursiveDestroyContainer (root);
-  rootContainer = nullptr;
-
-  //checks
-  if (not allContainers.empty()) {
-    THROWF(tracing_error, 0, "some containers still present even after destroying all of them");
-  }
-}