1 /* Copyright (c) 2012, 2014-2017. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "src/instr/instr_private.hpp"
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)");
11 static simgrid::instr::Type* rootType = nullptr; /* the root type */
16 Type::Type(std::string name, std::string alias, std::string color, e_entity_types kind, Type* father)
17 : name_(name), color_(color), kind_(kind), father_(father)
19 if (name.empty() || alias.empty()) {
20 THROWF(tracing_error, 0, "can't create a new type with no name or alias");
23 id_ = std::to_string(instr_new_paje_id());
25 if (father != nullptr){
26 father->children_.insert({alias, this});
27 XBT_DEBUG("new type %s, child of %s", name_.c_str(), father->getCname());
33 for (auto elm : values_)
35 for (auto elm : children_)
39 Type* Type::byName(std::string name)
42 for (auto elm : children_) {
43 if (elm.second->name_ == name) {
45 THROWF (tracing_error, 0, "there are two children types with the same name?");
52 THROWF(tracing_error, 2, "type with name (%s) not found in father type (%s)", name.c_str(), getCname());
56 void Type::addEntityValue(std::string name)
58 addEntityValue(name, "");
61 void Type::addEntityValue(std::string name, std::string color)
64 THROWF(tracing_error, 0, "can't get a value with no name");
66 if (kind_ == TYPE_VARIABLE)
67 THROWF(tracing_error, 0, "variables can't have different values (%s)", getCname());
69 auto it = values_.find(name);
70 if (it == values_.end()) {
71 Value* new_val = new Value(name, color, this);
72 values_.insert({name, new_val});
73 XBT_DEBUG("new value %s, child of %s", name_.c_str(), getCname());
78 Value* Type::getEntityValue(std::string name)
80 auto ret = values_.find(name);
81 if (ret == values_.end()) {
82 THROWF(tracing_error, 2, "value with name (%s) not found in father type (%s)", name.c_str(), getCname());
87 Type* Type::createRootType()
89 simgrid::instr::Type* ret = new simgrid::instr::Type("0", "0", "", TYPE_CONTAINER, nullptr);
94 Type* Type::getRootType()
99 Type* Type::getOrCreateContainerType(std::string name)
101 auto it = children_.find(name);
102 if (it == children_.end()) {
103 Type* ret = new simgrid::instr::Type(name, name, "", TYPE_CONTAINER, this);
104 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
105 ret->logContainerTypeDefinition();
111 Type* Type::getOrCreateEventType(std::string name)
113 auto it = children_.find(name);
114 if (it == children_.end()) {
115 Type* ret = new Type(name, name, "", TYPE_EVENT, this);
116 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
117 ret->logDefineEventType();
124 Type* Type::getOrCreateVariableType(std::string name, std::string color)
126 auto it = children_.find(name);
127 if (it == children_.end()) {
128 Type* ret = new Type(name, name, color.empty() ? "1 1 1" : color, TYPE_VARIABLE, this);
130 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
131 ret->logVariableTypeDefinition();
138 Type* Type::getOrCreateLinkType(std::string name, Type* source, Type* dest)
140 std::string alias = name + "-" + source->id_ + "-" + dest->id_;
141 auto it = children_.find(alias);
142 if (it == children_.end()) {
143 Type* ret = new Type(name, alias, "", TYPE_LINK, this);
144 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->getCname(), ret->getId(), getCname(), getId(),
145 source->getCname(), source->getId(), dest->getCname(), dest->getId());
146 ret->logLinkTypeDefinition(source, dest);
152 Type* Type::getOrCreateStateType(std::string name)
154 auto it = children_.find(name);
155 if (it == children_.end()) {
156 Type* ret = new Type(name, name, "", TYPE_STATE, this);
157 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
158 ret->logStateTypeDefinition();