Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
380f1c6a76c9120e2eb1917cfb9f55357e70d873
[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 #include "src/instr/instr_private.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)");
11
12 namespace simgrid {
13 namespace instr {
14
15 Value::Value(std::string name, std::string color, Type* father) : name_(name), color_(color), father_(father)
16 {
17   if (name.empty() || father == nullptr) {
18     THROWF(tracing_error, 0, "can't create a value with no name (or a nullptr father)");
19   }
20   this->id_    = std::to_string(instr_new_paje_id());
21
22   father->values_.insert({name, this});
23   XBT_DEBUG("new value %s, child of %s", name_.c_str(), father_->getCname());
24   print();
25 };
26
27 Value::~Value()
28 {
29   XBT_DEBUG("free value %s, child of %s", getCname(), father_->getCname());
30 }
31
32 Value* Value::byNameOrCreate(std::string name, std::string color, Type* father)
33 {
34   Value* ret = nullptr;
35   try {
36     ret = Value::byName(name, father);
37   } catch (xbt_ex& e) {
38     ret = new Value(name, color, father);
39   }
40   return ret;
41 }
42
43 Value* Value::byName(std::string name, Type* father)
44 {
45   if (name.empty() || father == nullptr) {
46     THROWF(tracing_error, 0, "can't get a value with no name (or a nullptr father)");
47   }
48
49   if (father->getKind() == TYPE_VARIABLE)
50     THROWF(tracing_error, 0, "variables can't have different values (%s)", father->getCname());
51   auto ret = father->values_.find(name);
52   if (ret == father->values_.end()) {
53     THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), father->getCname());
54   }
55   return ret->second;
56 }
57 }
58 }