Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move ugly dict closer to the C APIs
[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() = default;
12
13 PropertyHolder::~PropertyHolder() {
14   delete properties_;
15 }
16
17 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
18 const char *PropertyHolder::getProperty(const char*key) {
19   if (properties_ == nullptr)
20     return nullptr;
21   try {
22     return properties_->at(key).c_str();
23   } catch (std::out_of_range& unfound) {
24     return nullptr;
25   }
26 }
27
28 /** @brief Change the value of a given key in the property set */
29 void PropertyHolder::setProperty(const char*key, const char*value) {
30   if (not properties_)
31     properties_       = new std::unordered_map<std::string, std::string>;
32   (*properties_)[key] = value;
33 }
34
35 /** @brief Return the whole set of properties. Don't mess with it, dude! */
36 std::unordered_map<std::string, std::string>* PropertyHolder::getProperties()
37 {
38   if (not properties_)
39     properties_ = new std::unordered_map<std::string, std::string>;
40   return properties_;
41 }
42
43 } /* namespace surf */
44 } /* namespace simgrid */