From 97649330a50bb45407df6b741a9126c24cc000af Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 6 May 2017 23:31:04 +0200 Subject: [PATCH 1/1] API improvement in s4u --- include/simgrid/s4u/NetZone.hpp | 3 +-- src/bindings/java/jmsg_as.cpp | 8 +++++--- src/msg/msg_environment.cpp | 5 +++-- src/s4u/s4u_netzone.cpp | 14 ++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index b3b3c18293..b0accf1e76 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -40,7 +40,6 @@ protected: explicit NetZone(NetZone * father, const char* name); virtual ~NetZone(); - std::vector hosts_; public: /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */ @@ -49,7 +48,7 @@ public: NetZone* father(); std::vector* children(); // Sub netzones - std::vector* hosts(); // my content as a vector of hosts + void hosts(std::vector * whereto); // retrieve my content as a vector of hosts /** Get the properties assigned to a host */ std::unordered_map* properties(); diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index cb796c4592..09d996d2e2 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -126,11 +126,13 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas); jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host"); - std::vector* table = as->hosts(); if (!cls) return nullptr; - jtable = env->NewObjectArray(static_cast(table->size()), cls, nullptr); + std::vector table; + as->hosts(&table); + + jtable = env->NewObjectArray(static_cast(table.size()), cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); @@ -138,7 +140,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo } int index = 0; - for (auto host : *table) { + for (auto host : table) { jhost = static_cast(host->extension(JAVA_HOST_LEVEL)); if (!jhost) { jname = env->NewStringUTF(host->cname()); diff --git a/src/msg/msg_environment.cpp b/src/msg/msg_environment.cpp index fb2c8ad742..0dee03e28c 100644 --- a/src/msg/msg_environment.cpp +++ b/src/msg/msg_environment.cpp @@ -82,9 +82,10 @@ void MSG_zone_set_property_value(msg_netzone_t netzone, const char* name, char* void MSG_zone_get_hosts(msg_netzone_t netzone, xbt_dynar_t whereto) { - for (auto host : *netzone->hosts()) { + std::vector hosts; + netzone->hosts(&hosts); + for (auto host : hosts) xbt_dynar_push(whereto, &host); - } } SG_END_DECL() diff --git a/src/s4u/s4u_netzone.cpp b/src/s4u/s4u_netzone.cpp index 17035d2189..f539136108 100644 --- a/src/s4u/s4u_netzone.cpp +++ b/src/s4u/s4u_netzone.cpp @@ -71,15 +71,13 @@ NetZone* NetZone::father() return father_; } -std::vector* NetZone::hosts() +void NetZone::hosts(std::vector* whereto) { - if (hosts_.empty()) // Lazy initialization - for (auto card : vertices_) { - s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name()); - if (host != nullptr) - hosts_.push_back(host); - } - return &hosts_; + for (auto card : vertices_) { + s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name()); + if (host != nullptr) + whereto->push_back(host); + } } int NetZone::addComponent(kernel::routing::NetPoint* elm) -- 2.20.1