Logo AND Algorithmique Numérique Distribuée

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