Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
new callback: s4u::onTimeAdvance
[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 "xbt/sysdep.h"
7 #include "PropertyHolder.hpp"
8
9 namespace simgrid {
10 namespace surf {
11
12 PropertyHolder::PropertyHolder() = default;
13
14 PropertyHolder::~PropertyHolder() {
15   xbt_dict_free(&properties_);
16 }
17
18 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
19 const char *PropertyHolder::getProperty(const char*key) {
20   if (properties_ == nullptr)
21     return nullptr;
22   return (const char*) xbt_dict_get_or_null(properties_,key);
23 }
24
25 /** @brief Change the value of a given key in the property set */
26 void PropertyHolder::setProperty(const char*key, const char*value) {
27   if (!properties_)
28     properties_ = xbt_dict_new_homogeneous(xbt_free_f);
29   xbt_dict_set(properties_, key, xbt_strdup(value), nullptr);
30 }
31
32 /** @brief Return the whole set of properties. Don't mess with it, dude! */
33 xbt_dict_t PropertyHolder::getProperties() {
34   if (!properties_)
35     properties_ = xbt_dict_new_homogeneous(xbt_free_f);
36   return properties_;
37 }
38
39 } /* namespace surf */
40 } /* namespace simgrid */