blob: afd65dfa469e06ab8ed0bcf99fec3b25f04a4c74 [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
5#ifndef BOOST_TYPEOF_MODIFIERS_HPP_INCLUDED
6#define BOOST_TYPEOF_MODIFIERS_HPP_INCLUDED
7
8#include <ndnboost/typeof/encode_decode.hpp>
9#include <ndnboost/preprocessor/facilities/identity.hpp>
10
11#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
12
13// modifiers
14
15#define BOOST_TYPEOF_modifier_support(ID, Fun)\
16 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
34#define BOOST_TYPEOF_const_fun(T) const T
35#define BOOST_TYPEOF_volatile_fun(T) volatile T
36#define BOOST_TYPEOF_volatile_const_fun(T) volatile const T
37#define BOOST_TYPEOF_pointer_fun(T) T*
38#define BOOST_TYPEOF_reference_fun(T) T&
39
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.
43#define BOOST_TYPEOF_const_pointer_fun(T) T const *
44#define BOOST_TYPEOF_const_reference_fun(T) T const &
45#define BOOST_TYPEOF_volatile_pointer_fun(T) T volatile*
46#define BOOST_TYPEOF_volatile_reference_fun(T) T volatile&
47#define BOOST_TYPEOF_volatile_const_pointer_fun(T) T volatile const *
48#define BOOST_TYPEOF_volatile_const_reference_fun(T) T volatile const &
49#endif
50
51BOOST_TYPEOF_BEGIN_ENCODE_NS
52
53BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_const_fun);
54BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_fun);
55BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_const_fun);
56BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_pointer_fun);
57BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_reference_fun);
58
59#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
60BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_const_pointer_fun);
61BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_const_reference_fun);
62BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_pointer_fun);
63BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_reference_fun);
64BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_const_pointer_fun);
65BOOST_TYPEOF_modifier_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_TYPEOF_volatile_const_reference_fun);
66#endif
67
68BOOST_TYPEOF_END_ENCODE_NS
69
70#undef BOOST_TYPEOF_modifier_support
71#undef BOOST_TYPEOF_const_fun
72#undef BOOST_TYPEOF_volatile_fun
73#undef BOOST_TYPEOF_volatile_const_fun
74#undef BOOST_TYPEOF_pointer_fun
75#undef BOOST_TYPEOF_reference_fun
76
77#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
78#undef BOOST_TYPEOF_const_pointer_fun
79#undef BOOST_TYPEOF_const_reference_fun
80#undef BOOST_TYPEOF_volatile_pointer_fun
81#undef BOOST_TYPEOF_volatile_reference_fun
82#undef BOOST_TYPEOF_volatile_const_pointer_fun
83#undef BOOST_TYPEOF_volatile_const_reference_fun
84#endif
85
86// arrays
87
88#define BOOST_TYPEOF_array_support(ID, Qualifier)\
89 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
111BOOST_TYPEOF_BEGIN_ENCODE_NS
112
113BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_PP_EMPTY);
114BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_PP_IDENTITY(const));
115BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_PP_IDENTITY(volatile));
116BOOST_TYPEOF_array_support(BOOST_TYPEOF_UNIQUE_ID(), BOOST_PP_IDENTITY(volatile const));
117BOOST_TYPEOF_END_ENCODE_NS
118
119#undef BOOST_TYPEOF_array_support
120
121#endif//BOOST_TYPEOF_MODIFIERS_HPP_INCLUDED