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 Type* Type::createRootType()
58 simgrid::instr::Type* ret = new simgrid::instr::Type("0", "0", "", TYPE_CONTAINER, nullptr);
63 Type* Type::getRootType()
68 Type* Type::getOrCreateContainerType(std::string name)
70 auto it = children_.find(name);
71 if (it == children_.end()) {
72 Type* ret = new simgrid::instr::Type(name, name, "", TYPE_CONTAINER, this);
73 XBT_DEBUG("ContainerType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
74 ret->logContainerTypeDefinition();
80 Type* Type::getOrCreateEventType(std::string name)
82 auto it = children_.find(name);
83 if (it == children_.end()) {
84 Type* ret = new Type(name, name, "", TYPE_EVENT, this);
85 XBT_DEBUG("EventType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
86 ret->logDefineEventType();
93 Type* Type::getOrCreateVariableType(std::string name, std::string color)
95 auto it = children_.find(name);
96 if (it == children_.end()) {
97 Type* ret = new Type(name, name, color.empty() ? "1 1 1" : color, TYPE_VARIABLE, this);
99 XBT_DEBUG("VariableType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
100 ret->logVariableTypeDefinition();
107 Type* Type::getOrCreateLinkType(std::string name, Type* source, Type* dest)
109 std::string alias = name + "-" + source->id_ + "-" + dest->id_;
110 auto it = children_.find(alias);
111 if (it == children_.end()) {
112 Type* ret = new Type(name, alias, "", TYPE_LINK, this);
113 XBT_DEBUG("LinkType %s(%s), child of %s(%s) %s(%s)->%s(%s)", ret->getCname(), ret->getId(), getCname(), getId(),
114 source->getCname(), source->getId(), dest->getCname(), dest->getId());
115 ret->logLinkTypeDefinition(source, dest);
121 Type* Type::getOrCreateStateType(std::string name)
123 auto it = children_.find(name);
124 if (it == children_.end()) {
125 Type* ret = new Type(name, name, "", TYPE_STATE, this);
126 XBT_DEBUG("StateType %s(%s), child of %s(%s)", ret->getCname(), ret->getId(), getCname(), getId());
127 ret->logStateTypeDefinition();