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)
57 void log_definition(Type* source, Type* dest);
60 class ContainerType : public Type {
62 explicit ContainerType(const std::string& name) : Type(PAJE_DefineContainerType, name, name, "", nullptr){};
63 ContainerType(const std::string& name, Type* father) : Type(PAJE_DefineContainerType, name, name, "", father){};
66 class VariableType : public Type {
67 std::vector<VariableEvent*> events_;
69 VariableType(const std::string& name, const std::string& color, Type* father)
70 : Type(PAJE_DefineVariableType, name, name, color, father)
73 void instr_event(double now, double delta, const char* resource, double value);
74 void set_event(double timestamp, double value);
75 void add_event(double timestamp, double value);
76 void sub_event(double timestamp, double value);
79 class ValueType : public Type {
81 std::map<std::string, EntityValue> values_;
82 ValueType(e_event_type event_type, const std::string& name, const std::string& alias, Type* father)
83 : Type(event_type, name, alias, "", father){};
84 ValueType(e_event_type event_type, const std::string& name, Type* father)
85 : Type(event_type, name, name, "", father){};
86 virtual ~ValueType() = default;
87 void add_entity_value(const std::string& name, const std::string& color);
88 void add_entity_value(const std::string& name);
89 EntityValue* get_entity_value(const std::string& name);
92 class LinkType : public ValueType {
94 static xbt::signal<void(LinkType&, Type&, Type&)> on_creation;
95 LinkType(const std::string& name, Type* source, Type* dest, const std::string& alias, Type* father)
96 : ValueType(PAJE_DefineLinkType, name, alias, father)
98 on_creation(*this, *source, *dest);
100 void start_event(Container* startContainer, const std::string& value, const std::string& key);
101 void start_event(Container* startContainer, const std::string& value, const std::string& key, int size);
102 void end_event(Container* endContainer, const std::string& value, const std::string& key);
105 class EventType : public ValueType {
107 EventType(const std::string& name, Type* father) : ValueType(PAJE_DefineEventType, name, father) {}
110 class StateType : public ValueType {
111 std::vector<StateEvent*> events_;
113 StateType(const std::string& name, Type* father) : ValueType(PAJE_DefineStateType, name, father) {}
114 void set_event(const std::string& value_name);
115 void push_event(const std::string& value_name);
116 void push_event(const std::string& value_name, TIData* extra);
118 void pop_event(TIData* extra);
121 } // namespace simgrid