PageRenderTime 67ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Core/Dependencies/Boost/boost/typeof/msvc/typeof_impl.hpp

https://bitbucket.org/barakianc/nvidia-physx-and-apex-in-gge
C++ Header | 283 lines | 221 code | 40 blank | 22 comment | 6 complexity | b4f1c98c85b37364c5e48d11608c7ec0 MD5 | raw file
  1. // Copyright (C) 2005 Igor Chesnokov, mailto:ichesnokov@gmail.com (VC 6.5,VC 7.1 + counter code)
  2. // Copyright (C) 2005-2007 Peder Holt (VC 7.0 + framework)
  3. // Copyright (C) 2006 Steven Watanabe (VC 8.0)
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED
  7. # define BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED
  8. # include <boost/config.hpp>
  9. # include <boost/detail/workaround.hpp>
  10. # include <boost/mpl/int.hpp>
  11. # include <boost/type_traits/is_function.hpp>
  12. # include <boost/utility/enable_if.hpp>
  13. # if BOOST_WORKAROUND(BOOST_MSVC,>=1310)
  14. # include <typeinfo>
  15. # endif
  16. namespace boost
  17. {
  18. namespace type_of
  19. {
  20. //Compile time constant code
  21. # if BOOST_WORKAROUND(BOOST_MSVC,>=1300) && defined(_MSC_EXTENSIONS)
  22. template<int N> struct the_counter;
  23. template<typename T,int N = 5/*for similarity*/>
  24. struct encode_counter
  25. {
  26. __if_exists(the_counter<N + 256>)
  27. {
  28. BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 257>::count));
  29. }
  30. __if_not_exists(the_counter<N + 256>)
  31. {
  32. __if_exists(the_counter<N + 64>)
  33. {
  34. BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 65>::count));
  35. }
  36. __if_not_exists(the_counter<N + 64>)
  37. {
  38. __if_exists(the_counter<N + 16>)
  39. {
  40. BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 17>::count));
  41. }
  42. __if_not_exists(the_counter<N + 16>)
  43. {
  44. __if_exists(the_counter<N + 4>)
  45. {
  46. BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 5>::count));
  47. }
  48. __if_not_exists(the_counter<N + 4>)
  49. {
  50. __if_exists(the_counter<N>)
  51. {
  52. BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 1>::count));
  53. }
  54. __if_not_exists(the_counter<N>)
  55. {
  56. BOOST_STATIC_CONSTANT(unsigned,count=N);
  57. typedef the_counter<N> type;
  58. }
  59. }
  60. }
  61. }
  62. }
  63. };
  64. # define BOOST_TYPEOF_INDEX(T) (encode_counter<T>::count)
  65. # define BOOST_TYPEOF_NEXT_INDEX(next)
  66. # else
  67. template<int N> struct encode_counter : encode_counter<N - 1> {};
  68. template<> struct encode_counter<0> {};
  69. //Need to default to a larger value than 4, as due to MSVC's ETI errors. (sizeof(int)==4)
  70. char (*encode_index(...))[5];
  71. # define BOOST_TYPEOF_INDEX(T) (sizeof(*boost::type_of::encode_index((boost::type_of::encode_counter<1005>*)0)))
  72. # define BOOST_TYPEOF_NEXT_INDEX(next) friend char (*encode_index(encode_counter<next>*))[next];
  73. # endif
  74. //Typeof code
  75. # if BOOST_WORKAROUND(BOOST_MSVC,==1300)
  76. template<typename ID>
  77. struct msvc_extract_type
  78. {
  79. template<bool>
  80. struct id2type_impl;
  81. typedef id2type_impl<true> id2type;
  82. };
  83. template<typename T, typename ID>
  84. struct msvc_register_type : msvc_extract_type<ID>
  85. {
  86. template<>
  87. struct id2type_impl<true> //VC7.0 specific bugfeature
  88. {
  89. typedef T type;
  90. };
  91. };
  92. #elif BOOST_WORKAROUND(BOOST_MSVC,>=1400)
  93. struct msvc_extract_type_default_param {};
  94. template<typename ID, typename T = msvc_extract_type_default_param>
  95. struct msvc_extract_type;
  96. template<typename ID>
  97. struct msvc_extract_type<ID, msvc_extract_type_default_param> {
  98. template<bool>
  99. struct id2type_impl;
  100. typedef id2type_impl<true> id2type;
  101. };
  102. template<typename ID, typename T>
  103. struct msvc_extract_type : msvc_extract_type<ID,msvc_extract_type_default_param>
  104. {
  105. template<>
  106. struct id2type_impl<true> //VC8.0 specific bugfeature
  107. {
  108. typedef T type;
  109. };
  110. template<bool>
  111. struct id2type_impl;
  112. typedef id2type_impl<true> id2type;
  113. };
  114. template<typename T, typename ID>
  115. struct msvc_register_type : msvc_extract_type<ID, T>
  116. {
  117. };
  118. # else
  119. template<typename ID>
  120. struct msvc_extract_type
  121. {
  122. struct id2type;
  123. };
  124. template<typename T, typename ID>
  125. struct msvc_register_type : msvc_extract_type<ID>
  126. {
  127. typedef msvc_extract_type<ID> base_type;
  128. struct base_type::id2type // This uses nice VC6.5 and VC7.1 bugfeature
  129. {
  130. typedef T type;
  131. };
  132. };
  133. # endif
  134. // EAN: preprocess this block out on advice of Peder Holt
  135. // to eliminate errors in type_traits/common_type.hpp
  136. # if 0 //BOOST_WORKAROUND(BOOST_MSVC,==1310)
  137. template<const std::type_info& ref_type_info>
  138. struct msvc_typeid_wrapper {
  139. typedef typename msvc_extract_type<msvc_typeid_wrapper>::id2type id2type;
  140. typedef typename id2type::type wrapped_type;
  141. typedef typename wrapped_type::type type;
  142. };
  143. //This class is used for registering the type T. encode_type<T> is mapped against typeid(encode_type<T>).
  144. //msvc_typeid_wrapper<typeid(encode_type<T>)> will now have a type typedef that equals encode_type<T>.
  145. template<typename T>
  146. struct encode_type
  147. {
  148. typedef encode_type<T> input_type;
  149. //Invoke registration of encode_type<T>. typeid(encode_type<T>) is now mapped to encode_type<T>. Do not use registered_type for anything.
  150. //The reason for registering encode_type<T> rather than T, is that VC handles typeid(function reference) poorly. By adding another
  151. //level of indirection, we solve this problem.
  152. typedef typename msvc_register_type<input_type,msvc_typeid_wrapper<typeid(input_type)> >::id2type registered_type;
  153. typedef T type;
  154. };
  155. template<typename T> typename disable_if<
  156. typename is_function<T>::type,
  157. typename encode_type<T>::input_type>::type encode_start(T const&);
  158. template<typename T> typename enable_if<
  159. typename is_function<T>::type,
  160. typename encode_type<T>::input_type>::type encode_start(T&);
  161. template<typename Organizer, typename T>
  162. msvc_register_type<T,Organizer> typeof_register_type(const T&);
  163. # define BOOST_TYPEOF(expr) \
  164. boost::type_of::msvc_typeid_wrapper<typeid(boost::type_of::encode_start(expr))>::type
  165. # define BOOST_TYPEOF_TPL(expr) typename BOOST_TYPEOF(expr)
  166. # define BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) \
  167. struct name {\
  168. enum {_typeof_register_value=sizeof(typeid(boost::type_of::typeof_register_type<name>(expr)))};\
  169. typedef typename boost::type_of::msvc_extract_type<name>::id2type id2type;\
  170. typedef typename id2type::type type;\
  171. };
  172. # define BOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \
  173. struct name {\
  174. enum {_typeof_register_value=sizeof(typeid(boost::type_of::typeof_register_type<name>(expr)))};\
  175. typedef boost::type_of::msvc_extract_type<name>::id2type id2type;\
  176. typedef id2type::type type;\
  177. };
  178. # else
  179. template<int ID>
  180. struct msvc_typeid_wrapper {
  181. typedef typename msvc_extract_type<mpl::int_<ID> >::id2type id2type;
  182. typedef typename id2type::type type;
  183. };
  184. //Workaround for ETI-bug for VC6 and VC7
  185. template<>
  186. struct msvc_typeid_wrapper<1> {
  187. typedef msvc_typeid_wrapper<1> type;
  188. };
  189. //Workaround for ETI-bug for VC7.1
  190. template<>
  191. struct msvc_typeid_wrapper<4> {
  192. typedef msvc_typeid_wrapper<4> type;
  193. };
  194. //Tie it all together
  195. template<typename T>
  196. struct encode_type
  197. {
  198. //Get the next available compile time constants index
  199. BOOST_STATIC_CONSTANT(unsigned,value=BOOST_TYPEOF_INDEX(T));
  200. //Instantiate the template
  201. typedef typename msvc_register_type<T,mpl::int_<value> >::id2type type;
  202. //Set the next compile time constants index
  203. BOOST_STATIC_CONSTANT(unsigned,next=value+1);
  204. //Increment the compile time constant (only needed when extensions are not active
  205. BOOST_TYPEOF_NEXT_INDEX(next);
  206. };
  207. template<class T>
  208. struct sizer
  209. {
  210. typedef char(*type)[encode_type<T>::value];
  211. };
  212. # if BOOST_WORKAROUND(BOOST_MSVC,>=1310)
  213. template<typename T> typename disable_if<
  214. typename is_function<T>::type,
  215. typename sizer<T>::type>::type encode_start(T const&);
  216. template<typename T> typename enable_if<
  217. typename is_function<T>::type,
  218. typename sizer<T>::type>::type encode_start(T&);
  219. # else
  220. template<typename T>
  221. typename sizer<T>::type encode_start(T const&);
  222. # endif
  223. template<typename Organizer, typename T>
  224. msvc_register_type<T,Organizer> typeof_register_type(const T&,Organizer* =0);
  225. # define BOOST_TYPEOF(expr) \
  226. boost::type_of::msvc_typeid_wrapper<sizeof(*boost::type_of::encode_start(expr))>::type
  227. # define BOOST_TYPEOF_TPL(expr) typename BOOST_TYPEOF(expr)
  228. # define BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) \
  229. struct name {\
  230. BOOST_STATIC_CONSTANT(int,_typeof_register_value=sizeof(boost::type_of::typeof_register_type<name>(expr)));\
  231. typedef typename boost::type_of::msvc_extract_type<name>::id2type id2type;\
  232. typedef typename id2type::type type;\
  233. };
  234. # define BOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \
  235. struct name {\
  236. BOOST_STATIC_CONSTANT(int,_typeof_register_value=sizeof(boost::type_of::typeof_register_type<name>(expr)));\
  237. typedef boost::type_of::msvc_extract_type<name>::id2type id2type;\
  238. typedef id2type::type type;\
  239. };
  240. #endif
  241. }
  242. }
  243. #endif//BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED