From 53300623ffc4a530dedcc517d559926ea0891edf Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 10 Jun 2018 17:17:53 +0200 Subject: [PATCH] further snake_case NetZone --- .../s4u-routing-get-clusters.cpp | 6 +- include/simgrid/s4u/NetZone.hpp | 59 ++++++++++++------- src/kernel/routing/ClusterZone.cpp | 2 +- src/kernel/routing/NetPoint.cpp | 2 +- src/kernel/routing/RoutedZone.cpp | 2 +- src/s4u/s4u_Netzone.cpp | 23 ++++++-- 6 files changed, 62 insertions(+), 32 deletions(-) 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 8f7f6220e6..21b583774f 100644 --- a/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp +++ b/examples/s4u/routing-get-clusters/s4u-routing-get-clusters.cpp @@ -19,11 +19,9 @@ int main(int argc, char* argv[]) for (auto c : clusters) { XBT_INFO("%s", c->get_cname()); - std::vector* hosts = new std::vector; - c->getHosts(hosts); - for (auto h : *hosts) + std::vector hosts = c->get_all_hosts(); + for (auto h : hosts) XBT_INFO(" %s", h->get_cname()); - delete hosts; } std::vector dragonfly_clusters = diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index d8e242b718..4b485bb049 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -39,23 +39,24 @@ public: const char* get_cname() const; NetZone* get_father(); + std::vector get_all_hosts(); + std::vector* getChildren(); // Sub netzones - void getHosts(std::vector * whereto); // retrieve my content as a vector of hosts int getHostCount(); private: std::unordered_map properties_; public: - /** Get the properties assigned to a host */ - std::unordered_map* getProperties(); + /** Get the properties assigned to a netzone */ + std::unordered_map* get_properties(); /** Retrieve the property value (or nullptr if not set) */ const char* get_property(const char* key); void set_property(const char* key, const char* value); /* Add content to the netzone, at parsing time. It should be sealed afterward. */ - virtual int addComponent(kernel::routing::NetPoint * elm); /* A host, a router or a netzone, whatever */ + virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, std::vector& link_list, bool symmetrical); @@ -71,7 +72,23 @@ public: static simgrid::xbt::signal on_creation; static simgrid::xbt::signal on_seal; - // Deprecation wrappers +private: + // our content, as known to our graph routing algorithm (maps vertexId -> vertex) + std::vector vertices_; + +protected: + unsigned int get_table_size() { return vertices_.size(); } + std::vector get_vertices() { return vertices_; } + +private: + NetZone* father_ = nullptr; + std::string name_; + + bool sealed_ = false; // We cannot add more content when sealed + + std::vector* children_ = nullptr; // sub-netzones + +public: // Deprecation wrappers XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); } XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_name()") const std::string& getName() const { return get_name(); } XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_cname()") const char* getCname() const { return get_cname(); } @@ -87,6 +104,11 @@ public: { add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical); } + XBT_ATTRIB_DEPRECATED_v323( + "Please use NetZone::get_properties()") std::unordered_map* getProperties() + { + return get_properties(); + } XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_property()") const char* getProperty(const char* key) { return get_property(key); @@ -95,22 +117,17 @@ public: { set_property(key, value); } - -private: - // our content, as known to our graph routing algorithm (maps vertexId -> vertex) - std::vector vertices_; - -protected: - unsigned int get_table_size() { return vertices_.size(); } - std::vector getVertices() { return vertices_; } - -private: - NetZone* father_ = nullptr; - std::string name_; - - bool sealed_ = false; // We cannot add more content when sealed - - std::vector* children_ = nullptr; // sub-netzones + XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_component()") virtual int addComponent( + kernel::routing::NetPoint* elm) + { + return add_component(elm); + } + XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_vertices()") std::vector getVertices() + { + return get_vertices(); + } + XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_all_hosts()") void getHosts( + std::vector* whereto); // retrieve my content as a vector of hosts }; } }; // Namespace simgrid::s4u diff --git a/src/kernel/routing/ClusterZone.cpp b/src/kernel/routing/ClusterZone.cpp index 26c7a1e75e..3013d78454 100644 --- a/src/kernel/routing/ClusterZone.cpp +++ b/src/kernel/routing/ClusterZone.cpp @@ -89,7 +89,7 @@ void ClusterZone::get_graph(xbt_graph_t graph, std::map new_xbt_graph_edge(graph, routerNode, backboneNode, edges); } - for (auto const& src : getVertices()) { + for (auto const& src : get_vertices()) { if (not src->is_router()) { xbt_node_t previous = new_xbt_graph_node(graph, src->get_cname(), nodes); diff --git a/src/kernel/routing/NetPoint.cpp b/src/kernel/routing/NetPoint.cpp index 04f9a23496..6326cf27a9 100644 --- a/src/kernel/routing/NetPoint.cpp +++ b/src/kernel/routing/NetPoint.cpp @@ -19,7 +19,7 @@ NetPoint::NetPoint(std::string name, NetPoint::Type componentType, NetZoneImpl* : name_(name), component_type_(componentType), englobing_zone_(netzone_p) { if (netzone_p != nullptr) - id_ = netzone_p->addComponent(this); + id_ = netzone_p->add_component(this); else id_ = static_cast(-1); simgrid::s4u::Engine::get_instance()->netpoint_register(this); diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index f6585e638c..2de68c1f99 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -66,7 +66,7 @@ RoutedZone::RoutedZone(NetZone* father, std::string name) : NetZoneImpl(father, void RoutedZone::get_graph(xbt_graph_t graph, std::map* nodes, std::map* edges) { - std::vector vertices = getVertices(); + std::vector vertices = get_vertices(); for (auto const& my_src : vertices) { for (auto const& my_dst : vertices) { diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index a46eb0a371..a01bd946c5 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -38,7 +38,7 @@ NetZone::~NetZone() delete children_; } -std::unordered_map* NetZone::getProperties() +std::unordered_map* NetZone::get_properties() { return simgrid::simix::simcall([this] { return &properties_; }); } @@ -71,6 +71,22 @@ NetZone* NetZone::get_father() return father_; } +/** @brief Returns the list of the hosts found in this NetZone (not recursively) + * + * Only the hosts that are directly contained in this NetZone are retrieved, + * not the ones contained in sub-netzones. + */ +std::vector NetZone::get_all_hosts() +{ + std::vector res; + for (auto const& card : vertices_) { + s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name()); + if (host != nullptr) + res.push_back(host); + } + return res; +} + void NetZone::getHosts(std::vector* whereto) { for (auto const& card : vertices_) { @@ -91,7 +107,7 @@ int NetZone::getHostCount() return count; } -int NetZone::addComponent(kernel::routing::NetPoint* elm) +int NetZone::add_component(kernel::routing::NetPoint* elm) { vertices_.push_back(elm); return vertices_.size() - 1; // The rank of the newly created object @@ -144,8 +160,7 @@ void sg_zone_set_property_value(sg_netzone_t netzone, const char* name, char* va void sg_zone_get_hosts(sg_netzone_t netzone, xbt_dynar_t whereto) { /* converts vector to dynar */ - std::vector hosts; - netzone->getHosts(&hosts); + std::vector hosts = netzone->get_all_hosts(); for (auto const& host : hosts) xbt_dynar_push(whereto, &host); } -- 2.20.1