Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove the argc/argv version of simcall_process_create
[simgrid.git] / src / surf / PropertyHolder.cpp
1 /* Copyright (c) 2015-2018. 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 PropertyHolder::~PropertyHolder() {
12   delete properties_;
13 }
14
15 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
16 const char* PropertyHolder::get_property(std::string key)
17 {
18   if (properties_ == nullptr)
19     return nullptr;
20   auto prop = properties_->find(key);
21   return prop == properties_->end() ? nullptr : prop->second.c_str();
22 }
23
24 /** @brief Change the value of a given key in the property set */
25 void PropertyHolder::set_property(std::string key, std::string value)
26 {
27   if (not properties_)
28     properties_ = new std::unordered_map<std::string, std::string>;
29   (*properties_)[key] = value;
30 }
31
32 /** @brief Return the whole set of properties. Don't mess with it, dude! */
33 std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
34 {
35   if (not properties_)
36     properties_ = new std::unordered_map<std::string, std::string>;
37   return properties_;
38 }
39
40 } /* namespace surf */
41 } /* namespace simgrid */