1 /* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved. */
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. */
6 #include <xbt/PropertyHolder.hpp>
14 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
15 const char* PropertyHolder::get_property(const std::string& key) const
19 auto prop = properties_->find(key);
20 return prop == properties_->end() ? nullptr : prop->second.c_str();
23 /** @brief Change the value of a given key in the property set */
24 void PropertyHolder::set_property(const std::string& key, const std::string& value)
27 properties_ = std::make_unique<std::unordered_map<std::string, std::string>>();
28 (*properties_)[key] = value;
31 /** @brief Return the whole set of properties. Don't mess with it, dude! */
32 const std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
35 properties_ = std::make_unique<std::unordered_map<std::string, std::string>>();
36 return properties_.get();
39 /** @brief Change the value of the given keys in the property set */
40 template <class Assoc> void PropertyHolder::set_properties(const Assoc& properties)
43 properties_ = std::make_unique<std::unordered_map<std::string, std::string>>();
44 std::unordered_map<std::string, std::string> props(std::cbegin(properties), std::cend(properties));
45 #if __cplusplus >= 201703L
46 props.merge(properties_);
48 props.insert(properties_->cbegin(), properties_->cend());
50 properties_->swap(props);
53 template void PropertyHolder::set_properties(const std::map<std::string, std::string, std::less<>>& properties);
54 template void PropertyHolder::set_properties(const std::unordered_map<std::string, std::string>& properties);
57 } // namespace simgrid