Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / instr / instr_paje_values.cpp
1 /* Copyright (c) 2012-2017. 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.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)");
12
13 simgrid::instr::Value::Value(const char* name, const char* color, simgrid::instr::Type* father) : father_(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->name_   = xbt_strdup(name);
19   this->color_  = xbt_strdup(color);
20
21   this->id_ = bprintf("%lld", instr_new_paje_id());
22
23   xbt_dict_set(father->values_, name, this, nullptr);
24   XBT_DEBUG("new value %s, child of %s", name_, father_->name_);
25   LogEntityValue(this);
26 };
27
28 simgrid::instr::Value::~Value()
29 {
30   xbt_free(name_);
31   xbt_free(color_);
32   xbt_free(id_);
33 }
34
35 simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const char* color,
36                                                          simgrid::instr::Type* father)
37 {
38   Value* ret = 0;
39   try {
40     ret = Value::get(name, father);
41   }
42   catch(xbt_ex& e) {
43     ret = new Value(name, color, father);
44   }
45   return ret;
46 }
47
48 simgrid::instr::Value* simgrid::instr::Value::get(const char* name, Type* father)
49 {
50   if (name == nullptr || father == nullptr){
51     THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
52   }
53
54   if (father->kind_ == TYPE_VARIABLE)
55     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name_);
56   Value* ret = (Value*)xbt_dict_get_or_null(father->values_, name);
57   if (ret == nullptr) {
58     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name_);
59   }
60   return ret;
61 }