#pragma once #include #include "dxxsconf.h" #include "objnum.h" #include "segnum.h" template class valptridx_specialized_types; template class valptridx : protected valptridx_specialized_types { using specialized_types = valptridx_specialized_types; class partial_policy { public: class require_valid; class allow_invalid; class const_policy; class mutable_policy; template class apply_cv_policy; }; class vc; /* require_valid + const_policy */ class ic; /* allow_invalid + const_policy */ class vm; /* require_valid + mutable_policy */ class im; /* allow_invalid + mutable_policy */ public: class array_managed_type; protected: using const_pointer_type = const managed_type *; using const_reference_type = const managed_type &; using mutable_pointer_type = managed_type *; using index_type = typename specialized_types::index_type; using typename specialized_types::integral_type; template class basic_idx; template class basic_ptr; template class basic_ptridx; static constexpr const array_managed_type &get_array(const_pointer_type p) { return get_global_array(p); } static constexpr array_managed_type &get_array(mutable_pointer_type p = mutable_pointer_type()) { return get_global_array(p); } static constexpr std::size_t get_array_size() { return get_array().size(); } static inline void check_index_match(const_reference_type, index_type, const array_managed_type &); 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 &); static inline void check_null_pointer_conversion(const_pointer_type); static inline void check_null_pointer(const_pointer_type, const array_managed_type &); static void check_null_pointer(std::nullptr_t, ...) = delete; #define DXX_VALPTRIDX_SUBTYPE(VERB,managed_type,derived_type_prefix) \ DXX_VALPTRIDX_SUBTYPE_C(VERB, managed_type, derived_type_prefix, c); \ DXX_VALPTRIDX_SUBTYPE_C(VERB, managed_type, derived_type_prefix, ) #define DXX_VALPTRIDX_SUBTYPE_C(VERB,managed_type,derived_type_prefix,cprefix) \ DXX_VALPTRIDX_SUBTYPE_VC(VERB, managed_type, derived_type_prefix, cprefix); \ DXX_VALPTRIDX_SUBTYPE_VC(VERB, managed_type, derived_type_prefix, v##cprefix) #define DXX_VALPTRIDX_SUBTYPE_VC(VERB,managed_type,derived_type_prefix,vcprefix) \ VERB(managed_type, derived_type_prefix, vcprefix, idx); \ VERB(managed_type, derived_type_prefix, vcprefix, ptr); \ VERB(managed_type, derived_type_prefix, vcprefix, ptridx) public: typedef basic_ptridx vcptridx; typedef basic_ptridx cptridx; typedef basic_ptridx vptridx; typedef basic_ptridx ptridx; typedef basic_idx vcidx; typedef basic_idx cidx; typedef basic_idx vidx; typedef basic_idx idx; typedef basic_ptr vcptr; typedef basic_ptr cptr; typedef basic_ptr vptr; typedef basic_ptr ptr; class index_mismatch_exception; class index_range_exception; class null_pointer_exception; template class basic_vptr_global_factory; template class basic_ptridx_global_factory; template class magic_constant { public: constexpr operator integral_type() const { return constant; } // integral_type conversion deprecated }; }; #define DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEF(managed_type,derived_type_prefix,vcprefix,suffix) \ typedef valptridx::vcprefix##suffix vcprefix##derived_type_prefix##suffix##_t #define DXX_VALPTRIDX_DECLARE_GLOBAL_SUBTYPE(managed_type,derived_type_prefix,global_array) \ struct managed_type; \ template <> \ class valptridx_specialized_types { \ public: \ using index_type = derived_type_prefix##num_t; \ using integral_type = derived_type_prefix##num_t; \ }; \ extern valptridx::array_managed_type global_array; \ DXX_VALPTRIDX_SUBTYPE(DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEF, managed_type, derived_type_prefix)