Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #202 from Takishipp/clear_fct
[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 s_val::s_val(const char *name, const char *color, type_t father){
14   if (name == nullptr || father == nullptr){
15     THROWF (tracing_error, 0, "can't create a value with a nullptr name (or a nullptr father)");
16   }
17   this->ret = xbt_new0(s_val, 1);
18   this->ret->name = xbt_strdup (name);
19   this->ret->father = father;
20   this->ret->color = xbt_strdup (color);
21
22   char str_id[INSTR_DEFAULT_STR_SIZE];
23   snprintf (str_id, INSTR_DEFAULT_STR_SIZE, "%lld", instr_new_paje_id());
24   this->ret->id = xbt_strdup (str_id);
25
26   xbt_dict_set (father->values, name, ret, nullptr);
27   XBT_DEBUG("new value %s, child of %s", ret->name, ret->father->name);
28   LogEntityValue(this->ret);
29 };
30
31 val_t s_val::PJ_value_get_or_new (const char *name, const char *color, type_t father)
32 {
33   val_t ret = 0;
34   try {
35     ret = s_val::PJ_value_get(name, father);
36   }
37   catch(xbt_ex& e) {
38     s_val rett(name, color, father);
39     ret = rett.ret;
40   }
41   return ret;
42 }
43
44 val_t s_val::PJ_value_get (const char *name, type_t father)
45 {
46   if (name == nullptr || father == nullptr){
47     THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
48   }
49
50   if (father->kind == TYPE_VARIABLE)
51     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name);
52   val_t ret = (val_t)xbt_dict_get_or_null (father->values, name);
53   if (ret == nullptr) {
54     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name);
55   }
56   return ret;
57 }