Logo AND Algorithmique Numérique Distribuée

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