Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make s4u::Engine::pimpl private at the price of a static_cast deep below
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 9 May 2018 23:01:16 +0000 (01:01 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 9 May 2018 23:01:19 +0000 (01:01 +0200)
There is something rotten between Netzone and NetzoneImpl. They should
be aligned with the design of the other s4u/kernel objects. At some
point.

include/simgrid/s4u/Engine.hpp
src/s4u/s4u_Engine.cpp
src/surf/sg_platf.cpp

index 43c4920..381563f 100644 (file)
@@ -110,6 +110,7 @@ public:
   simgrid::kernel::routing::NetPoint* netpoint_by_name_or_null(std::string name);
 
   simgrid::s4u::NetZone* get_netzone_root();
   simgrid::kernel::routing::NetPoint* netpoint_by_name_or_null(std::string name);
 
   simgrid::s4u::NetZone* get_netzone_root();
+  void set_netzone_root(s4u::NetZone* netzone);
 
   simgrid::s4u::NetZone* netzone_by_name_or_null(const char* name);
 
 
   simgrid::s4u::NetZone* netzone_by_name_or_null(const char* name);
 
@@ -133,9 +134,8 @@ public:
    */
   void set_config(std::string str);
 
    */
   void set_config(std::string str);
 
-  simgrid::kernel::EngineImpl* pimpl;
-
 private:
 private:
+  simgrid::kernel::EngineImpl* pimpl;
   static s4u::Engine* instance_;
 
   //////////////// Deprecated functions
   static s4u::Engine* instance_;
 
   //////////////// Deprecated functions
index 352e4eb..5860786 100644 (file)
@@ -193,6 +193,12 @@ s4u::NetZone* Engine::get_netzone_root()
 {
   return pimpl->netzone_root_;
 }
 {
   return pimpl->netzone_root_;
 }
+/** @brief Set the root netzone, containing all others. Once set, it cannot be changed. */
+void Engine::set_netzone_root(s4u::NetZone* netzone)
+{
+  xbt_assert(pimpl->netzone_root_ == nullptr, "The root NetZone cannot be changed once set");
+  pimpl->netzone_root_ = static_cast<kernel::routing::NetZoneImpl*>(netzone);
+}
 
 static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name)
 {
 
 static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name)
 {
index c3c3562..e7374e5 100644 (file)
@@ -599,10 +599,7 @@ simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCre
   }
 
   if (current_routing == nullptr) { /* it is the first one */
   }
 
   if (current_routing == nullptr) { /* it is the first one */
-    xbt_assert(simgrid::s4u::Engine::get_instance()->pimpl->netzone_root_ == nullptr,
-               "All defined components must belong to a networking zone.");
-    simgrid::s4u::Engine::get_instance()->pimpl->netzone_root_ = new_zone;
-
+    simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone);
   } else {
     /* set the father behavior */
     if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
   } else {
     /* set the father behavior */
     if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)