Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a0b4a1adf0866ea4bb453b7da9d12eac4f1fa131
[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 simgrid::instr::Value::Value(const char* name, const char* color, simgrid::instr::Type* 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->father_ = father;
20   this->color_  = xbt_strdup(color);
21
22   this->id_ = bprintf("%lld", instr_new_paje_id());
23
24   xbt_dict_set(father->values_, name, this, nullptr);
25   XBT_DEBUG("new value %s, child of %s", name_, father_->name_);
26   LogEntityValue(this);
27 };
28
29 simgrid::instr::Value::~Value()
30 {
31   xbt_free(name_);
32   xbt_free(color_);
33   xbt_free(id_);
34 }
35
36 simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const char* color,
37                                                          simgrid::instr::Type* father)
38 {
39   Value* ret = 0;
40   try {
41     ret = Value::get(name, father);
42   }
43   catch(xbt_ex& e) {
44     ret = new Value(name, color, father);
45   }
46   return ret;
47 }
48
49 simgrid::instr::Value* simgrid::instr::Value::get(const char* name, Type* father)
50 {
51   if (name == nullptr || father == nullptr){
52     THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
53   }
54
55   if (father->kind_ == TYPE_VARIABLE)
56     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name_);
57   Value* ret = (Value*)xbt_dict_get_or_null(father->values_, name);
58   if (ret == nullptr) {
59     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name_);
60   }
61   return ret;
62 }