From a43ef1c628f2962dceb1994099e6a67dc292424e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 9 May 2018 23:58:08 +0200 Subject: [PATCH] finish snake_case s4u::Engine --- .../s4u-platform-properties.cpp | 2 +- .../s4u-routing-get-clusters.cpp | 21 +++----- include/simgrid/s4u/Engine.hpp | 48 ++++++++++++++----- src/instr/instr_paje_containers.cpp | 4 +- src/instr/instr_platform.cpp | 6 +-- src/kernel/routing/NetPoint.cpp | 2 +- src/kernel/routing/NetZoneImpl.cpp | 2 +- src/kernel/routing/VivaldiZone.cpp | 4 +- src/s4u/s4u_Engine.cpp | 9 ++-- src/s4u/s4u_Netzone.cpp | 4 +- src/surf/sg_platf.cpp | 2 +- src/surf/xml/surfxml_sax_cb.cpp | 2 +- 12 files changed, 61 insertions(+), 45 deletions(-) diff --git a/examples/s4u/platform-properties/s4u-platform-properties.cpp b/examples/s4u/platform-properties/s4u-platform-properties.cpp index c4d57e00e2..fafbfa74ec 100644 --- a/examples/s4u/platform-properties/s4u-platform-properties.cpp +++ b/examples/s4u/platform-properties/s4u-platform-properties.cpp @@ -71,7 +71,7 @@ static int david(int argc, char* argv[]) static int bob(int argc, char* argv[]) { /* this host also tests the properties of the AS*/ - simgrid::s4u::NetZone* root = simgrid::s4u::Engine::get_instance()->getNetRoot(); + simgrid::s4u::NetZone* root = simgrid::s4u::Engine::get_instance()->get_netzone_root(); XBT_INFO("== Print the properties of the zone"); XBT_INFO(" Zone property: filename -> %s", root->getProperty("filename")); XBT_INFO(" Zone property: date -> %s", root->getProperty("date")); diff --git a/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp index d10b4154db..8f7f6220e6 100644 --- a/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp +++ b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp @@ -14,12 +14,10 @@ int main(int argc, char* argv[]) simgrid::s4u::Engine e(&argc, argv); e.load_platform(argv[1]); - std::vector* clusters = - new std::vector; + std::vector clusters = + e.filter_netzones_by_type(); - e.getNetzoneByType(clusters); - - for (auto c : *clusters) { + for (auto c : clusters) { XBT_INFO("%s", c->get_cname()); std::vector* hosts = new std::vector; c->getHosts(hosts); @@ -28,15 +26,11 @@ int main(int argc, char* argv[]) delete hosts; } - delete clusters; - - std::vector* dragonfly_clusters = - new std::vector; - - e.getNetzoneByType(dragonfly_clusters); + std::vector dragonfly_clusters = + e.filter_netzones_by_type(); - if (not dragonfly_clusters->empty()) { - for (auto d : *dragonfly_clusters) { + if (not dragonfly_clusters.empty()) { + for (auto d : dragonfly_clusters) { XBT_INFO("%s' dragonfly topology:", d->get_cname()); for (int i = 0; i < d->getHostCount(); i++) { unsigned int coords[4]; @@ -45,7 +39,6 @@ int main(int argc, char* argv[]) } } } - delete dragonfly_clusters; return 0; } diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index ead005caea..43c49204b8 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -107,17 +107,19 @@ public: simgrid::s4u::Storage* storage_by_name_or_null(std::string name); std::vector get_all_netpoints(); + simgrid::kernel::routing::NetPoint* netpoint_by_name_or_null(std::string name); - /** @brief Retrieve the root netzone, containing all others */ - simgrid::s4u::NetZone* getNetRoot(); + simgrid::s4u::NetZone* get_netzone_root(); - simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name); + simgrid::s4u::NetZone* netzone_by_name_or_null(const char* name); - /** @brief Retrieves all netzones of the same type than the subtype of the whereto vector */ - template void getNetzoneByType(std::vector * whereto) { netzoneByTypeRecursive(getNetRoot(), whereto); } - - /** @brief Retrieve the netcard of the given name (or nullptr if not found) */ - simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(std::string name); + /** @brief Retrieves all netzones of the type indicated by the template argument */ + template std::vector filter_netzones_by_type() + { + std::vector res; + filter_netzones_by_type_recursive(get_netzone_root(), &res); + return res; + } /** Returns whether SimGrid was initialized yet -- mostly for internal use */ static bool is_initialized(); @@ -194,9 +196,8 @@ public: return get_all_hosts(); } XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_link_count()") size_t getLinkCount() { return get_link_count(); } - XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_link_list()") - XBT_ATTRIB_DEPRECATED_v322("Engine::getLinkList() is deprecated in favor of Engine::get_all_links(). Please " - "switch before v3.22") void getLinkList(std::vector* list); + XBT_ATTRIB_DEPRECATED_v322("Engine::getLinkList() is deprecated in favor of Engine::get_all_links(). Please " + "switch before v3.22") void getLinkList(std::vector* list); XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_link_list()") std::vector getAllLinks() { return get_all_links(); @@ -208,6 +209,27 @@ public: XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_clock()") static double getClock() { return get_clock(); } XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_all_netpoints()") void getNetpointList( std::vector* list); + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::netpoint_by_name_or_null()") + simgrid::kernel::routing::NetPoint* getNetpointByNameOrNull(std::string name) + { + return netpoint_by_name_or_null(name); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_netzone_root()") simgrid::s4u::NetZone* getNetRoot() + { + return get_netzone_root(); + } + XBT_ATTRIB_DEPRECATED_v323( + "Please use Engine::netzone_by_name_or_null()") simgrid::s4u::NetZone* getNetzoneByNameOrNull(const char* name) + { + return netzone_by_name_or_null(name); + } + template + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::filter_netzones_by_type()") void getNetzoneByType( + std::vector* whereto) + { + filter_netzones_by_type_recursive(get_netzone_root(), whereto); + } + XBT_ATTRIB_DEPRECATED_v323("Please use Engine::get_instance()") static s4u::Engine* getInstance() { return get_instance(); @@ -236,10 +258,10 @@ extern XBT_PUBLIC xbt::signal on_time_advance; /** Callback fired when the time cannot jump because of inter-actors deadlock */ extern XBT_PUBLIC xbt::signal on_deadlock; -template XBT_PRIVATE void netzoneByTypeRecursive(s4u::NetZone* current, std::vector* whereto) +template XBT_PRIVATE void filter_netzones_by_type_recursive(s4u::NetZone* current, std::vector* whereto) { for (auto const& elem : *(current->getChildren())) { - netzoneByTypeRecursive(elem, whereto); + filter_netzones_by_type_recursive(elem, whereto); if (elem == dynamic_cast(elem)) whereto->push_back(dynamic_cast(elem)); } diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 2cea47fa07..fa9527efa2 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -35,7 +35,7 @@ container_t Container::getRoot() NetZoneContainer::NetZoneContainer(std::string name, unsigned int level, NetZoneContainer* father) : Container::Container(name, "", father) { - netpoint_ = simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(name); + netpoint_ = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name); xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); if (father_) { type_ = father_->type_->getOrCreateContainerType(std::string("L") + std::to_string(level)); @@ -51,7 +51,7 @@ RouterContainer::RouterContainer(std::string name, Container* father) : Containe { xbt_assert(father, "Only the Root container has no father"); - netpoint_ = simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(name); + netpoint_ = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name); xbt_assert(netpoint_, "Element '%s' not found", name.c_str()); trivaNodeTypes.insert(type_->get_name()); diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 26aed0e47c..2e13b1a0f1 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -241,8 +241,8 @@ static void instr_on_platform_created() currentContainer.clear(); std::set* filter = new std::set; XBT_DEBUG("Starting graph extraction."); - recursiveGraphExtraction(simgrid::s4u::Engine::get_instance()->getNetRoot(), simgrid::instr::Container::getRoot(), - filter); + recursiveGraphExtraction(simgrid::s4u::Engine::get_instance()->get_netzone_root(), + simgrid::instr::Container::getRoot(), filter); XBT_DEBUG("Graph extraction finished."); delete filter; TRACE_paje_dump_buffer(true); @@ -455,7 +455,7 @@ xbt_graph_t instr_routing_platform_graph() xbt_graph_t ret = xbt_graph_new_graph(0, nullptr); std::map* nodes = new std::map; std::map* edges = new std::map; - recursiveXBTGraphExtraction(ret, nodes, edges, simgrid::s4u::Engine::get_instance()->getNetRoot(), + recursiveXBTGraphExtraction(ret, nodes, edges, simgrid::s4u::Engine::get_instance()->get_netzone_root(), simgrid::instr::Container::getRoot()); delete nodes; delete edges; diff --git a/src/kernel/routing/NetPoint.cpp b/src/kernel/routing/NetPoint.cpp index 9246108db2..04f9a23496 100644 --- a/src/kernel/routing/NetPoint.cpp +++ b/src/kernel/routing/NetPoint.cpp @@ -35,5 +35,5 @@ NetPoint::NetPoint(std::string name, NetPoint::Type componentType, NetZoneImpl* */ simgrid::kernel::routing::NetPoint* sg_netpoint_by_name_or_null(const char* name) { - return simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(name); + return simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name); } diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 8c4f453d3c..0c3a7dcedd 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -28,7 +28,7 @@ public: NetZoneImpl::NetZoneImpl(NetZone* father, std::string name) : NetZone(father, name) { - xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(name.c_str()), + xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name.c_str()), "Refusing to create a second NetZone called '%s'.", name.c_str()); netpoint_ = new NetPoint(name, NetPoint::Type::NetZone, static_cast(father)); diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index 3364f033c7..8b32044991 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -84,8 +84,8 @@ void VivaldiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArg if (src->is_netzone()) { std::string srcName = "router_" + src->get_name(); std::string dstName = "router_" + dst->get_name(); - route->gw_src = simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(srcName.c_str()); - route->gw_dst = simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(dstName.c_str()); + route->gw_src = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(srcName.c_str()); + route->gw_dst = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(dstName.c_str()); } /* Retrieve the private links */ diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 9bcbae96a2..352e4eb79c 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -188,7 +188,8 @@ void Engine::run() } } -s4u::NetZone* Engine::getNetRoot() +/** @brief Retrieve the root netzone, containing all others */ +s4u::NetZone* Engine::get_netzone_root() { return pimpl->netzone_root_; } @@ -208,13 +209,13 @@ static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char } /** @brief Retrieve the NetZone of the given name (or nullptr if not found) */ -NetZone* Engine::getNetzoneByNameOrNull(const char* name) +NetZone* Engine::netzone_by_name_or_null(const char* name) { - return netzone_by_name_recursive(getNetRoot(), name); + return netzone_by_name_recursive(get_netzone_root(), name); } /** @brief Retrieve the netpoint of the given name (or nullptr if not found) */ -simgrid::kernel::routing::NetPoint* Engine::getNetpointByNameOrNull(std::string name) +simgrid::kernel::routing::NetPoint* Engine::netpoint_by_name_or_null(std::string name) { auto netp = pimpl->netpoints_.find(name); return netp == pimpl->netpoints_.end() ? nullptr : netp->second; diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index d805c8c828..5a60eeb44a 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -111,7 +111,7 @@ void NetZone::add_route(kernel::routing::NetPoint* /*src*/, kernel::routing::Net sg_netzone_t sg_zone_get_root() { - return simgrid::s4u::Engine::get_instance()->getNetRoot(); + return simgrid::s4u::Engine::get_instance()->get_netzone_root(); } const char* sg_zone_get_name(sg_netzone_t netzone) @@ -121,7 +121,7 @@ const char* sg_zone_get_name(sg_netzone_t netzone) sg_netzone_t sg_zone_get_by_name(const char* name) { - return simgrid::s4u::Engine::get_instance()->getNetzoneByNameOrNull(name); + return simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(name); } void sg_zone_get_sons(sg_netzone_t netzone, xbt_dict_t whereto) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 86cd770e03..c3c3562046 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -96,7 +96,7 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(std::string name, const if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base; - xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->getNetpointByNameOrNull(name), + xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name), "Refusing to create a router named '%s': this name already describes a node.", name.c_str()); simgrid::kernel::routing::NetPoint* netpoint = diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index be0c93d586..9e8f53489a 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -404,7 +404,7 @@ void STag_surfxml_prop() { if (ZONE_TAG) { // We need to retrieve the most recently opened zone XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value); - simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::get_instance()->getNetzoneByNameOrNull(A_surfxml_zone_id); + simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::get_instance()->netzone_by_name_or_null(A_surfxml_zone_id); netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value); } else { -- 2.20.1