Commit 425a4828 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: removing the old map class

parent ee46e9a9
Pipeline #40028 passed with stage
in 1 minute and 33 seconds
......@@ -7,6 +7,8 @@
#define WINDOWS_LEAN_AND_MEAN
#endif
#include <irritator/ext.hpp>
#include "application.hpp"
#include "dialog.hpp"
#include "internal.hpp"
......@@ -352,10 +354,10 @@ editor::compute_automatic_layout() noexcept
}
static status
copy_port(simulation& sim,
const map<model_id, model_id>& mapping,
output_port& src,
output_port& dst) noexcept
copy_port(simulation& sim,
const table<model_id, model_id>& mapping,
output_port& src,
output_port& dst) noexcept
{
if (src == static_cast<u64>(-1)) {
dst = src;
......@@ -369,10 +371,10 @@ copy_port(simulation& sim,
auto et = src_list.end();
while (it != et) {
if (auto found = mapping.find(it->model); found != mapping.end()) {
if (auto* found = mapping.get(it->model); found) {
irt_return_if_fail(sim.can_connect(1u),
status::simulation_not_enough_connection);
dst_list.emplace_back(found->v, it->port_index);
dst_list.emplace_back(*found, it->port_index);
} else {
if (model* mdl = sim.models.try_to_get(it->model); mdl) {
irt_return_if_fail(sim.can_connect(1u),
......@@ -391,8 +393,8 @@ copy_port(simulation& sim,
status
editor::copy(const ImVector<int>& nodes) noexcept
{
map<model_id, model_id> mapping;
irt_return_if_bad(mapping.init(nodes.size()));
table<model_id, model_id> mapping;
irt_return_if_bad(mapping.data.init(nodes.size()));
for (int i = 0, e = nodes.size(); i != e; ++i) {
auto* src_mdl = sim.models.try_to_get(nodes[i]);
......@@ -408,14 +410,14 @@ editor::copy(const ImVector<int>& nodes) noexcept
sim.make_initialize(dst_mdl, simulation_current);
mapping.emplace_back(src_mdl_id, dst_mdl_id);
mapping.data.emplace_back(src_mdl_id, dst_mdl_id);
}
mapping.sort();
for (int i = 0, e = length(mapping); i != e; ++i) {
auto& src_mdl = sim.models.get(mapping[i].u);
auto& dst_mdl = sim.models.get(mapping[i].v);
for (int i = 0, e = length(mapping.data); i != e; ++i) {
auto& src_mdl = sim.models.get(mapping.data[i].id);
auto& dst_mdl = sim.models.get(mapping.data[i].value);
dispatch(src_mdl,
[this, &mapping, &dst_mdl]<typename Dynamics>(Dynamics& dyn) {
......
......@@ -1865,99 +1865,6 @@ public:
}
};
template<typename U, typename V>
class map
{
static_assert(std::is_trivial_v<V> && std::is_trivial_v<U>,
"map is trivial type only (model_id, etc.)");
struct map_node
{
map_node() noexcept = default;
map_node(const U u_) noexcept
: u(u_)
{}
map_node(const U u_, const V v_) noexcept
: u(u_)
, v(v_)
{}
U u;
V v;
};
vector<map_node> m_data;
public:
using size_type = vector<map_node>::size_type;
using index_type = vector<map_node>::index_type;
using iterator = vector<map_node>::iterator;
using const_iterator = vector<map_node>::const_iterator;
using reference = vector<map_node>::reference;
using const_reference = vector<map_node>::const_reference;
using pointer = vector<map_node>::pointer;
using const_pointer = vector<map_node>::const_pointer;
using pair_iterator_bool = std::pair<iterator, bool>;
status init(sz capacity) noexcept
{
return m_data.init(static_cast<i32>(capacity));
}
bool can_alloc(sz capacity) const noexcept
{
return m_data.can_alloc(capacity);
}
pointer try_emplace_back(const U& u, const V& v)
{
if (!m_data.can_alloc(1u))
return nullptr;
return &m_data.emplace_back(u, v);
}
reference emplace_back(const U& u, const V& v)
{
irt_assert(m_data.can_alloc(1u));
return m_data.emplace_back(u, v);
}
void sort() noexcept
{
std::sort(m_data.begin(),
m_data.end(),
[](const auto& left, const auto& right) noexcept {
return left.u < right.u;
});
}
const_iterator find(const U u) const noexcept
{
auto it = std::lower_bound(
m_data.begin(), m_data.end(), u, [](const map_node& m, const U u) {
return m.u < u;
});
return (it != m_data.end() && u == it->u) ? it : m_data.end();
}
iterator begin() noexcept { return m_data.begin(); }
iterator end() noexcept { return m_data.end(); }
const_iterator begin() const noexcept { return m_data.begin(); }
const_iterator end() const noexcept { return m_data.end(); }
sz size() const noexcept { return m_data.size(); }
sz capacity() const noexcept { return m_data.capacity(); }
const_reference operator[](index_type i) const noexcept
{
return m_data[i];
}
};
struct record
{
record() noexcept = default;
......
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