Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Objectif the disk model
[simgrid.git] / src / simgrid / module.hpp
1 /* Copyright (c) 2004-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 SIMGRID_MODULE_HPP
7 #define SIMGRID_MODULE_HPP
8
9 #include <xbt/base.h>
10
11 #include <functional>
12 #include <string>
13 #include <vector>
14
15 namespace simgrid {
16
17 struct Module {
18   const char* name_;
19   const char* description_;
20   std::function<void()> init;
21   Module(const char* id, const char* desc, std::function<void()> init_fun)
22       : name_(id), description_(desc), init(init_fun)
23   {
24   }
25 };
26
27 class ModuleGroup {
28   std::vector<Module> table_;
29   const std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only
30 public:
31   ModuleGroup(const std::string& kind) : kind_(kind) {}
32
33   ModuleGroup& add(const char* id, const char* desc, std::function<void()> init);
34   Module const& by_name(const std::string& name) const;
35   void help() const;
36   const std::string get_kind() const { return kind_; }
37   std::string existing_values() const;
38   void create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
39                    bool init_now);
40 };
41
42 }; // namespace simgrid
43
44 #define SIMGRID_REGISTER_PLUGIN(id, desc, init)                                                                        \
45   static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _plugin_register)()                               \
46   {                                                                                                                    \
47     simgrid_plugins().add(_XBT_STRINGIFY(id), (desc), (init));                                                         \
48   }
49 /** @brief The list of all available plugins */
50 inline auto& simgrid_plugins() // Function to avoid static initialization order fiasco
51 {
52   static simgrid::ModuleGroup plugins("plugin");
53   return plugins;
54 }
55
56 #define SIMGRID_REGISTER_NETWORK_MODEL(id, desc, init)                                                                 \
57   static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _network_model_register)()                        \
58   {                                                                                                                    \
59     simgrid_network_models().add(_XBT_STRINGIFY(id), (desc), (init));                                                  \
60   }
61 /** @brief The list of all available network models (pick one with --cfg=network/model) */
62 inline auto& simgrid_network_models() // Function to avoid static initialization order fiasco
63 {
64   static simgrid::ModuleGroup models("network model");
65   return models;
66 }
67
68 #define SIMGRID_REGISTER_CPU_MODEL(id, desc, init)                                                                     \
69   static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _cpu_model_register)()                            \
70   {                                                                                                                    \
71     simgrid_cpu_models().add(_XBT_STRINGIFY(id), (desc), (init));                                                      \
72   }
73 /** @brief The list of all available CPU models (pick one with --cfg=cpu/model) */
74 inline auto& simgrid_cpu_models() // Function to avoid static initialization order fiasco
75 {
76   static simgrid::ModuleGroup models("CPU model");
77   return models;
78 }
79
80 #define SIMGRID_REGISTER_DISK_MODEL(id, desc, init)                                                                    \
81   static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _disk_model_register)()                           \
82   {                                                                                                                    \
83     simgrid_disk_models().add(_XBT_STRINGIFY(id), (desc), (init));                                                     \
84   }
85 /** @brief The list of all available disk models (pick one with --cfg=disk/model) */
86 inline auto& simgrid_disk_models() // Function to avoid static initialization order fiasco
87 {
88   static simgrid::ModuleGroup models("disk model");
89   return models;
90 }
91
92 #define SIMGRID_REGISTER_HOST_MODEL(id, desc, init)                                                                    \
93   static void XBT_ATTRIB_CONSTRUCTOR(800) _XBT_CONCAT3(simgrid_, id, _host_model_register)()                           \
94   {                                                                                                                    \
95     simgrid_host_models().add(_XBT_STRINGIFY(id), (desc), (init));                                                     \
96   }
97 /** @brief The list of all available host models (pick one with --cfg=host/model) */
98 inline auto& simgrid_host_models() // Function to avoid static initialization order fiasco
99 {
100   static simgrid::ModuleGroup models("host model");
101   return models;
102 }
103
104 #endif