From: Martin Quinson Date: Wed, 9 May 2018 23:01:16 +0000 (+0200) Subject: make s4u::Engine::pimpl private at the price of a static_cast deep below X-Git-Tag: v3.20~259 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/48028d9fbcca84960514fb0622b9b22a48162cc0 make s4u::Engine::pimpl private at the price of a static_cast deep below There is something rotten between Netzone and NetzoneImpl. They should be aligned with the design of the other s4u/kernel objects. At some point. --- diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 43c49204b8..381563fa91 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -110,6 +110,7 @@ public: 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); @@ -133,9 +134,8 @@ public: */ void set_config(std::string str); - simgrid::kernel::EngineImpl* pimpl; - private: + simgrid::kernel::EngineImpl* pimpl; static s4u::Engine* instance_; //////////////// Deprecated functions diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 352e4eb79c..5860786bb5 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -193,6 +193,12 @@ s4u::NetZone* Engine::get_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(netzone); +} static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name) { diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index c3c3562046..e7374e59c4 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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 */ - 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)