blob: b985b6b24ae627e2080a04d4ce3e9298c3237588 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001// Copyright (C) 2004 Arkadiy Vertleyb
2// Distributed under the Boost Software License, Version 1.0. (See accompanying
3// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
Jeff Thompson3d613fd2013-10-15 15:39:04 -07005#ifndef NDNBOOST_TYPEOF_MODIFIERS_HPP_INCLUDED
6#define NDNBOOST_TYPEOF_MODIFIERS_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07007
8#include <ndnboost/typeof/encode_decode.hpp>
9#include <ndnboost/preprocessor/facilities/identity.hpp>
10
Jeff Thompson3d613fd2013-10-15 15:39:04 -070011#include NDNBOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
Jeff Thompsona28eed82013-08-22 16:21:10 -070012
13// modifiers
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#define NDNBOOST_TYPEOF_modifier_support(ID, Fun)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070016 template<class V, class T> struct encode_type_impl<V, Fun(T)>\
17 {\
18 typedef\
19 typename ndnboost::type_of::encode_type<\
20 typename ndnboost::type_of::push_back<\
21 V\
22 , ndnboost::mpl::size_t<ID> >::type\
23 , T>::type\
24 type;\
25 };\
26 template<class Iter> struct decode_type_impl<ndnboost::mpl::size_t<ID>, Iter>\
27 {\
28 typedef ndnboost::type_of::decode_type<Iter> d1;\
29 typedef Fun(typename d1::type) type;\
30 typedef typename d1::iter iter;\
31 }
32
33
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034#define NDNBOOST_TYPEOF_const_fun(T) const T
35#define NDNBOOST_TYPEOF_volatile_fun(T) volatile T
36#define NDNBOOST_TYPEOF_volatile_const_fun(T) volatile const T
37#define NDNBOOST_TYPEOF_pointer_fun(T) T*
38#define NDNBOOST_TYPEOF_reference_fun(T) T&
Jeff Thompsona28eed82013-08-22 16:21:10 -070039
40#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
41//Borland incorrectly handles T const, T const volatile and T volatile.
42//It drops the decoration no matter what, so we need to try to handle T* const etc. without loosing the top modifier.
Jeff Thompson3d613fd2013-10-15 15:39:04 -070043#define NDNBOOST_TYPEOF_const_pointer_fun(T) T const *
44#define NDNBOOST_TYPEOF_const_reference_fun(T) T const &
45#define NDNBOOST_TYPEOF_volatile_pointer_fun(T) T volatile*
46#define NDNBOOST_TYPEOF_volatile_reference_fun(T) T volatile&
47#define NDNBOOST_TYPEOF_volatile_const_pointer_fun(T) T volatile const *
48#define NDNBOOST_TYPEOF_volatile_const_reference_fun(T) T volatile const &
Jeff Thompsona28eed82013-08-22 16:21:10 -070049#endif
50
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051NDNBOOST_TYPEOF_BEGIN_ENCODE_NS
Jeff Thompsona28eed82013-08-22 16:21:10 -070052
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_const_fun);
54NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_volatile_fun);
55NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_volatile_const_fun);
56NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_pointer_fun);
57NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_reference_fun);
Jeff Thompsona28eed82013-08-22 16:21:10 -070058
59#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
Jeff Thompson3d613fd2013-10-15 15:39:04 -070060NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_const_pointer_fun);
61NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_const_reference_fun);
62NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_volatile_pointer_fun);
63NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_volatile_reference_fun);
64NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_volatile_const_pointer_fun);
65NDNBOOST_TYPEOF_modifier_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_TYPEOF_volatile_const_reference_fun);
Jeff Thompsona28eed82013-08-22 16:21:10 -070066#endif
67
Jeff Thompson3d613fd2013-10-15 15:39:04 -070068NDNBOOST_TYPEOF_END_ENCODE_NS
Jeff Thompsona28eed82013-08-22 16:21:10 -070069
Jeff Thompson3d613fd2013-10-15 15:39:04 -070070#undef NDNBOOST_TYPEOF_modifier_support
71#undef NDNBOOST_TYPEOF_const_fun
72#undef NDNBOOST_TYPEOF_volatile_fun
73#undef NDNBOOST_TYPEOF_volatile_const_fun
74#undef NDNBOOST_TYPEOF_pointer_fun
75#undef NDNBOOST_TYPEOF_reference_fun
Jeff Thompsona28eed82013-08-22 16:21:10 -070076
77#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
Jeff Thompson3d613fd2013-10-15 15:39:04 -070078#undef NDNBOOST_TYPEOF_const_pointer_fun
79#undef NDNBOOST_TYPEOF_const_reference_fun
80#undef NDNBOOST_TYPEOF_volatile_pointer_fun
81#undef NDNBOOST_TYPEOF_volatile_reference_fun
82#undef NDNBOOST_TYPEOF_volatile_const_pointer_fun
83#undef NDNBOOST_TYPEOF_volatile_const_reference_fun
Jeff Thompsona28eed82013-08-22 16:21:10 -070084#endif
85
86// arrays
87
Jeff Thompson3d613fd2013-10-15 15:39:04 -070088#define NDNBOOST_TYPEOF_array_support(ID, Qualifier)\
Jeff Thompsona28eed82013-08-22 16:21:10 -070089 template<class V, class T, int N>\
90 struct encode_type_impl<V, Qualifier() T[N]>\
91 {\
92 typedef\
93 typename ndnboost::type_of::encode_type<\
94 typename ndnboost::type_of::push_back<\
95 typename ndnboost::type_of::push_back<\
96 V\
97 , ndnboost::mpl::size_t<ID> >::type\
98 , ndnboost::mpl::size_t<N> >::type\
99 , T>::type\
100 type;\
101 };\
102 template<class Iter>\
103 struct decode_type_impl<ndnboost::mpl::size_t<ID>, Iter>\
104 {\
105 enum{n = Iter::type::value};\
106 typedef ndnboost::type_of::decode_type<typename Iter::next> d;\
107 typedef typename d::type Qualifier() type[n];\
108 typedef typename d::iter iter;\
109 }
110
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700111NDNBOOST_TYPEOF_BEGIN_ENCODE_NS
Jeff Thompsona28eed82013-08-22 16:21:10 -0700112
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700113NDNBOOST_TYPEOF_array_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_PP_EMPTY);
114NDNBOOST_TYPEOF_array_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_PP_IDENTITY(const));
115NDNBOOST_TYPEOF_array_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_PP_IDENTITY(volatile));
116NDNBOOST_TYPEOF_array_support(NDNBOOST_TYPEOF_UNIQUE_ID(), NDNBOOST_PP_IDENTITY(volatile const));
117NDNBOOST_TYPEOF_END_ENCODE_NS
Jeff Thompsona28eed82013-08-22 16:21:10 -0700118
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700119#undef NDNBOOST_TYPEOF_array_support
Jeff Thompsona28eed82013-08-22 16:21:10 -0700120
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700121#endif//NDNBOOST_TYPEOF_MODIFIERS_HPP_INCLUDED