Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:47:48

0001 /* Copyright 2016-2018 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/poly_collection for library home page.
0007  */
0008 
0009 #ifndef BOOST_POLY_COLLECTION_DETAIL_BASE_MODEL_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_BASE_MODEL_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/core/addressof.hpp>
0017 #include <boost/poly_collection/detail/is_final.hpp>
0018 #include <boost/poly_collection/detail/packed_segment.hpp>
0019 #include <boost/poly_collection/detail/stride_iterator.hpp>
0020 #include <memory>
0021 #include <type_traits>
0022 #include <typeinfo>
0023 #include <utility>
0024 
0025 namespace boost{
0026 
0027 namespace poly_collection{
0028 
0029 namespace detail{
0030 
0031 /* model for base_collection */
0032 
0033 template<typename Base>
0034 struct base_model
0035 {
0036   using value_type=Base;
0037   template<typename Derived>
0038   using is_implementation=std::is_base_of<Base,Derived>;
0039   template<typename T>
0040   using is_terminal=is_final<T>; //TODO: should we say !is_polymorhpic||is_final?
0041 
0042 private:
0043   template<typename T>
0044   using enable_if_not_terminal=
0045     typename std::enable_if<!is_terminal<T>::value>::type*;
0046   template<typename T>
0047   using enable_if_terminal=
0048     typename std::enable_if<is_terminal<T>::value>::type*;
0049 
0050 public:
0051   template<typename T,enable_if_not_terminal<T> =nullptr>
0052   static const std::type_info& subtypeid(const T& x){return typeid(x);}
0053 
0054   template<typename T,enable_if_terminal<T> =nullptr>
0055   static const std::type_info& subtypeid(const T&){return typeid(T);}
0056 
0057   template<typename T,enable_if_not_terminal<T> =nullptr>
0058   static void* subaddress(T& x)
0059   {
0060     return dynamic_cast<void*>(boost::addressof(x));
0061   }
0062 
0063   template<typename T,enable_if_not_terminal<T> =nullptr>
0064   static const void* subaddress(const T& x)
0065   {
0066     return dynamic_cast<const void*>(boost::addressof(x));
0067   }
0068 
0069   template<typename T,enable_if_terminal<T> =nullptr>
0070   static void* subaddress(T& x){return boost::addressof(x);}
0071 
0072   template<typename T,enable_if_terminal<T> =nullptr>
0073   static const void* subaddress(const T& x){return boost::addressof(x);}
0074 
0075   using base_iterator=stride_iterator<Base>;
0076   using const_base_iterator=stride_iterator<const Base>;
0077   using base_sentinel=Base*;
0078   using const_base_sentinel=const Base*;
0079   template<typename Derived>
0080   using iterator=Derived*;
0081   template<typename Derived>
0082   using const_iterator=const Derived*;
0083   template<typename Allocator>
0084   using segment_backend=detail::segment_backend<base_model,Allocator>;
0085   template<typename Derived,typename Allocator>
0086   using segment_backend_implementation=
0087     packed_segment<base_model,Derived,Allocator>;
0088 
0089   static base_iterator nonconst_iterator(const_base_iterator it)
0090   {
0091     return {
0092       const_cast<value_type*>(static_cast<const value_type*>(it)),
0093       it.stride()
0094     };
0095   }
0096 
0097   template<typename T>
0098   static iterator<T> nonconst_iterator(const_iterator<T> it)
0099   {
0100     return const_cast<iterator<T>>(it);
0101   }
0102 
0103 private:
0104   template<typename,typename,typename>
0105   friend class packed_segment;
0106 
0107   template<typename Derived>
0108   static const Base* value_ptr(const Derived* p)noexcept
0109   {
0110     return p;
0111   }
0112 };
0113 
0114 } /* namespace poly_collection::detail */
0115 
0116 } /* namespace poly_collection */
0117 
0118 } /* namespace boost */
0119 
0120 #endif