Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill dead code
[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(xbt_dict_t props)
13 : p_properties(props)
14 {
15 }
16
17 PropertyHolder::~PropertyHolder() {
18         xbt_dict_free(&p_properties);
19 }
20
21 /** @brief Return the property associated to the provided key (or NULL if not existing) */
22 const char *PropertyHolder::getProperty(const char*key) {
23         if (p_properties == NULL)
24                 return NULL;
25         return (const char*) xbt_dict_get_or_null(p_properties,key);
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 (!p_properties)
31                 p_properties = xbt_dict_new();
32         xbt_dict_set(p_properties, key, xbt_strdup(value), &xbt_free_f);
33 }
34
35 /** @brief Return the whole set of properties. Don't mess with it, dude! */
36 xbt_dict_t PropertyHolder::getProperties() {
37         if (!p_properties)
38                 p_properties = xbt_dict_new();
39         return p_properties;
40 }
41
42 } /* namespace surf */
43 } /* namespace simgrid */