Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #218 from Takishipp/MSG2S4U
[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->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 simgrid::instr::Value::~Value()
33 {
34   /* FIXME: this should be cleanable
35   xbt_free(name);
36   xbt_free(color);
37   xbt_free(id);
38   */
39 }
40
41 simgrid::instr::Value* simgrid::instr::Value::get_or_new(const char* name, const char* color,
42                                                          simgrid::instr::Type* father)
43 {
44   Value* ret = 0;
45   try {
46     ret = Value::get(name, father);
47   }
48   catch(xbt_ex& e) {
49     Value rett(name, color, father);
50     ret = rett.ret_;
51   }
52   return ret;
53 }
54
55 simgrid::instr::Value* simgrid::instr::Value::get(const char* name, Type* father)
56 {
57   if (name == nullptr || father == nullptr){
58     THROWF (tracing_error, 0, "can't get a value with a nullptr name (or a nullptr father)");
59   }
60
61   if (father->kind_ == TYPE_VARIABLE)
62     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name_);
63   Value* ret = (Value*)xbt_dict_get_or_null(father->values_, name);
64   if (ret == nullptr) {
65     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name, father->name_);
66   }
67   return ret;
68 }