Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a6696aee1ed40ca8a41a98a89b2fd3207d0cea78
[simgrid.git] / src / surf / PropertyHolder.cpp
1 /* Copyright (c) 2015. 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::getProperty(const char*key) {
17   if (properties_ == nullptr)
18     return nullptr;
19   try {
20     return properties_->at(key).c_str();
21   } catch (std::out_of_range& unfound) {
22     return nullptr;
23   }
24 }
25
26 /** @brief Change the value of a given key in the property set */
27 void PropertyHolder::setProperty(std::string key, std::string value)
28 {
29   if (not properties_)
30     properties_       = new std::map<std::string, std::string>;
31   (*properties_)[key] = value;
32 }
33
34 /** @brief Return the whole set of properties. Don't mess with it, dude! */
35 std::map<std::string, std::string>* PropertyHolder::getProperties()
36 {
37   if (not properties_)
38     properties_ = new std::map<std::string, std::string>;
39   return properties_;
40 }
41
42 } /* namespace surf */
43 } /* namespace simgrid */