Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define simgrid::xbt::Path to manage file names.
[simgrid.git] / src / surf / PropertyHolder.cpp
1 /* Copyright (c) 2015-2017. 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   auto prop = properties_->find(key);
20   return prop == properties_->end() ? nullptr : prop->second.c_str();
21 }
22
23 /** @brief Change the value of a given key in the property set */
24 void PropertyHolder::setProperty(std::string key, std::string value)
25 {
26   if (not properties_)
27     properties_       = new std::map<std::string, std::string>;
28   (*properties_)[key] = value;
29 }
30
31 /** @brief Return the whole set of properties. Don't mess with it, dude! */
32 std::map<std::string, std::string>* PropertyHolder::getProperties()
33 {
34   if (not properties_)
35     properties_ = new std::map<std::string, std::string>;
36   return properties_;
37 }
38
39 } /* namespace surf */
40 } /* namespace simgrid */