fixed_typemap.hpp: add range iterator

Remove recently added functions.
This commit is contained in:
Nekotekina 2021-06-08 23:12:40 +03:00
parent 4f76211551
commit 2d3fe7ce1c
3 changed files with 53 additions and 25 deletions

View File

@ -1542,31 +1542,23 @@ void Emulator::Stop(bool restart)
cpu_thread::stop_all();
using fxo_t = std::remove_pointer_t<decltype(g_fxo)>;
// Signal threads
for (const auto& type : fxo_t::view_typelist())
for (const auto& [type, data] : *g_fxo)
{
if (type.stop)
{
if (auto data = g_fxo->try_get(type))
{
type.stop(data, thread_state::aborting);
}
type.stop(data, thread_state::aborting);
}
}
GetCallbacks().on_stop();
// Join threads
for (const auto& type : fxo_t::view_typelist())
for (const auto& [type, data] : *g_fxo)
{
if (type.stop)
{
if (auto data = g_fxo->try_get(type))
{
type.stop(data, thread_state::finished);
}
type.stop(data, thread_state::finished);
}
}

View File

@ -155,8 +155,8 @@ namespace stx
clear();
}
m_order = new void*[stx::typelist<typeinfo>().count()];
m_info = new const typeinfo*[stx::typelist<typeinfo>().count()];
m_order = new void*[stx::typelist<typeinfo>().count() + 1];
m_info = new const typeinfo*[stx::typelist<typeinfo>().count() + 1];
m_init = new bool[stx::typelist<typeinfo>().count()]{};
if constexpr (Size == 0)
@ -176,6 +176,9 @@ namespace stx
ensure(Align >= stx::typelist<typeinfo>().align());
m_data[0] = 0;
}
*m_order++ = nullptr;
*m_info++ = nullptr;
}
void init(bool reset = true)
@ -231,6 +234,8 @@ namespace stx
}
// Pointers should be restored to their positions
m_info--;
m_order--;
delete[] m_init;
delete[] m_info;
delete[] m_order;
@ -344,20 +349,51 @@ namespace stx
[[unlikely]] return nullptr;
}
static const auto& view_typelist() noexcept
class iterator
{
return stx::typelist<typeinfo>();
}
const typeinfo** m_info;
void** m_ptr;
// Get type-erased raw pointer to storage of type
uchar* try_get(const type_info<typeinfo>& type) const noexcept
{
if (m_init[type.index()])
public:
iterator(const typeinfo** _info, void** _ptr)
: m_info(_info)
, m_ptr(_ptr)
{
[[likely]] return (Size ? +m_data : m_list) + type.pos();
}
[[unlikely]] return nullptr;
std::pair<const typeinfo&, void*> operator*() const
{
return {*m_info[-1], m_ptr[-1]};
}
iterator& operator++()
{
m_info--;
m_ptr--;
if (!m_info[-1])
{
m_info = nullptr;
m_ptr = nullptr;
}
return *this;
}
bool operator!=(const iterator& rhs) const
{
return m_info != rhs.m_info || m_ptr != rhs.m_ptr;
}
};
iterator begin() noexcept
{
return iterator{m_info, m_order};
}
iterator end() noexcept
{
return iterator{nullptr, nullptr};
}
};
}

View File

@ -761,7 +761,7 @@ constexpr unsigned __builtin_COLUMN()
}
#endif
template <usz Size = usz(-1)>
template <usz Size = umax>
struct const_str_t
{
static constexpr usz size = Size;
@ -792,7 +792,7 @@ struct const_str_t
};
template <>
struct const_str_t<usz(-1)>
struct const_str_t<umax>
{
const usz size;