Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a doc error about actors (Tutorial_algorithms)
[simgrid.git] / src / instr / instr_paje_types.hpp
1 /* Copyright (c) 2010-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef INSTR_PAJE_TYPES_HPP
7 #define INSTR_PAJE_TYPES_HPP
8
9 #include "src/instr/instr_private.hpp"
10 #include <memory>
11 #include <sstream>
12 #include <string>
13 #include <vector>
14
15 namespace simgrid {
16 namespace instr {
17 class ContainerType;
18 class EventType;
19
20 class Type {
21   long long int id_;
22   std::string name_;
23   std::string color_;
24   Type* father_;
25
26 public:
27   std::map<std::string, std::unique_ptr<Type>> children_;
28   Container* issuer_ = nullptr;
29   std::stringstream stream_;
30
31   Type(const std::string& name, const std::string& alias, const std::string& color, Type* father);
32   virtual ~Type() = default;
33
34   const std::string& get_name() const { return name_; }
35   const char* get_cname() { return name_.c_str(); }
36   long long int get_id() { return id_; }
37   bool is_colored() { return not color_.empty(); }
38
39   Type* by_name(const std::string& name);
40   LinkType* by_name_or_create(const std::string& name, Type* source, Type* dest);
41   VariableType* by_name_or_create(const std::string& name, const std::string& color);
42
43   template <class T> T* by_name_or_create(const std::string& name)
44   {
45     auto cont = children_.find(name);
46     return cont == children_.end() ? new T(name, this) : static_cast<T*>(cont->second.get());
47   }
48
49   void set_calling_container(Container* container) { issuer_ = container; }
50
51   void log_definition(e_event_type event_type);
52   void log_definition(Type* source, Type* dest);
53 };
54
55 class ContainerType : public Type {
56 public:
57   explicit ContainerType(const std::string& name) : Type(name, name, "", nullptr){};
58   ContainerType(const std::string& name, Type* father);
59 };
60
61 class VariableType : public Type {
62   std::vector<VariableEvent*> events_;
63 public:
64   VariableType(const std::string& name, const std::string& color, Type* father);
65   void instr_event(double now, double delta, const char* resource, double value);
66   void set_event(double timestamp, double value);
67   void add_event(double timestamp, double value);
68   void sub_event(double timestamp, double value);
69 };
70
71 class ValueType : public Type {
72 public:
73   std::map<std::string, EntityValue> values_;
74   ValueType(const std::string& name, const std::string& alias, Type* father) : Type(name, alias, "", father){};
75   ValueType(const std::string& name, Type* father) : Type(name, name, "", father){};
76   virtual ~ValueType() = default;
77   void add_entity_value(const std::string& name, const std::string& color);
78   void add_entity_value(const std::string& name);
79   EntityValue* get_entity_value(const std::string& name);
80 };
81
82 class LinkType : public ValueType {
83 public:
84   LinkType(const std::string& name, const std::string& alias, Type* father);
85   void start_event(Container* startContainer, const std::string& value, const std::string& key);
86   void start_event(Container* startContainer, const std::string& value, const std::string& key, int size);
87   void end_event(Container* endContainer, const std::string& value, const std::string& key);
88 };
89
90 class EventType : public ValueType {
91 public:
92   EventType(const std::string& name, Type* father);
93 };
94
95 class StateType : public ValueType {
96   std::vector<StateEvent*> events_;
97 public:
98   StateType(const std::string& name, Type* father);
99   void set_event(const std::string& value_name);
100   void push_event(const std::string& value_name);
101   void push_event(const std::string& value_name, TIData* extra);
102   void pop_event();
103   void pop_event(TIData* extra);
104 };
105 }
106 }
107 #endif