It allows to have a single simcall when setting many properties.
const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
const std::unordered_map<std::string, std::string>* get_properties() const;
+ void set_properties(const std::map<std::string, std::string>& properties);
void set_state_profile(kernel::profile::Profile* p);
void set_speed_profile(kernel::profile::Profile* p);
/* 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);
/* Add properties */
if (properties != nullptr)
- for (auto const& kv : *properties)
- actor->set_property(kv.first, kv.second);
+ actor->set_properties(*properties);
actor->start(code);
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
{
simix::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
}
+
+void Host::set_properties(const std::map<std::string, std::string>& 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)
#include "PropertyHolder.hpp"
+#include <map>
+
namespace simgrid {
namespace surf {
return properties_.get();
}
+/** @brief Change the value of the given keys in the property set */
+template <class Assoc> void PropertyHolder::set_properties(const Assoc& properties)
+{
+ if (not properties_)
+ properties_.reset(new std::unordered_map<std::string, std::string>);
+ std::unordered_map<std::string, std::string> 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<std::string, std::string>& properties);
+template void PropertyHolder::set_properties(const std::unordered_map<std::string, std::string>& properties);
+
} /* namespace surf */
} /* namespace simgrid */
void set_property(const std::string& id, const std::string& value);
const std::unordered_map<std::string, std::string>* get_properties();
+ template <class Assoc> void set_properties(const Assoc& properties);
private:
std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
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)
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;
}
}