From: Arnaud Giersch Date: Thu, 18 Apr 2019 09:45:34 +0000 (+0200) Subject: Define PropertyHolder::set_properties. X-Git-Tag: v3.22.2~104 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c5652f475d35a3d6505bed5102ac5162e19044a2?ds=sidebyside Define PropertyHolder::set_properties. It allows to have a single simcall when setting many properties. --- diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index f4d75503e3..48870a8fce 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -100,6 +100,7 @@ public: const char* get_property(const std::string& key) const; void set_property(const std::string& key, const std::string& value); const std::unordered_map* get_properties() const; + void set_properties(const std::map& properties); void set_state_profile(kernel::profile::Profile* p); void set_speed_profile(kernel::profile::Profile* p); diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 9a646da55c..8b3f02d817 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -93,8 +93,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h /* Add properties */ if (properties != nullptr) - for (auto const& kv : *properties) - actor->set_property(kv.first, kv.second); + actor->set_properties(*properties); /* Add the process to it's host process list */ host->pimpl_->process_list_.push_back(*actor); @@ -487,8 +486,7 @@ ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode& /* Add properties */ if (properties != nullptr) - for (auto const& kv : *properties) - actor->set_property(kv.first, kv.second); + actor->set_properties(*properties); actor->start(code); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index babab5a07b..670720c3cf 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -105,8 +105,7 @@ simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount); if (props != nullptr) - for (auto const& kv : *props) - res->set_property(kv.first, kv.second); + res->set_properties(*props); simgrid::s4u::Host::on_creation(*res); // notify the signal diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 2af9129ccd..46d86bbf9e 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -180,6 +180,12 @@ void Host::set_property(const std::string& key, const std::string& value) { simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); }); } + +void Host::set_properties(const std::map& properties) +{ + simix::simcall([this, &properties] { this->pimpl_->set_properties(properties); }); +} + /** Specify a profile turning the host on and off according to a exhaustive list or a stochastic law. * The profile must contain boolean values. */ void Host::set_state_profile(kernel::profile::Profile* p) diff --git a/src/surf/PropertyHolder.cpp b/src/surf/PropertyHolder.cpp index 8b002a4c86..bf262b9e1e 100644 --- a/src/surf/PropertyHolder.cpp +++ b/src/surf/PropertyHolder.cpp @@ -5,6 +5,8 @@ #include "PropertyHolder.hpp" +#include + namespace simgrid { namespace surf { @@ -33,5 +35,22 @@ const std::unordered_map* PropertyHolder::get_properti return properties_.get(); } +/** @brief Change the value of the given keys in the property set */ +template void PropertyHolder::set_properties(const Assoc& properties) +{ + if (not properties_) + properties_.reset(new std::unordered_map); + std::unordered_map props(properties.cbegin(), properties.cend()); +#if __cplusplus >= 201703L + props.merge(properties_); +#else + props.insert(properties_->cbegin(), properties_->cend()); +#endif + properties_->swap(props); +} + +template void PropertyHolder::set_properties(const std::map& properties); +template void PropertyHolder::set_properties(const std::unordered_map& properties); + } /* namespace surf */ } /* namespace simgrid */ diff --git a/src/surf/PropertyHolder.hpp b/src/surf/PropertyHolder.hpp index 27ae7a627f..2c7cdceedf 100644 --- a/src/surf/PropertyHolder.hpp +++ b/src/surf/PropertyHolder.hpp @@ -28,6 +28,7 @@ public: void set_property(const std::string& id, const std::string& value); const std::unordered_map* get_properties(); + template void set_properties(const Assoc& properties); private: std::unique_ptr> properties_ = nullptr; diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e729a52c7b..3b46bc1529 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -115,8 +115,7 @@ static void sg_platf_new_link(simgrid::kernel::routing::LinkCreationArgs* link, surf_network_model->create_link(link_name, link->bandwidth, link->latency, link->policy); if (link->properties) { - for (auto const& elm : *link->properties) - l->set_property(elm.first, elm.second); + l->set_properties(*link->properties); } if (link->latency_trace) @@ -362,8 +361,7 @@ void sg_platf_new_storage(simgrid::kernel::routing::StorageCreationArgs* storage auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach); if (storage->properties) { - for (auto const& elm : *storage->properties) - s->set_property(elm.first, elm.second); + s->set_properties(*storage->properties); delete storage->properties; } }