18#include <Simo/core/Log.h>
19#include <Simo/core/Time.h>
23#include "Simo/core/InitializationStatus.h"
24#include "Simo/parameter/ParameterTrie.h"
25#include "Simo/port/Port.h"
26#include "Simo/statistics/StatMapper.h"
37 [[nodiscard]] std::string_view name()
const;
39 template <
typename Self>
40 Self& name(
this Self& self,
const std::string_view name) {
50 [[nodiscard]]
virtual bool check()
const;
56 return trie.add<T>(name, value);
65 const std::string& name)
const {
66 return trie.find<T>(name);
70 return trie.find(name);
78 [[nodiscard]] std::optional<Parameters> get_subtree(
79 const std::string& name)
const;
82 Parameter::ParameterTrie trie;
100 [[nodiscard]] std::string_view name()
const;
102 [[nodiscard]]
constexpr std::string name_of_child(
103 const std::string_view child)
const {
104 return name_ +
"/" + std::string(child);
107 [[nodiscard]]
Context& sim_ctx()
const;
114 [[nodiscard]]
Port* get_port(std::string_view);
116 Time current_time()
const;
118 template <
typename Stat>
119 Stat* get_statistic(
const std::string_view name) {
120 return statistics.get<Stat>(name);
123 template <
typename Function>
124 void visit_statistics(Function f) {
139 void log_level(
size_t level);
140 void log_level(std::string_view level_name);
147 template <
typename Callable>
148 void log(
size_t level, Callable&& callable) {
149 auto f = [
this, callable]() {
150 return std::format(
"[{}] [{}] {}\n", current_time(), name(), callable());
156 template <
typename Callable>
158 logger.log_callable(level, print_level, std::forward<Callable>(callable));
161 void populate_default_log_levels();
166 template <
typename T,
typename... Args>
168 T& s = statistics.emplace<T>(std::forward<Args>(args)...);
173 template <
typename T,
typename... Args>
175 auto ptr = std::make_unique<T>(std::forward<Args>(args)...);
177 ports[std::string(name)] = std::move(ptr);
183 template <
typename T,
typename... Args>
185 auto ptr = std::make_unique<T>(std::forward<Args>(args)...);
187 children.emplace_back(std::move(ptr));
193 std::unordered_map<std::string, std::unique_ptr<Port>> ports;
194 std::vector<std::unique_ptr<Module>> children;
Definition InitializationStatus.h:32
void log_raw_callable(size_t level, bool print_level, Callable &&callable)
Log a message with the given level without adding timestamp.
Definition Module.h:157
T & create_child(Args... args)
Definition Module.h:184
void record_statistics(Statistics::StatMapper &mapper)
Record a statistic in a StatMapper to dump statistics.
Definition Module.cc:62
T & create_port(const std::string_view name, Args... args)
Create a new port of type T.
Definition Module.h:174
void log(size_t level, Callable &&callable)
Definition Module.h:148
virtual InitializationStatus log_setup(const std::filesystem::path &out_file)
Definition Module.cc:71
virtual InitializationStatus initialize(Context &sim_ctx_v, const Parameters ¶meters)
Definition Module.cc:47
T & create_statistic(Args... args)
Create a new statistic of type T.
Definition Module.h:167
void log_enable(bool new_value)
Enable/disable logging for the component.
Definition Module.cc:78
A Parameter with a type.
Definition Parameter.h:68
Base class for any Parameter.
Definition Parameter.h:31
Collects parameters that are then passed to a Module instance.
Definition Module.h:33
virtual bool check() const
Definition Module.cc:29
Parameter::ParameterTyped< T > * get(const std::string &name) const
Definition Module.h:64
Parameter::ParameterTyped< T > & set(const std::string &name, const T &value)
Create a new parameter with the given type and return a reference to it.
Definition Module.h:55
Generic port. It offers the virtual method connect.
Definition Port.h:30
Definition StatMapper.h:33
Definition StatMapper.h:68
General namespace for Simo.
Definition Collection.h:51