Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / instr / instr_paje_containers.hpp
1 /* Copyright (c) 2010-2023. 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_CONTAINERS_HPP
7 #define INSTR_PAJE_CONTAINERS_HPP
8
9 #include "src/instr/instr_private.hpp"
10 #include <string>
11
12 namespace simgrid::instr {
13 class Type;
14 class LinkType;
15 class StateType;
16 class VariableType;
17
18 class Container {
19   friend class NetZoneContainer;
20   static Container* root_container_;
21   static std::map<std::string, Container*, std::less<>> all_containers_;
22
23   long long int id_;
24   std::string name_; /* Unique name of this container */
25   Type* type_;       /* Type of this container */
26   Container* parent_;
27   std::map<std::string, Container*, std::less<>> children_;
28
29 protected:
30   static void set_root(Container* root) { root_container_ = root; }
31
32 private:
33   static xbt::signal<void(Container const&)> on_creation;
34   static xbt::signal<void(Container const&)> on_destruction;
35
36 public:
37   static void on_creation_cb(const std::function<void(Container const&)>& cb) { on_creation.connect(cb); }
38   static void on_destruction_cb(const std::function<void(Container const&)>& cb) { on_destruction.connect(cb); }
39
40   explicit Container(const std::string& name, const std::string& type_name, Container* parent);
41   Container(const Container&) = delete;
42   Container& operator=(const Container&) = delete;
43   virtual ~Container();
44
45
46   static Container* by_name_or_null(const std::string& name);
47   static Container* by_name(const std::string& name);
48   const std::string& get_name() const { return name_; }
49   const char* get_cname() const { return name_.c_str(); }
50   long long int get_id() const { return id_; }
51   void remove_from_parent();
52
53   Container* get_parent() const { return parent_; }
54   Type* get_type() const { return type_; }
55   StateType* get_state(const std::string& name);
56   LinkType* get_link(const std::string& name);
57   VariableType* get_variable(const std::string& name);
58   void create_child(const std::string& name, const std::string& type_name);
59   Container* get_child_by_name(const std::string& name) const { return children_.at(name); }
60   static Container* get_root() { return root_container_; }
61 };
62
63 class NetZoneContainer : public Container {
64 public:
65   NetZoneContainer(const std::string& name, unsigned int level, NetZoneContainer* parent);
66 };
67
68 class RouterContainer : public Container {
69 public:
70   RouterContainer(const std::string& name, Container* parent);
71 };
72
73 class HostContainer : public Container {
74 public:
75   HostContainer(s4u::Host const& host, NetZoneContainer* parent);
76 };
77 } // namespace simgrid::instr
78 #endif