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"
26 static xbt::signal<void(Type&, e_event_type event_type)> on_creation;
27 std::map<std::string, std::unique_ptr<Type>> children_;
28 Container* issuer_ = nullptr;
30 Type(e_event_type event_type, const std::string& name, const std::string& alias, const std::string& color,
32 virtual ~Type() = default;
34 long long int get_id() { return id_; }
35 const std::string& get_name() const { return name_; }
36 const char* get_cname() { return name_.c_str(); }
37 const std::string& get_color() const { return color_; }
38 Type* get_father() const { return father_; }
39 bool is_colored() { return not color_.empty(); }
41 Type* by_name(const std::string& name);
42 LinkType* by_name_or_create(const std::string& name, Type* source, Type* dest);
43 VariableType* by_name_or_create(const std::string& name, const std::string& color);
45 template <class T> T* by_name_or_create(const std::string& name)
47 auto cont = children_.find(name);
48 return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
51 Type* set_calling_container(Container* container)
58 class ContainerType : public Type {
60 explicit ContainerType(const std::string& name) : Type(PAJE_DefineContainerType, name, name, "", nullptr){};
61 ContainerType(const std::string& name, Type* father) : Type(PAJE_DefineContainerType, name, name, "", father){};
64 class VariableType : public Type {
65 std::vector<VariableEvent*> events_;
67 VariableType(const std::string& name, const std::string& color, Type* father)
68 : Type(PAJE_DefineVariableType, name, name, color, father)
71 void instr_event(double now, double delta, const char* resource, double value);
72 void set_event(double timestamp, double value);
73 void add_event(double timestamp, double value);
74 void sub_event(double timestamp, double value);
77 class ValueType : public Type {
79 std::map<std::string, EntityValue> values_;
80 ValueType(e_event_type event_type, const std::string& name, const std::string& alias, Type* father)
81 : Type(event_type, name, alias, "", father){};
82 ValueType(e_event_type event_type, const std::string& name, Type* father)
83 : Type(event_type, name, name, "", father){};
84 virtual ~ValueType() = default;
85 void add_entity_value(const std::string& name, const std::string& color);
86 void add_entity_value(const std::string& name);
87 EntityValue* get_entity_value(const std::string& name);
90 class LinkType : public ValueType {
92 static xbt::signal<void(LinkType&, Type&, Type&)> on_creation;
93 LinkType(const std::string& name, Type* source, Type* dest, const std::string& alias, Type* father)
94 : ValueType(PAJE_DefineLinkType, name, alias, father)
96 on_creation(*this, *source, *dest);
98 void start_event(Container* startContainer, const std::string& value, const std::string& key);
99 void start_event(Container* startContainer, const std::string& value, const std::string& key, int size);
100 void end_event(Container* endContainer, const std::string& value, const std::string& key);
103 class EventType : public ValueType {
105 EventType(const std::string& name, Type* father) : ValueType(PAJE_DefineEventType, name, father) {}
108 class StateType : public ValueType {
109 std::vector<StateEvent*> events_;
111 StateType(const std::string& name, Type* father) : ValueType(PAJE_DefineStateType, name, father) {}
112 void set_event(const std::string& value_name);
113 void push_event(const std::string& value_name);
114 void push_event(const std::string& value_name, TIData* extra);
116 void pop_event(TIData* extra);
119 } // namespace simgrid