1 /* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef INSTR_PAJE_TYPES_HPP
7 #define INSTR_PAJE_TYPES_HPP
9 #include "src/instr/instr_private.hpp"
24 std::map<std::string, std::unique_ptr<Type>> children_;
25 Container* issuer_ = nullptr;
28 Container* get_issuer() const { return issuer_; }
31 static xbt::signal<void(Type const&, e_event_type event_type)> on_creation;
33 Type(e_event_type event_type, const std::string& name, const std::string& alias, const std::string& color,
35 virtual ~Type() = default;
37 long long int get_id() const { return id_; }
38 const std::string& get_name() const { return name_; }
39 const char* get_cname() const { return name_.c_str(); }
40 const std::string& get_color() const { return color_; }
41 Type* get_father() const { return father_; }
42 const std::map<std::string, std::unique_ptr<Type>>& get_children() const { return children_; }
43 bool is_colored() const { return not color_.empty(); }
45 Type* by_name(const std::string& name);
46 LinkType* by_name_or_create(const std::string& name, Type* source, Type* dest);
47 VariableType* by_name_or_create(const std::string& name, const std::string& color);
49 template <class T> T* by_name_or_create(const std::string& name)
51 auto cont = children_.find(name);
52 return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
55 Type* set_calling_container(Container* container)
62 class ContainerType : public Type {
64 explicit ContainerType(const std::string& name) : Type(PAJE_DefineContainerType, name, name, "", nullptr){};
65 ContainerType(const std::string& name, Type* father) : Type(PAJE_DefineContainerType, name, name, "", father){};
68 class VariableType : public Type {
69 std::vector<VariableEvent*> events_;
71 VariableType(const std::string& name, const std::string& color, Type* father)
72 : Type(PAJE_DefineVariableType, name, name, color, father)
75 void instr_event(double now, double delta, const char* resource, double value);
76 void set_event(double timestamp, double value);
77 void add_event(double timestamp, double value);
78 void sub_event(double timestamp, double value);
81 class ValueType : public Type {
83 std::map<std::string, EntityValue> values_;
84 ValueType(e_event_type event_type, const std::string& name, const std::string& alias, Type* father)
85 : Type(event_type, name, alias, "", father){};
86 ValueType(e_event_type event_type, const std::string& name, Type* father)
87 : Type(event_type, name, name, "", father){};
88 ~ValueType() override = default;
89 void add_entity_value(const std::string& name, const std::string& color);
90 void add_entity_value(const std::string& name);
91 EntityValue* get_entity_value(const std::string& name);
94 class LinkType : public ValueType {
96 static xbt::signal<void(LinkType const&, Type const&, Type const&)> on_creation;
97 LinkType(const std::string& name, Type* source, Type* dest, const std::string& alias, Type* father)
98 : ValueType(PAJE_DefineLinkType, name, alias, father)
100 on_creation(*this, *source, *dest);
102 void start_event(Container* startContainer, const std::string& value, const std::string& key);
103 void start_event(Container* startContainer, const std::string& value, const std::string& key, int size);
104 void end_event(Container* endContainer, const std::string& value, const std::string& key);
107 class EventType : public ValueType {
109 EventType(const std::string& name, Type* father) : ValueType(PAJE_DefineEventType, name, father) {}
112 class StateType : public ValueType {
113 std::vector<StateEvent*> events_;
115 StateType(const std::string& name, Type* father) : ValueType(PAJE_DefineStateType, name, father) {}
116 void set_event(const std::string& value_name);
117 void push_event(const std::string& value_name);
118 void push_event(const std::string& value_name, TIData* extra);
120 void pop_event(TIData* extra);
123 } // namespace simgrid