From: Frederic Suter Date: Mon, 9 Dec 2019 16:15:48 +0000 (+0100) Subject: tidy up PropertyHolder X-Git-Tag: v3.25~314 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5a4bab52900d62dfd3dec063ece907974899db09 tidy up PropertyHolder + change namespace + move files + use it for netzones too --- diff --git a/MANIFEST.in b/MANIFEST.in index cd3d19a7b3..9cc9214314 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1993,6 +1993,7 @@ include include/smpi/smpi_helpers_internal.h include include/smpi/smpi_main.h include include/xbt.h include include/xbt/Extendable.hpp +include include/xbt/PropertyHolder.hpp include include/xbt/asserts.h include include/xbt/automaton.h include include/xbt/automaton.hpp @@ -2513,8 +2514,6 @@ include src/smpi/smpirun.in include src/smpi/smpitools.sh include src/surf/HostImpl.cpp include src/surf/HostImpl.hpp -include src/surf/PropertyHolder.cpp -include src/surf/PropertyHolder.hpp include src/surf/StorageImpl.cpp include src/surf/StorageImpl.hpp include src/surf/cpu_cas01.cpp @@ -2560,6 +2559,7 @@ include src/surf/xml/simgrid_dtd.h include src/surf/xml/surfxml_parseplatf.cpp include src/surf/xml/surfxml_sax_cb.cpp include src/xbt/OsSemaphore.hpp +include src/xbt/PropertyHolder.cpp include src/xbt/automaton/automaton.c include src/xbt/automaton/automaton_lexer.yy.c include src/xbt/automaton/automatonparse_promela.c diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index 4b0754414e..4c48344f96 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -47,8 +48,8 @@ class BypassRoute; * called Autonomous Systems in this article). * */ -class XBT_PUBLIC NetZoneImpl { - friend simgrid::kernel::EngineImpl; // it destroys netRoot_ +class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder { + friend EngineImpl; // it destroys netRoot_ protected: explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model); @@ -60,8 +61,8 @@ public: s4u::NetZone* get_iface() { return &piface_; } /** @brief Make a host within that NetZone */ - simgrid::s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate, int core_count, - const std::map* props); + s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate, int core_count, + const std::map* props); /** @brief Creates a new route in this NetZone */ virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, std::vector& link_list, bool symmetrical); diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 609542f022..e95407be73 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -44,18 +44,16 @@ public: private: kernel::routing::NetZoneImpl* const pimpl_; - std::unordered_map properties_; public: /** Get the properties assigned to a netzone */ const std::unordered_map* get_properties() const; - - std::vector get_children(); - /** Retrieve the property value (or nullptr if not set) */ const char* get_property(const std::string& key) const; void set_property(const std::string& key, const std::string& value); + std::vector get_children(); + /* Add content to the netzone, at parsing time. It should be sealed afterward. */ int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src, diff --git a/src/surf/PropertyHolder.hpp b/include/xbt/PropertyHolder.hpp similarity index 83% rename from src/surf/PropertyHolder.hpp rename to include/xbt/PropertyHolder.hpp index 2c7cdceedf..763fd29a84 100644 --- a/src/surf/PropertyHolder.hpp +++ b/include/xbt/PropertyHolder.hpp @@ -3,15 +3,15 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#ifndef SRC_SURF_PROPERTYHOLDER_HPP_ -#define SRC_SURF_PROPERTYHOLDER_HPP_ +#ifndef XBT_PROPERTYHOLDER_HPP +#define XBT_PROPERTYHOLDER_HPP #include #include #include namespace simgrid { -namespace surf { +namespace xbt { /** @brief a PropertyHolder can be given a set of textual properties * @@ -20,7 +20,7 @@ namespace surf { class PropertyHolder { // DO NOT DERIVE THIS CLASS, or the diamond inheritance mayhem will get you public: - PropertyHolder() = default; + PropertyHolder() = default; PropertyHolder(const PropertyHolder&) = delete; PropertyHolder& operator=(const PropertyHolder&) = delete; @@ -34,7 +34,7 @@ private: std::unique_ptr> properties_ = nullptr; }; -} /* namespace surf */ -} /* namespace simgrid */ +} // namespace xbt +} // namespace simgrid -#endif /* SRC_SURF_PROPERTYHOLDER_HPP_ */ +#endif diff --git a/src/kernel/actor/ActorImpl.hpp b/src/kernel/actor/ActorImpl.hpp index 831fb73654..c0883ae97d 100644 --- a/src/kernel/actor/ActorImpl.hpp +++ b/src/kernel/actor/ActorImpl.hpp @@ -8,7 +8,7 @@ #include "simgrid/s4u/Actor.hpp" #include "src/simix/popping_private.hpp" -#include "src/surf/PropertyHolder.hpp" +#include "xbt/PropertyHolder.hpp" #include #include #include @@ -19,7 +19,7 @@ namespace simgrid { namespace kernel { namespace actor { -class XBT_PUBLIC ActorImpl : public surf::PropertyHolder { +class XBT_PUBLIC ActorImpl : public xbt::PropertyHolder { s4u::Host* host_ = nullptr; /* the host on which the actor is running */ // XBT_DEPRECATED_v329 void* userdata_ = nullptr; /* kept for compatibility, it should be replaced with moddata */ diff --git a/src/kernel/resource/DiskImpl.hpp b/src/kernel/resource/DiskImpl.hpp index 269a3607d8..9ce6640235 100644 --- a/src/kernel/resource/DiskImpl.hpp +++ b/src/kernel/resource/DiskImpl.hpp @@ -8,8 +8,8 @@ #include "simgrid/kernel/resource/Resource.hpp" #include "simgrid/s4u/Disk.hpp" #include "simgrid/s4u/Io.hpp" -#include "src/surf/PropertyHolder.hpp" #include "src/surf/surf_interface.hpp" +#include #include @@ -47,7 +47,7 @@ public: /************ * Resource * ************/ -class DiskImpl : public Resource, public surf::PropertyHolder { +class DiskImpl : public Resource, public xbt::PropertyHolder { bool currently_destroying_ = false; s4u::Host* host_ = nullptr; s4u::Disk piface_; diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index 807bf42da0..b5cdbce1c9 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -21,19 +21,18 @@ xbt::signal NetZone::on_seal; const std::unordered_map* NetZone::get_properties() const { - return &properties_; + return pimpl_->get_properties(); } /** Retrieve the property value (or nullptr if not set) */ const char* NetZone::get_property(const std::string& key) const { - auto prop = properties_.find(key); - return prop == properties_.end() ? nullptr : prop->second.c_str(); + return pimpl_->get_property(key); } void NetZone::set_property(const std::string& key, const std::string& value) { - kernel::actor::simcall([this, &key, &value] { properties_[key] = value; }); + kernel::actor::simcall([this, &key, &value] { pimpl_->set_property(key, value); }); } /** @brief Returns the list of direct children (no grand-children) */ diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 0aef460423..d48e4bb14e 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -8,10 +8,10 @@ #include "src/kernel/actor/ActorImpl.hpp" #include "src/kernel/resource/DiskImpl.hpp" -#include "src/surf/PropertyHolder.hpp" #include "src/surf/StorageImpl.hpp" #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" +#include #include @@ -42,7 +42,7 @@ public: * @brief SURF Host interface class * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage */ -class XBT_PRIVATE HostImpl : public simgrid::surf::PropertyHolder { +class XBT_PRIVATE HostImpl : public xbt::PropertyHolder { std::vector actors_at_boot_; s4u::Host* piface_ = nullptr; // FIXME: why don't we store a s4u::Host here as we do everywhere else? diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index bd885d0847..338268c3f1 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -8,8 +8,8 @@ #include "simgrid/kernel/resource/Resource.hpp" #include "simgrid/s4u/Io.hpp" #include "simgrid/s4u/Storage.hpp" -#include "src/surf/PropertyHolder.hpp" #include "surf_interface.hpp" +#include "xbt/PropertyHolder.hpp" #include @@ -59,7 +59,7 @@ public: * @brief SURF storage interface class * @details A Storage represent a storage unit (e.g.: hard drive, usb key) */ -class StorageImpl : public Resource, public surf::PropertyHolder { +class StorageImpl : public Resource, public xbt::PropertyHolder { s4u::Storage piface_; public: diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index d5ecd179b0..69fbcb2cf8 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -10,7 +10,7 @@ #include "simgrid/kernel/resource/Resource.hpp" #include "simgrid/s4u/Link.hpp" #include "src/kernel/lmm/maxmin.hpp" -#include "src/surf/PropertyHolder.hpp" +#include #include #include @@ -107,7 +107,7 @@ public: * @brief SURF network link interface class * @details A Link represents the link between two [hosts](@ref simgrid::surf::HostImpl) */ -class LinkImpl : public Resource, public surf::PropertyHolder { +class LinkImpl : public Resource, public xbt::PropertyHolder { bool currently_destroying_ = false; s4u::Link piface_; diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 318a7194a8..e57d0d022e 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -646,8 +646,8 @@ void sg_platf_new_Zone_set_properties(std::unordered_mapbegin(); kv != props->end(); ++kv) - current_routing->get_iface()->set_property(kv->first, kv->second); + if (props) + current_routing->set_properties(*props); } /** diff --git a/src/surf/PropertyHolder.cpp b/src/xbt/PropertyHolder.cpp similarity index 95% rename from src/surf/PropertyHolder.cpp rename to src/xbt/PropertyHolder.cpp index bf262b9e1e..8b62106b8c 100644 --- a/src/surf/PropertyHolder.cpp +++ b/src/xbt/PropertyHolder.cpp @@ -3,12 +3,12 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "PropertyHolder.hpp" +#include #include namespace simgrid { -namespace surf { +namespace xbt { /** @brief Return the property associated to the provided key (or nullptr if not existing) */ const char* PropertyHolder::get_property(const std::string& key) const @@ -52,5 +52,5 @@ template void PropertyHolder::set_properties(const Assoc& properti template void PropertyHolder::set_properties(const std::map& properties); template void PropertyHolder::set_properties(const std::unordered_map& properties); -} /* namespace surf */ -} /* namespace simgrid */ +} // namespace xbt +} // namespace simgrid diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 3db1ff93f8..725e75df24 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -55,7 +55,6 @@ set(EXTRA_DIST src/surf/storage_n11.hpp src/surf/surf_interface.hpp src/surf/surf_private.hpp - src/surf/PropertyHolder.hpp src/surf/host_clm03.hpp src/surf/HostImpl.hpp src/surf/ptask_L07.hpp @@ -284,6 +283,7 @@ set(XBT_SRC src/xbt/memory_map.cpp src/xbt/memory_map.hpp src/xbt/OsSemaphore.hpp + src/xbt/PropertyHolder.cpp src/xbt/parmap.cpp src/xbt/random.cpp src/xbt/snprintf.c @@ -353,7 +353,6 @@ set(SURF_SRC src/surf/network_constant.cpp src/surf/network_interface.cpp src/surf/network_wifi.cpp - src/surf/PropertyHolder.cpp src/surf/sg_platf.cpp src/surf/StorageImpl.cpp src/surf/storage_n11.cpp @@ -776,6 +775,7 @@ set(headers_to_install include/xbt/mallocator.h include/xbt/misc.h include/xbt/module.h + include/xbt/PropertyHolder.hpp include/xbt/parmap.h include/xbt/range.hpp include/xbt/random.hpp