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 */
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();
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");
}
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());
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()
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)