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;
81 template <
typename Function>
82 void visit(Function f) {
87 Parameter::ParameterTrie trie;
105 [[nodiscard]] std::string_view name()
const;
107 [[nodiscard]]
constexpr std::string name_of_child(
108 const std::string_view child)
const {
109 return name_ +
"/" + std::string(child);
112 [[nodiscard]]
Context& sim_ctx()
const;
125 template <
typename T>
128 requires std::is_pointer_v<T>
131 if (port ==
nullptr) {
134 return boost::typeindex::runtime_cast<T>(port);
140 template <
typename T>
141 requires(!std::is_pointer_v<T>)
148 std::string full_name;
154 bool include_nested_components)
const;
156 Time current_time()
const;
158 template <
typename Stat>
159 Stat* get_statistic(
const std::string_view name) {
160 return statistics.get<Stat>(name);
163 template <
typename Function>
164 void visit_statistics(Function f) {
172 virtual InitializationStatus log_setup(
const std::filesystem::path& out_file);
174 InitializationStatus log_setup();
177 void log_enable(
bool new_value);
179 void log_level(
size_t level);
180 void log_level(std::string_view level_name);
187 template <
typename Callable>
188 void log(
size_t level, Callable&& callable) {
189 auto f = [
this, callable]() {
190 return std::format(
"[{}] [{}] {}\n", current_time(), name(), callable());
196 template <
typename Callable>
198 logger.log_callable(level, print_level, std::forward<Callable>(callable));
201 void populate_default_log_levels();
206 template <
typename T,
typename... Args>
208 T& s = statistics.emplace<T>(std::forward<Args>(args)...);
213 template <
typename T,
typename... Args>
215 auto ptr = std::make_unique<T>(std::forward<Args>(args)...);
217 ports[std::string(name)] = std::move(ptr);
223 template <
typename T,
typename... Args>
225 auto ptr = std::make_unique<T>(std::forward<Args>(args)...);
227 children.emplace_back(std::move(ptr));
233 std::unordered_map<std::string, std::unique_ptr<Port>> ports;
234 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:197
T & create_child(Args... args)
Definition Module.h:224
void record_statistics(Statistics::StatMapper &mapper)
Record a statistic in a StatMapper to dump statistics.
Definition Module.cc:62
std::vector< PortWithFullName > get_unconnected_ports(bool include_nested_components) const
Return all the unconnected ports that a module exposes.
Definition Module.cc:71
T & create_port(const std::string_view name, Args... args)
Create a new port of type T.
Definition Module.h:214
T get_port(std::string_view name)
Definition Module.h:127
void log(size_t level, Callable &&callable)
Definition Module.h:188
virtual InitializationStatus initialize(Context &sim_ctx_v, const Parameters ¶meters)
Definition Module.cc:47
Port * get_port(std::string_view)
Get a single port.
Definition Module.cc:66
T & create_statistic(Args... args)
Create a new statistic of type T.
Definition Module.h:207
T * get_port(std::string_view name)
Definition Module.h:143
A Parameter with a type.
Definition Parameter.h:74
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