Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compile src/instr with g++ so that we can use C++ constructs
[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 "src/instr/instr_private.h"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)");
10
11 val_t PJ_value_new (const char *name, const char *color, type_t father)
12 {
13   if (name == NULL || father == NULL){
14     THROWF (tracing_error, 0, "can't create a value with a NULL name (or a NULL father)");
15   }
16
17   val_t ret = xbt_new0(s_val_t, 1);
18   ret->name = xbt_strdup (name);
19   ret->father = father;
20   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   ret->id = xbt_strdup (str_id);
25
26   xbt_dict_set (father->values, name, ret, NULL);
27   XBT_DEBUG("new value %s, child of %s", ret->name, ret->father->name);
28   new_pajeDefineEntityValue(ret);
29   return ret;
30 }
31
32 val_t PJ_value_get_or_new (const char *name, const char *color, type_t father)
33 {
34   val_t ret = 0;
35   xbt_ex_t e;
36   TRY {
37     ret = PJ_value_get(name, father);
38   }
39   CATCH(e) {
40     xbt_ex_free(e);
41     ret = PJ_value_new(name, color, father);
42   }
43   return ret;
44 }
45
46 val_t PJ_value_get (const char *name, type_t father)
47 {
48   if (name == NULL || father == NULL){
49     THROWF (tracing_error, 0, "can't get a value with a NULL name (or a NULL father)");
50   }
51
52   if (father->kind == TYPE_VARIABLE)
53     THROWF(tracing_error, 0,
54            "variables can't have different values (%s)", father->name);
55   val_t ret = (val_t)xbt_dict_get_or_null (father->values, name);
56   if (ret == NULL) {
57     THROWF(tracing_error, 2,
58            "value with name (%s) not found in father type (%s)",
59            name, father->name);
60   }
61   return ret;
62 }
63
64 void PJ_value_free (val_t value)
65 {
66   XBT_DEBUG("free value %s, child of %s", value->name, value->father->name);
67   xbt_free(((val_t)value)->name);
68   xbt_free(((val_t)value)->color);
69   xbt_free(((val_t)value)->id);
70   xbt_free(value);
71 }