Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a88589bbaf3c4df0615a4993445a7853183c282e
[simgrid.git] / src / surf / PropertyHolder.hpp
1 /* Copyright (c) 2015-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SRC_SURF_PROPERTYHOLDER_HPP_
7 #define SRC_SURF_PROPERTYHOLDER_HPP_
8
9 #include <memory>
10 #include <string>
11 #include <unordered_map>
12
13 namespace simgrid {
14 namespace surf {
15
16 /** @brief a PropertyHolder can be given a set of textual properties
17  *
18  * Common PropertyHolders are elements of the platform file, such as Host, Link or Storage.
19  */
20 class PropertyHolder { // DO NOT DERIVE THIS CLASS, or the diamond inheritance mayhem will get you
21
22 public:
23   PropertyHolder() = default;
24   PropertyHolder(const PropertyHolder&) = delete;
25   PropertyHolder& operator=(const PropertyHolder&) = delete;
26
27   const char* get_property(const std::string& key) const;
28   void set_property(const std::string& id, const std::string& value);
29
30   /* FIXME: This should not be exposed, as users may do bad things with the map they got (it's not a copy).
31    * But some user API expose this call so removing it is not so easy.
32    */
33   std::unordered_map<std::string, std::string>* get_properties();
34
35 private:
36   std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
37 };
38
39 } /* namespace surf */
40 } /* namespace simgrid */
41
42 #endif /* SRC_SURF_PROPERTYHOLDER_HPP_ */