stlab.adobe.com Adobe Systems Incorporated
type_inspection.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 
10 #ifndef ADOBE_TYPE_INSPECTION_HPP
11 #define ADOBE_TYPE_INSPECTION_HPP
12 
13 
14 
15 namespace adobe
16 {
17 
18 
19 namespace detail
20 {
21  struct yes_struct {char a;};
22  struct no_struct { yes_struct a[2];};
23 }
24 
37 #define ADOBE_HAS_TYPE_IMPL(TypeInQuestion) \
38 template< \
39  typename C##TypeInQuestion> \
40 struct has_type##TypeInQuestion \
41 { \
42  template <typename T##TypeInQuestion> \
43  static adobe::detail::yes_struct SFINAE(typename T##TypeInQuestion::TypeInQuestion*); \
44  template <typename> \
45  static adobe::detail::no_struct SFINAE(...); \
46  static const bool value = sizeof(SFINAE<C##TypeInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
47 }
48 
65 #define ADOBE_HAS_TYPE(C, TypeInQuestion) \
66 has_type##TypeInQuestion<C>::value
67 
68 
74 // one of the most important types to look for is 'type', so let's just implement that one here
75 template <typename T>
77 {
78  ADOBE_HAS_TYPE_IMPL(type);
79 
80  static const bool value = ADOBE_HAS_TYPE(T, type);
81 };
82 
83 template <typename T, typename Default>
85 {
86  template <bool condition, typename IFtype, typename ELSEtype>
87  struct if_has_type
88  {
89  typedef typename IFtype::type type;
90  };
91  template <typename IFtype, typename ELSEtype>
92  struct if_has_type<false, IFtype, ELSEtype>
93  {
94  typedef ELSEtype type;
95  };
96  typedef typename if_has_type<has_type_type<T>::value, T, Default>::type type;
97 };
98 
99 
116 #if _MSC_VER <= 1400
117 #define ADOBE_HAS_MEMBER_IMPL(Member) \
118 template <class Class> \
119 struct has_member##Member \
120 { \
121  __if_exists(Class::Member) \
122  { \
123  static const bool value = true; \
124  } \
125  __if_not_exists(Class::Member) \
126  { \
127  static const bool value = false; \
128  } \
129 }
130 #else
131 
132 namespace detail
133 {
134  template<size_t>
135  struct member_test_helper
136  {
137  };
138 }
139 
140 #define ADOBE_HAS_MEMBER_IMPL(MemberInQuestion) \
141 template <class Class> \
142 struct has_member##MemberInQuestion \
143 { \
144  template <class T##MemberInQuestion> \
145  static adobe::detail::yes_struct SFINAE( adobe::detail::member_test_helper<sizeof(&T##MemberInQuestion::MemberInQuestion)> * ); \
146  template<class> \
147  static adobe::detail::no_struct SFINAE(...); \
148  static const bool value = sizeof(SFINAE<Class>(0)) == sizeof(adobe::detail::yes_struct); \
149 }
150 #endif
151 
168 #define ADOBE_HAS_MEMBER(C, MemberInQuestion) \
169 has_member##MemberInQuestion<C>::value
170 
171 
184 #define ADOBE_HAS_TEMPLATE1_IMPL(TemplateInQuestion) \
185 template< \
186  typename C##TemplateInQuestion> \
187 struct has_template1##TemplateInQuestion \
188 { \
189  template <typename T##TemplateInQuestion> \
190  static adobe::detail::yes_struct SFINAE(typename T##TemplateInQuestion::template TemplateInQuestion<int>*); \
191  template <typename> \
192  static adobe::detail::no_struct SFINAE(...); \
193  static const bool value = sizeof(SFINAE<C##TemplateInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
194 }
195 
217 #define ADOBE_HAS_TEMPLATE1(C, TemplateInQuestion) \
218 has_template1##TemplateInQuestion<C>::value
219 
220 
222 // 2 Arg case
223 //
224 #define ADOBE_HAS_TEMPLATE2_IMPL(TemplateInQuestion) \
225 template< \
226  typename C##TemplateInQuestion> \
227 struct has_template2##TemplateInQuestion \
228 { \
229  template <typename T##TemplateInQuestion> \
230  static adobe::detail::yes_struct SFINAE(typename T##TemplateInQuestion::template TemplateInQuestion<int, int>*); \
231  template <typename> \
232  static adobe::detail::no_struct SFINAE(...); \
233  static const bool value = sizeof(SFINAE<C##TemplateInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
234 }
235 
236 #define ADOBE_HAS_TEMPLATE2(C, TemplateInQuestion) \
237 has_template2##TemplateInQuestion<C>::value
238 
239 #define ADOBE_HAS_TEMPLATE3_IMPL(TemplateInQuestion) \
240 template< \
241  typename C##TemplateInQuestion> \
242 struct has_template3##TemplateInQuestion \
243 { \
244  template <typename T##TemplateInQuestion> \
245  static adobe::detail::yes_struct SFINAE(typename T##TemplateInQuestion::template TemplateInQuestion<int, int, int>*); \
246  template <typename> \
247  static adobe::detail::no_struct SFINAE(...); \
248  static const bool value = sizeof(SFINAE<C##TemplateInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
249 }
250 
251 #define ADOBE_HAS_TEMPLATE3(C, TemplateInQuestion) \
252 has_template3##TemplateInQuestion<C>::value
253 
254 
255 } // namespace
256 
257 #endif // include guard
258 

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google