Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
API improvement in s4u
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 6 May 2017 21:31:04 +0000 (23:31 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 6 May 2017 21:31:04 +0000 (23:31 +0200)
include/simgrid/s4u/NetZone.hpp
src/bindings/java/jmsg_as.cpp
src/msg/msg_environment.cpp
src/s4u/s4u_netzone.cpp

index b3b3c18..b0accf1 100644 (file)
@@ -40,7 +40,6 @@ protected:
 
   explicit NetZone(NetZone * father, const char* name);
   virtual ~NetZone();
-  std::vector<Host*> 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<NetZone*>* children(); // Sub netzones
-  std::vector<Host*>* hosts(); // my content as a vector of hosts
+  void hosts(std::vector<s4u::Host*> * whereto); // retrieve my content as a vector of hosts
 
   /** Get the properties assigned to a host */
   std::unordered_map<std::string, std::string>* properties();
index cb796c4..09d996d 100644 (file)
@@ -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<sg_host_t>* table = as->hosts();
   if (!cls)
     return nullptr;
 
-  jtable = env->NewObjectArray(static_cast<jsize>(table->size()), cls, nullptr);
+  std::vector<sg_host_t> table;
+  as->hosts(&table);
+
+  jtable = env->NewObjectArray(static_cast<jsize>(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<jobject>(host->extension(JAVA_HOST_LEVEL));
     if (!jhost) {
       jname = env->NewStringUTF(host->cname());
index fb2c8ad..0dee03e 100644 (file)
@@ -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<simgrid::s4u::Host*> hosts;
+  netzone->hosts(&hosts);
+  for (auto host : hosts)
     xbt_dynar_push(whereto, &host);
-  }
 }
 
 SG_END_DECL()
index 17035d2..f539136 100644 (file)
@@ -71,15 +71,13 @@ NetZone* NetZone::father()
   return father_;
 }
 
-std::vector<s4u::Host*>* NetZone::hosts()
+void NetZone::hosts(std::vector<s4u::Host*>* 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)