Pass common highest_valid to vptr factory
This commit is contained in:
parent
0101f98905
commit
ec025d4e88
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
#include "dxxsconf.h"
|
||||
|
||||
|
@ -54,6 +55,7 @@ protected:
|
|||
class basic_ptr;
|
||||
template <typename policy>
|
||||
class basic_ptridx;
|
||||
class allow_end_construction;
|
||||
|
||||
static constexpr const array_managed_type &get_array(const_pointer_type p)
|
||||
{
|
||||
|
@ -64,6 +66,7 @@ protected:
|
|||
return get_global_array(p);
|
||||
}
|
||||
static inline void check_index_match(const_reference_type, index_type, const array_managed_type &);
|
||||
template <template <typename> class Compare = std::less>
|
||||
static inline index_type check_index_range(index_type, const array_managed_type *);
|
||||
static inline void check_explicit_index_range_ref(const_reference_type, std::size_t, const array_managed_type &);
|
||||
static inline void check_implicit_index_range_ref(const_reference_type, const array_managed_type &);
|
||||
|
|
|
@ -34,7 +34,13 @@ struct highest_valid_factory
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
highest_valid_factory<T> highest_valid(T &t, const typename T::index_type start = 0)
|
||||
T &highest_valid(T &t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
highest_valid_factory<T> highest_valid(T &t, const typename T::index_type start)
|
||||
{
|
||||
return {t, start};
|
||||
}
|
||||
|
|
|
@ -62,6 +62,9 @@ protected:
|
|||
|
||||
}
|
||||
|
||||
template <typename INTEGRAL_TYPE, std::size_t array_size_value>
|
||||
constexpr std::size_t valptridx_specialized_type_parameters<INTEGRAL_TYPE, array_size_value>::array_size;
|
||||
|
||||
template <typename P>
|
||||
class valptridx<P>::index_mismatch_exception :
|
||||
public std::logic_error
|
||||
|
@ -110,10 +113,11 @@ void valptridx<managed_type>::check_index_match(const managed_type &r, index_typ
|
|||
}
|
||||
|
||||
template <typename managed_type>
|
||||
template <template <typename> class Compare>
|
||||
typename valptridx<managed_type>::index_type valptridx<managed_type>::check_index_range(const index_type i, const array_managed_type *a)
|
||||
{
|
||||
const std::size_t ss = i;
|
||||
DXX_VALPTRIDX_CHECK(ss < array_size, index_range_exception, "invalid index used in array subscript", a, ss);
|
||||
DXX_VALPTRIDX_CHECK(Compare<std::size_t>()(ss, array_size), index_range_exception, "invalid index used in array subscript", a, ss);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -252,6 +256,10 @@ public:
|
|||
m_idx(check_allowed_invalid_index(i) ? i : check_index_range(i, &a))
|
||||
{
|
||||
}
|
||||
basic_idx(index_type i, array_managed_type &a, const allow_end_construction *) :
|
||||
m_idx(check_index_range<std::less_equal>(i, &a))
|
||||
{
|
||||
}
|
||||
template <integral_type v>
|
||||
basic_idx(const magic_constant<v> &) :
|
||||
m_idx(v)
|
||||
|
@ -355,6 +363,10 @@ public:
|
|||
m_ptr(check_allowed_invalid_index(i) ? nullptr : &a[check_index_range(i, &a)])
|
||||
{
|
||||
}
|
||||
basic_ptr(index_type i, array_managed_type &a, const allow_end_construction *) :
|
||||
m_ptr(&a[check_index_range<std::less_equal>(i, &a)])
|
||||
{
|
||||
}
|
||||
basic_ptr(pointer_type p) = delete;
|
||||
basic_ptr(pointer_type p, array_managed_type &a) :
|
||||
/* No array consistency check here, since some code incorrectly
|
||||
|
@ -507,6 +519,11 @@ public:
|
|||
vidx_type(i, a)
|
||||
{
|
||||
}
|
||||
basic_ptridx(index_type i, array_managed_type &a, const allow_end_construction *e) :
|
||||
vptr_type(i, a, e),
|
||||
vidx_type(i, a, e)
|
||||
{
|
||||
}
|
||||
basic_ptridx(pointer_type p, array_managed_type &a) :
|
||||
/* Null pointer is never allowed when an index must be computed.
|
||||
* Check for null, then use the reference constructor for
|
||||
|
@ -593,6 +610,20 @@ template <typename P>
|
|||
class valptridx<managed_type>::basic_vptr_global_factory
|
||||
{
|
||||
using containing_type = valptridx<managed_type>;
|
||||
struct iterator :
|
||||
std::iterator<std::forward_iterator_tag, P>,
|
||||
P
|
||||
{
|
||||
using P::operator++;
|
||||
iterator(P &&i) :
|
||||
P(static_cast<P &&>(i))
|
||||
{
|
||||
}
|
||||
P operator*() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
public:
|
||||
using index_type = typename containing_type::index_type;
|
||||
using result_type = P;
|
||||
|
@ -619,6 +650,17 @@ public:
|
|||
{
|
||||
return get_array().get_count() - 1;
|
||||
}
|
||||
__attribute_warn_unused_result
|
||||
iterator begin() const
|
||||
{
|
||||
return P(containing_type::magic_constant<0>(), get_array());
|
||||
}
|
||||
__attribute_warn_unused_result
|
||||
iterator end() const
|
||||
{
|
||||
auto &a = get_array();
|
||||
return P(static_cast<index_type>(a.get_count()), a, static_cast<const allow_end_construction *>(nullptr));
|
||||
}
|
||||
template <containing_type::integral_type v>
|
||||
__attribute_warn_unused_result
|
||||
P operator()(const containing_type::magic_constant<v> &m) const
|
||||
|
|
|
@ -566,7 +566,7 @@ static segnum_t exists_fuelcen_in_mine(segnum_t start_seg)
|
|||
return *i;
|
||||
}
|
||||
{
|
||||
const auto &&rh = highest_valid(vcsegptr);
|
||||
const auto &rh = vcsegptr;
|
||||
const auto a = [](const vcsegptr_t &s) {
|
||||
return s->special == SEGMENT_IS_FUELCEN;
|
||||
};
|
||||
|
@ -939,7 +939,7 @@ static void do_buddy_dude_stuff(void)
|
|||
|
||||
if (Buddy_last_missile_time + F1_0*2 < GameTime64) {
|
||||
// See if a robot potentially in view cone
|
||||
const auto &&rh = highest_valid(vobjptridx);
|
||||
const auto &rh = vobjptridx;
|
||||
range_for (const auto &&objp, rh)
|
||||
{
|
||||
if ((objp->type == OBJ_ROBOT) && !Robot_info[get_robot_id(objp)].companion)
|
||||
|
|
|
@ -902,7 +902,7 @@ object_signature_t obj_get_signature()
|
|||
{
|
||||
static short sig = 0; // Yes! Short! a) We do not need higher values b) the demo system only stores shorts
|
||||
uint_fast32_t lsig = sig;
|
||||
for (const auto &&range = highest_valid(vcobjptridx);;)
|
||||
for (const auto &range = highest_valid(vcobjptridx);;)
|
||||
{
|
||||
if (unlikely(lsig == std::numeric_limits<decltype(sig)>::max()))
|
||||
lsig = 0;
|
||||
|
|
Loading…
Reference in a new issue