Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
this field is useless indeed. Good catch CI
[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(std::string name, std::string color, simgrid::instr::Type* father) : father_(father)
14 {
15   if (name.empty() || father == nullptr) {
16     THROWF(tracing_error, 0, "can't create a value with no name (or a nullptr father)");
17   }
18   this->name_  = name;
19   this->color_ = color;
20   this->id_    = std::to_string(instr_new_paje_id());
21
22   xbt_dict_set(father->values_, name.c_str(), this, nullptr);
23   XBT_DEBUG("new value %s, child of %s", name_.c_str(), father_->name_);
24   print();
25 };
26
27 simgrid::instr::Value* simgrid::instr::Value::byNameOrCreate(std::string name, std::string color,
28                                                              simgrid::instr::Type* father)
29 {
30   Value* ret = 0;
31   try {
32     ret = Value::byName(name, father);
33   }
34   catch(xbt_ex& e) {
35     ret = new Value(name, color, father);
36   }
37   return ret;
38 }
39
40 simgrid::instr::Value* simgrid::instr::Value::byName(std::string name, Type* father)
41 {
42   if (name.empty() || father == nullptr) {
43     THROWF(tracing_error, 0, "can't get a value with no name (or a nullptr father)");
44   }
45
46   if (father->kind_ == TYPE_VARIABLE)
47     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->name_);
48   Value* ret = (Value*)xbt_dict_get_or_null(father->values_, name.c_str());
49   if (ret == nullptr) {
50     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), father->name_);
51   }
52   return ret;
53 }