Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add type_container_new to s_type class as method
[simgrid.git] / src / instr / instr_paje_values.cpp
1 /* Copyright (c) 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <xbt/ex.hpp>
8
9 #include "src/instr/instr_private.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)");
12
13 value::value(const char* name, const char* color, type_t father)
14 {
15   if (name == nullptr || father == nullptr){
16     THROWF (tracing_error, 0, "can't create a value with a nullptr name (or a nullptr father)");
17   }
18   this->ret         = xbt_new0(value, 1);
19   this->ret->name = xbt_strdup (name);
20   this->ret->father = father;
21   this->ret->color = xbt_strdup (color);
22
23   char str_id[INSTR_DEFAULT_STR_SIZE];
24   snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
25   this->ret->id = xbt_strdup (str_id);
26
27   xbt_dict_set (father->values, name, ret, nullptr);
28   XBT_DEBUG("new value %s, child of %s", ret->name, ret->father->name);
29   LogEntityValue(this->ret);
30 };
31
32 value::~value()
33 {
34   /* FIXME: this should be cleanable
35   xbt_free(name);
36   xbt_free(color);
37   xbt_free(id);
38   */
39 }
40
41 value* value::get_or_new(const char* name, const char* color, type_t father)
42 {
43   value* ret = 0;
44   try {
45     ret = value::get(name, father);
46   }
47   catch(xbt_ex& e) {
48     value rett(name, color, father);
49     ret = rett.ret;
50   }
51   return ret;
52 }
53
54 value* value::get(const char* name, type_t father)
55 {
56   if (name == nullptr || father == nullptr){
57     THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
58   }
59
60   if (father->kind == TYPE_VARIABLE)
61     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name);
62   value* ret = (value*)xbt_dict_get_or_null(father->values, name);
63   if (ret == nullptr) {
64     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name);
65   }
66   return ret;
67 }