Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0eaefe26fe20c47b6220ca922be1384bf0b4bea2
[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::get_or_new(const char* name, const char* color, type_t father)
33 {
34   value* ret = 0;
35   try {
36     ret = value::get(name, father);
37   }
38   catch(xbt_ex& e) {
39     value rett(name, color, father);
40     ret = rett.ret;
41   }
42   return ret;
43 }
44
45 value* value::get(const char* name, type_t father)
46 {
47   if (name == nullptr || father == nullptr){
48     THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
49   }
50
51   if (father->kind == TYPE_VARIABLE)
52     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name);
53   value* ret = (value*)xbt_dict_get_or_null(father->values, name);
54   if (ret == nullptr) {
55     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name);
56   }
57   return ret;
58 }