Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Constify get_properties() and and remove simcalls.
[simgrid.git] / src / surf / PropertyHolder.cpp
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 #include "PropertyHolder.hpp"
7
8 namespace simgrid {
9 namespace surf {
10
11 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
12 const char* PropertyHolder::get_property(const std::string& key) const
13 {
14   if (not properties_)
15     return nullptr;
16   auto prop = properties_->find(key);
17   return prop == properties_->end() ? nullptr : prop->second.c_str();
18 }
19
20 /** @brief Change the value of a given key in the property set */
21 void PropertyHolder::set_property(const std::string& key, const std::string& value)
22 {
23   if (not properties_)
24     properties_.reset(new std::unordered_map<std::string, std::string>);
25   (*properties_)[key] = value;
26 }
27
28 /** @brief Return the whole set of properties. Don't mess with it, dude! */
29 const std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
30 {
31   if (not properties_)
32     properties_.reset(new std::unordered_map<std::string, std::string>);
33   return properties_.get();
34 }
35
36 } /* namespace surf */
37 } /* namespace simgrid */