Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move global variables to class Container.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 16 Oct 2020 06:30:28 +0000 (08:30 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 16 Oct 2020 07:29:58 +0000 (09:29 +0200)
src/instr/instr_paje_containers.cpp
src/instr/instr_paje_containers.hpp

index 13aa84b..ce91863 100644 (file)
@@ -13,8 +13,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing eve
 namespace simgrid {
 namespace instr {
 
-static Container* rootContainer = nullptr;              /* the root container */
-static std::map<std::string, Container*> allContainers; /* all created containers indexed by name */
+Container* Container::root_container_ = nullptr;              /* the root container */
+std::map<std::string, Container*> Container::all_containers_; /* all created containers indexed by name */
 
 long long int new_paje_id()
 {
@@ -22,11 +22,6 @@ long long int new_paje_id()
   return type_id++;
 }
 
-Container* Container::get_root()
-{
-  return rootContainer;
-}
-
 NetZoneContainer::NetZoneContainer(const std::string& name, unsigned int level, NetZoneContainer* father)
     : Container::Container(name, "", father)
 {
@@ -38,7 +33,7 @@ NetZoneContainer::NetZoneContainer(const std::string& name, unsigned int level,
     on_creation(*this);
   } else {
     type_         = new ContainerType("0");
-    rootContainer = this;
+    set_root(this);
   }
 }
 
@@ -74,9 +69,9 @@ Container::Container(const std::string& name, const std::string& type_name, Cont
   }
 
   //register all kinds by name
-  if (not allContainers.emplace(name_, this).second)
+  if (not all_containers_.emplace(name_, this).second)
     throw TracingError(XBT_THROW_POINT,
-                       xbt::string_printf("container %s already present in allContainers data structure", get_cname()));
+                       xbt::string_printf("container %s already present in all_containers_", get_cname()));
 
   XBT_DEBUG("Add container name '%s'", get_cname());
 }
@@ -88,8 +83,8 @@ Container::~Container()
   for (auto child : children_)
     delete child.second;
 
-  // remove me from the allContainers data structure
-  allContainers.erase(name_);
+  // remove me from the all_containers_ data structure
+  all_containers_.erase(name_);
 
   // obligation to dump previous events because they might reference the container that is about to be destroyed
   last_timestamp_to_dump = SIMIX_get_clock();
@@ -105,8 +100,8 @@ void Container::create_child(const std::string& name, const std::string& type_na
 
 Container* Container::by_name_or_null(const std::string& name)
 {
-  auto cont = allContainers.find(name);
-  return cont == allContainers.end() ? nullptr : cont->second;
+  auto cont = all_containers_.find(name);
+  return cont == all_containers_.end() ? nullptr : cont->second;
 }
 
 Container* Container::by_name(const std::string& name)
index b342f77..52a2b2d 100644 (file)
@@ -17,9 +17,15 @@ class StateType;
 class VariableType;
 
 class Container {
+  static Container* root_container_;
+  static std::map<std::string, Container*> all_containers_;
+
   long long int id_;
   std::string name_; /* Unique name of this container */
 
+protected:
+  static void set_root(Container* root) { root_container_ = root; }
+
 public:
   static xbt::signal<void(Container const&)> on_creation;
   static xbt::signal<void(Container const&)> on_destruction;
@@ -44,7 +50,7 @@ public:
   LinkType* get_link(const std::string& name);
   VariableType* get_variable(const std::string& name);
   void create_child(const std::string& name, const std::string& type_name);
-  static Container* get_root();
+  static Container* get_root() { return root_container_; }
 };
 
 class NetZoneContainer : public Container {