Commit fbb7fbc8 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

WIP

parent 348ca3e5
Pipeline #41354 failed with stage
in 0 seconds
......@@ -538,12 +538,12 @@ public:
irt_return_if_bad(do_read_model(mod, compo, &id));
}
// irt_return_if_bad(do_read_inputs(compo));
// irt_return_if_bad(do_read_outputs(compo));
// irt_return_if_bad(do_read_observables(compo));
// irt_return_if_bad(do_read_parameters(compo));
// irt_return_if_bad(do_read_inputs(mod, compo));
// irt_return_if_bad(do_read_outputs(mod, compo));
// irt_return_if_bad(do_read_observables(mod, compo));
// irt_return_if_bad(do_read_parameters(mod, compo));
// irt_return_if_bad(do_read_connections(sim));
irt_return_if_bad(do_read_connections(mod, compo));
return status::success;
}
......@@ -873,6 +873,39 @@ private:
return status::success;
}
status do_read_connections(modeling& mod, component& compo) noexcept
{
while (is) {
int mdl_src_id, port_src_index, mdl_dst_id, port_dst_index;
if (!(is >> mdl_src_id >> port_src_index >> mdl_dst_id >>
port_dst_index)) {
if (is.eof())
break;
irt_bad_return(status::io_file_format_error);
}
irt_return_if_fail(0 <= mdl_src_id && mdl_src_id < model_number,
status::io_file_format_model_error);
irt_return_if_fail(0 <= mdl_dst_id && mdl_dst_id < model_number,
status::io_file_format_model_error);
auto* m_src_id = map.get(mdl_src_id);
irt_return_if_fail(m_src_id, status::io_file_format_model_unknown);
auto* m_dst_id = map.get(mdl_dst_id);
irt_return_if_fail(m_dst_id, status::io_file_format_model_unknown);
irt_return_if_bad(mod.connect(
compo, mdl_src_id, port_src_index, mdl_dst_id, port_dst_index));
++connection_error;
}
return status::success;
}
status do_read_connections(simulation& sim) noexcept
{
while (is) {
......@@ -1093,10 +1126,11 @@ private:
return status::success;
});
irt_return_if_bad(ret);
compo.children.emplace_back(mod.models.get_id(mdl));
map.set(id, ordinal(mod.models.get_id(mdl)));
irt_return_if_bad(ret);
}
map.set(id, compo.children.size());
return status::success;
}
......
......@@ -69,21 +69,6 @@ void for_each(const DataArray& data, vector<T>& vec, Function&& f)
}
}
struct connection
{
connection() noexcept = default;
template<typename Src, typename Dst>
connection(Src src, i8 port_src_, Dst dst, i8 port_dst_) noexcept;
u64 src; // model_id or component_id
u64 dst; // model_id or component_id
child_type type_src; // model or component
child_type type_dst; // model or component
i8 port_src; // output port index
i8 port_dst; // input port index
};
struct component_ref
{
component_id id; // the component reference
......@@ -112,6 +97,23 @@ struct port
i8 index; // index of the port
};
struct connection
{
connection() noexcept = default;
template<typename Src, typename Dst>
connection(Src src, i8 port_src_, Dst dst, i8 port_dst_) noexcept;
connection(child src_, i8 port_src_, child dst_, i8 port_dst_) noexcept;
u64 src; // model_id or component_id
u64 dst; // model_id or component_id
child_type type_src; // model or component
child_type type_dst; // model or component
i8 port_src; // output port index
i8 port_dst; // input port index
};
enum class component_type
{
qss1_izhikevich,
......@@ -181,6 +183,12 @@ struct modeling
DynamicsDst& dst,
i8 port_dst) noexcept;
status connect(component& parent,
i32 src,
i8 port_src,
i32 dst,
i8 port_dst) noexcept;
template<typename Dynamics>
model_id get_id(const Dynamics& dyn) const;
};
......@@ -209,6 +217,19 @@ connection::connection(Src src, i8 port_src_, Dst dst, i8 port_dst_) noexcept
}
}
inline
connection::connection(child src_,
i8 port_src_,
child dst_,
i8 port_dst_) noexcept
: src(src_.id)
, dst(dst_.id)
, type_src(src_.type)
, type_dst(dst_.type)
, port_src(port_src_)
, port_dst(port_dst_)
{}
inline child::child(model_id model) noexcept
: id{ ordinal(model) }
, type{ child_type::model }
......
......@@ -913,6 +913,69 @@ status modeling::fill_component() noexcept
return status::success;
}
status modeling::connect(component& parent,
i32 src,
i8 port_src,
i32 dst,
i8 port_dst) noexcept
{
irt_return_if_fail(0 <= src && src < parent.children.size(),
status::model_connect_bad_dynamics);
irt_return_if_fail(0 <= dst && dst < parent.children.size(),
status::model_connect_bad_dynamics);
irt_assert(!parent.connections.full());
auto src_child = parent.children[src];
auto dst_child = parent.children[dst];
model_id real_src_id, real_dst_id;
i8 real_src_port, real_dst_port;
if (src_child.type == child_type::component) {
irt_return_if_fail(
found_output_port(*this,
enum_cast<component_ref_id>(src_child.id),
port_src,
real_src_id,
real_src_port),
status::model_connect_bad_dynamics);
} else {
real_src_id = enum_cast<model_id>(src_child.id);
real_src_port = port_src;
}
if (dst_child.type == child_type::component) {
irt_return_if_fail(
found_input_port(*this,
enum_cast<component_ref_id>(dst_child.id),
port_dst,
real_dst_id,
real_dst_port),
status::model_connect_bad_dynamics);
} else {
real_dst_id = enum_cast<model_id>(dst_child.id);
real_dst_port = port_dst;
}
if (auto* mdl_src = models.try_to_get(real_src_id); mdl_src) {
if (auto* mdl_dst = models.try_to_get(real_dst_id); mdl_dst) {
irt_return_if_fail(
is_ports_compatible(
*mdl_src, real_src_port, *mdl_dst, real_dst_port),
status::model_connect_bad_dynamics);
parent.connections.emplace_back(parent.children[src],
port_src,
parent.children[dst],
port_dst);
return status::success;
}
}
return status::model_connect_bad_dynamics;
}
static component* find_file_component(modeling& mod,
const char* file_path) noexcept
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment