Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
more stringification/privatization
[simgrid.git] / src / instr / instr_paje_types.cpp
1 /* Copyright (c) 2012, 2014-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 "src/instr/instr_private.hpp"
8
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
10
11 static simgrid::instr::Type* rootType = nullptr; /* the root type */
12
13 simgrid::instr::Type* PJ_type_get_root()
14 {
15   return rootType;
16 }
17
18 simgrid::instr::Type::Type(std::string name, const char* key, std::string color, e_entity_types kind, Type* father)
19     : name_(name), color_(color), kind_(kind), father_(father)
20 {
21   if (name.empty() || key == nullptr) {
22     THROWF(tracing_error, 0, "can't create a new type with name or key equal nullptr");
23   }
24
25   this->id_ = std::to_string(instr_new_paje_id());
26
27   if (father != nullptr){
28     father->children_.insert({key, this});
29     XBT_DEBUG("new type %s, child of %s", name_.c_str(), father->getCname());
30   }
31 }
32
33 simgrid::instr::Type::~Type()
34 {
35   for (auto elm : values_) {
36     XBT_DEBUG("free value %s, child of %s", elm.second->getCname(), elm.second->father_->getCname());
37     delete elm.second;
38   }
39   for (auto elm : children_) {
40     delete elm.second;
41   }
42 }
43
44 simgrid::instr::Type* simgrid::instr::Type::getChild(std::string name)
45 {
46   simgrid::instr::Type* ret = this->getChildOrNull(name);
47   if (ret == nullptr)
48     THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name.c_str(), getCname());
49   return ret;
50 }
51
52 simgrid::instr::Type* simgrid::instr::Type::getChildOrNull(std::string name)
53 {
54   xbt_assert(not name.empty(), "can't get type with a nullptr name");
55
56   simgrid::instr::Type* ret = nullptr;
57   for (auto elm : children_) {
58     if (elm.second->name_ == name) {
59       if (ret != nullptr) {
60         THROWF (tracing_error, 0, "there are two children types with the same name?");
61       } else {
62         ret = elm.second;
63       }
64     }
65   }
66   return ret;
67 }
68
69 simgrid::instr::Type* simgrid::instr::Type::containerNew(const char* name, simgrid::instr::Type* father)
70 {
71   if (name == nullptr){
72     THROWF (tracing_error, 0, "can't create a container type with a nullptr name");
73   }
74
75   simgrid::instr::Type* ret = new simgrid::instr::Type(name, name, "", TYPE_CONTAINER, father);
76   if (father == nullptr) {
77     rootType = ret;
78   } else {
79     XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(),
80               father->getId());
81     LogContainerTypeDefinition(ret);
82   }
83   return ret;
84 }
85
86 simgrid::instr::Type* simgrid::instr::Type::eventNew(const char* name, simgrid::instr::Type* father)
87 {
88   if (name == nullptr){
89     THROWF (tracing_error, 0, "can't create an event type with a nullptr name");
90   }
91
92   Type* ret = new Type(name, name, "", TYPE_EVENT, father);
93   XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
94   LogDefineEventType(ret);
95   return ret;
96 }
97
98 simgrid::instr::Type* simgrid::instr::Type::variableNew(const char* name, std::string color,
99                                                         simgrid::instr::Type* father)
100 {
101   if (name == nullptr){
102     THROWF (tracing_error, 0, "can't create a variable type with a nullptr name");
103   }
104
105   Type* ret = nullptr;
106
107   if (color.empty()) {
108     char white[INSTR_DEFAULT_STR_SIZE] = "1 1 1";
109     ret = new Type (name, name, white, TYPE_VARIABLE, father);
110   }else{
111     ret = new Type (name, name, color, TYPE_VARIABLE, father);
112   }
113   XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
114   LogVariableTypeDefinition (ret);
115   return ret;
116 }
117
118 simgrid::instr::Type* simgrid::instr::Type::linkNew(const char* name, Type* father, Type* source, Type* dest)
119 {
120   if (name == nullptr){
121     THROWF (tracing_error, 0, "can't create a link type with a nullptr name");
122   }
123
124   char key[INSTR_DEFAULT_STR_SIZE];
125   snprintf(key, INSTR_DEFAULT_STR_SIZE, "%s-%s-%s", name, source->getId(), dest->getId());
126   Type* ret = new Type(name, key, "", TYPE_LINK, father);
127   XBT_DEBUG("LinkType %s(%s), child of %s(%s)  %s(%s)->%s(%s)", ret->getCname(), ret->getId(), father->getCname(),
128             father->getId(), source->getCname(), source->getId(), dest->getCname(), dest->getId());
129   LogLinkTypeDefinition(ret, source, dest);
130   return ret;
131 }
132
133 simgrid::instr::Type* simgrid::instr::Type::stateNew(const char* name, Type* father)
134 {
135   if (name == nullptr){
136     THROWF (tracing_error, 0, "can't create a state type with a nullptr name");
137   }
138
139   Type* ret = new Type(name, name, "", TYPE_STATE, father);
140   XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), father->getCname(), father->getId());
141   LogStateTypeDefinition(ret);
142   return ret;
143 }