Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add Dragonfly topology. Use XC30's Cray description as a basis
[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 : properties_(props)
14 {
15 }
16
17 PropertyHolder::~PropertyHolder() {
18   xbt_dict_free(&properties_);
19 }
20
21 /** @brief Return the property associated to the provided key (or nullptr if not existing) */
22 const char *PropertyHolder::getProperty(const char*key) {
23   if (properties_ == nullptr)
24     return nullptr;
25   return (const char*) xbt_dict_get_or_null(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 (!properties_)
31     properties_ = xbt_dict_new();
32   xbt_dict_set(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 (!properties_)
38     properties_ = xbt_dict_new();
39   return properties_;
40 }
41
42 } /* namespace surf */
43 } /* namespace simgrid */