| // Copyright (C) 2004, 2005 Arkadiy Vertleyb |
| // Copyright (C) 2005 Peder Holt |
| // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| |
| #ifndef NDNBOOST_TYPEOF_TYPEOF_IMPL_HPP_INCLUDED |
| #define NDNBOOST_TYPEOF_TYPEOF_IMPL_HPP_INCLUDED |
| |
| #include <ndnboost/mpl/size_t.hpp> |
| #include <ndnboost/preprocessor/repetition/enum.hpp> |
| #include <ndnboost/typeof/encode_decode.hpp> |
| #include <ndnboost/typeof/vector.hpp> |
| #include <ndnboost/type_traits/is_function.hpp> |
| #include <ndnboost/utility/enable_if.hpp> |
| |
| #define NDNBOOST_TYPEOF_VECTOR(n) NDNBOOST_PP_CAT(ndnboost::type_of::vector, n) |
| |
| #define NDNBOOST_TYPEOF_sizer_item(z, n, _)\ |
| char item ## n[V::item ## n ::value]; |
| |
| namespace ndnboost { namespace type_of { |
| template<class V> |
| struct sizer |
| { |
| // char item0[V::item0::value]; |
| // char item1[V::item1::value]; |
| // ... |
| |
| NDNBOOST_PP_REPEAT(NDNBOOST_TYPEOF_LIMIT_SIZE, NDNBOOST_TYPEOF_sizer_item, ~) |
| }; |
| }} |
| |
| #undef NDNBOOST_TYPEOF_sizer_item |
| |
| // |
| namespace ndnboost { namespace type_of { |
| # ifdef NDNBOOST_NO_SFINAE |
| template<class V, class T> |
| sizer<typename encode_type<V, T>::type> encode(const T&); |
| # else |
| template<class V, class T> |
| typename enable_if< |
| typename is_function<T>::type, |
| sizer<typename encode_type<V, T>::type> >::type encode(T&); |
| |
| template<class V, class T> |
| typename disable_if< |
| typename is_function<T>::type, |
| sizer<typename encode_type<V, T>::type> >::type encode(const T&); |
| # endif |
| }} |
| // |
| namespace ndnboost { namespace type_of { |
| |
| template<class V> |
| struct decode_begin |
| { |
| typedef typename decode_type<typename V::begin>::type type; |
| }; |
| }} |
| |
| #define NDNBOOST_TYPEOF_TYPEITEM(z, n, expr)\ |
| ndnboost::mpl::size_t<sizeof(ndnboost::type_of::encode<NDNBOOST_TYPEOF_VECTOR(0)<> >(expr).item ## n)> |
| |
| #define NDNBOOST_TYPEOF_ENCODED_VECTOR(Expr) \ |
| NDNBOOST_TYPEOF_VECTOR(NDNBOOST_TYPEOF_LIMIT_SIZE)< \ |
| NDNBOOST_PP_ENUM(NDNBOOST_TYPEOF_LIMIT_SIZE, NDNBOOST_TYPEOF_TYPEITEM, Expr) \ |
| > |
| |
| #define NDNBOOST_TYPEOF(Expr)\ |
| ndnboost::type_of::decode_begin<NDNBOOST_TYPEOF_ENCODED_VECTOR(Expr) >::type |
| |
| #define NDNBOOST_TYPEOF_TPL typename NDNBOOST_TYPEOF |
| |
| //offset_vector is used to delay the insertion of data into the vector in order to allow |
| //encoding to be done in many steps |
| namespace ndnboost { namespace type_of { |
| template<typename V,typename Offset> |
| struct offset_vector { |
| }; |
| |
| template<class V,class Offset,class T> |
| struct push_back<ndnboost::type_of::offset_vector<V,Offset>,T> { |
| typedef offset_vector<V,typename Offset::prior> type; |
| }; |
| |
| template<class V,class T> |
| struct push_back<ndnboost::type_of::offset_vector<V,mpl::size_t<0> >,T> { |
| typedef typename push_back<V,T>::type type; |
| }; |
| }} |
| |
| #define NDNBOOST_TYPEOF_NESTED_TYPEITEM(z, n, expr)\ |
| NDNBOOST_STATIC_CONSTANT(int,NDNBOOST_PP_CAT(value,n) = sizeof(ndnboost::type_of::encode<_typeof_start_vector>(expr).item ## n));\ |
| typedef ndnboost::mpl::size_t<NDNBOOST_PP_CAT(self_t::value,n)> NDNBOOST_PP_CAT(item,n); |
| |
| #ifdef __DMC__ |
| #define NDNBOOST_TYPEOF_NESTED_TYPEITEM_2(z,n,expr)\ |
| typedef typename _typeof_encode_fraction<iteration>::NDNBOOST_PP_CAT(item,n) NDNBOOST_PP_CAT(item,n); |
| |
| #define NDNBOOST_TYPEOF_FRACTIONTYPE()\ |
| NDNBOOST_PP_REPEAT(NDNBOOST_TYPEOF_LIMIT_SIZE,NDNBOOST_TYPEOF_NESTED_TYPEITEM_2,_)\ |
| typedef _typeof_fraction_iter<Pos> fraction_type; |
| #else |
| #define NDNBOOST_TYPEOF_FRACTIONTYPE()\ |
| typedef _typeof_encode_fraction<self_t::iteration> fraction_type; |
| #endif |
| |
| #ifdef __BORLANDC__ |
| namespace ndnboost { namespace type_of { |
| template<typename Pos,typename Iter> |
| struct generic_typeof_fraction_iter { |
| typedef generic_typeof_fraction_iter<Pos,Iter> self_t; |
| static const int pos=(Pos::value); |
| static const int iteration=(pos/5); |
| static const int where=pos%5; |
| typedef typename Iter::template _apply_next<self_t::iteration>::type fraction_type; |
| typedef generic_typeof_fraction_iter<typename Pos::next,Iter> next; |
| typedef typename v_iter<fraction_type,mpl::int_<self_t::where> >::type type; |
| }; |
| }} |
| #define NDNBOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr) \ |
| template<int _Typeof_Iteration>\ |
| struct _typeof_encode_fraction {\ |
| typedef _typeof_encode_fraction<_Typeof_Iteration> self_t;\ |
| NDNBOOST_STATIC_CONSTANT(int,_typeof_encode_offset = (_Typeof_Iteration*NDNBOOST_TYPEOF_LIMIT_SIZE));\ |
| typedef ndnboost::type_of::offset_vector<NDNBOOST_TYPEOF_VECTOR(0)<>,ndnboost::mpl::size_t<self_t::_typeof_encode_offset> > _typeof_start_vector;\ |
| NDNBOOST_PP_REPEAT(NDNBOOST_TYPEOF_LIMIT_SIZE,NDNBOOST_TYPEOF_NESTED_TYPEITEM,expr)\ |
| template<int Next>\ |
| struct _apply_next {\ |
| typedef _typeof_encode_fraction<Next> type;\ |
| };\ |
| };\ |
| template<typename Pos>\ |
| struct _typeof_fraction_iter {\ |
| typedef ndnboost::type_of::generic_typeof_fraction_iter<Pos,_typeof_encode_fraction<0> > self_t;\ |
| typedef typename self_t::next next;\ |
| typedef typename self_t::type type;\ |
| }; |
| #else |
| #define NDNBOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr) \ |
| template<int _Typeof_Iteration>\ |
| struct _typeof_encode_fraction {\ |
| typedef _typeof_encode_fraction<_Typeof_Iteration> self_t;\ |
| NDNBOOST_STATIC_CONSTANT(int,_typeof_encode_offset = (_Typeof_Iteration*NDNBOOST_TYPEOF_LIMIT_SIZE));\ |
| typedef ndnboost::type_of::offset_vector<NDNBOOST_TYPEOF_VECTOR(0)<>,ndnboost::mpl::size_t<self_t::_typeof_encode_offset> > _typeof_start_vector;\ |
| NDNBOOST_PP_REPEAT(NDNBOOST_TYPEOF_LIMIT_SIZE,NDNBOOST_TYPEOF_NESTED_TYPEITEM,expr)\ |
| };\ |
| template<typename Pos>\ |
| struct _typeof_fraction_iter {\ |
| typedef _typeof_fraction_iter<Pos> self_t;\ |
| NDNBOOST_STATIC_CONSTANT(int,pos=(Pos::value));\ |
| NDNBOOST_STATIC_CONSTANT(int,iteration=(pos/NDNBOOST_TYPEOF_LIMIT_SIZE));\ |
| NDNBOOST_STATIC_CONSTANT(int,where=pos%NDNBOOST_TYPEOF_LIMIT_SIZE);\ |
| NDNBOOST_TYPEOF_FRACTIONTYPE()\ |
| typedef typename ndnboost::type_of::v_iter<fraction_type,ndnboost::mpl::int_<self_t::where> >::type type;\ |
| typedef _typeof_fraction_iter<typename Pos::next> next;\ |
| }; |
| #endif |
| #ifdef __MWERKS__ |
| |
| # define NDNBOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \ |
| template<typename T>\ |
| struct NDNBOOST_PP_CAT(_typeof_template_,name) {\ |
| NDNBOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr)\ |
| typedef typename ndnboost::type_of::decode_type<_typeof_fraction_iter<ndnboost::mpl::size_t<0> > >::type type;\ |
| };\ |
| typedef NDNBOOST_PP_CAT(_typeof_template_,name)<int> name; |
| |
| # define NDNBOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) NDNBOOST_TYPEOF_NESTED_TYPEDEF(name,expr) |
| |
| #else |
| # define NDNBOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) \ |
| struct name {\ |
| NDNBOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr)\ |
| typedef typename ndnboost::type_of::decode_type<_typeof_fraction_iter<ndnboost::mpl::size_t<0> > >::type type;\ |
| }; |
| |
| # define NDNBOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \ |
| struct name {\ |
| NDNBOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr)\ |
| typedef ndnboost::type_of::decode_type<_typeof_fraction_iter<ndnboost::mpl::size_t<0> > >::type type;\ |
| }; |
| #endif |
| |
| #endif//NDNBOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED |