/Src/Dependencies/Boost/boost/spirit/home/support/adapt_adt_attributes.hpp

http://hadesmem.googlecode.com/ · C++ Header · 406 lines · 349 code · 42 blank · 15 comment · 0 complexity · a906ba9bda5eb8cd8cdb165a1b6c5766 MD5 · raw file

  1. // Copyright (c) 2001-2010 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM)
  6. #define BOOST_SPIRIT_ADAPT_ADT_ATTRIBUTES_SEP_15_2010_1219PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/attributes.hpp>
  11. #include <boost/spirit/home/support/container.hpp>
  12. #include <boost/spirit/home/support/numeric_traits.hpp>
  13. #include <boost/fusion/include/adapt_adt.hpp>
  14. #include <boost/utility/enable_if.hpp>
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // customization points allowing to use adapted classes with spirit
  17. namespace boost { namespace spirit { namespace traits
  18. {
  19. ///////////////////////////////////////////////////////////////////////////
  20. template <typename T, int N, bool Const, typename Domain>
  21. struct not_is_variant<
  22. fusion::extension::adt_attribute_proxy<T, N, Const>, Domain>
  23. : not_is_variant<
  24. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  25. , Domain>
  26. {};
  27. template <typename T, int N, bool Const, typename Domain>
  28. struct not_is_optional<
  29. fusion::extension::adt_attribute_proxy<T, N, Const>, Domain>
  30. : not_is_optional<
  31. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  32. , Domain>
  33. {};
  34. ///////////////////////////////////////////////////////////////////////////
  35. template <typename T, int N, bool Const>
  36. struct is_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
  37. : is_container<
  38. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  39. >
  40. {};
  41. template <typename T, int N, bool Const>
  42. struct container_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
  43. : container_value<
  44. typename remove_reference<
  45. typename fusion::extension::adt_attribute_proxy<
  46. T, N, Const
  47. >::type
  48. >::type
  49. >
  50. {};
  51. template <typename T, int N, bool Const>
  52. struct container_value<
  53. fusion::extension::adt_attribute_proxy<T, N, Const> const>
  54. : container_value<
  55. typename add_const<
  56. typename remove_reference<
  57. typename fusion::extension::adt_attribute_proxy<
  58. T, N, Const
  59. >::type
  60. >::type
  61. >::type
  62. >
  63. {};
  64. template <typename T, int N, typename Val>
  65. struct push_back_container<
  66. fusion::extension::adt_attribute_proxy<T, N, false>
  67. , Val
  68. , typename enable_if<is_reference<
  69. typename fusion::extension::adt_attribute_proxy<T, N, false>::type
  70. > >::type>
  71. {
  72. static bool call(
  73. fusion::extension::adt_attribute_proxy<T, N, false>& p
  74. , Val const& val)
  75. {
  76. typedef typename
  77. fusion::extension::adt_attribute_proxy<T, N, false>::type
  78. type;
  79. return push_back(type(p), val);
  80. }
  81. };
  82. template <typename T, int N, bool Const>
  83. struct container_iterator<
  84. fusion::extension::adt_attribute_proxy<T, N, Const> >
  85. : container_iterator<
  86. typename remove_reference<
  87. typename fusion::extension::adt_attribute_proxy<
  88. T, N, Const
  89. >::type
  90. >::type
  91. >
  92. {};
  93. template <typename T, int N, bool Const>
  94. struct container_iterator<
  95. fusion::extension::adt_attribute_proxy<T, N, Const> const>
  96. : container_iterator<
  97. typename add_const<
  98. typename remove_reference<
  99. typename fusion::extension::adt_attribute_proxy<
  100. T, N, Const
  101. >::type
  102. >::type
  103. >::type
  104. >
  105. {};
  106. template <typename T, int N, bool Const>
  107. struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
  108. {
  109. typedef typename remove_reference<
  110. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  111. >::type container_type;
  112. static typename container_iterator<container_type>::type
  113. call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
  114. {
  115. return c.get().begin();
  116. }
  117. };
  118. template <typename T, int N, bool Const>
  119. struct begin_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
  120. {
  121. typedef typename add_const<
  122. typename remove_reference<
  123. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  124. >::type
  125. >::type container_type;
  126. static typename container_iterator<container_type>::type
  127. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
  128. {
  129. return c.get().begin();
  130. }
  131. };
  132. template <typename T, int N, bool Const>
  133. struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> >
  134. {
  135. typedef typename remove_reference<
  136. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  137. >::type container_type;
  138. static typename container_iterator<container_type>::type
  139. call(fusion::extension::adt_attribute_proxy<T, N, Const>& c)
  140. {
  141. return c.get().end();
  142. }
  143. };
  144. template <typename T, int N, bool Const>
  145. struct end_container<fusion::extension::adt_attribute_proxy<T, N, Const> const>
  146. {
  147. typedef typename add_const<
  148. typename remove_reference<
  149. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  150. >::type
  151. >::type container_type;
  152. static typename container_iterator<container_type>::type
  153. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& c)
  154. {
  155. return c.get().end();
  156. }
  157. };
  158. ///////////////////////////////////////////////////////////////////////////
  159. template <typename T, int N, typename Val>
  160. struct assign_to_attribute_from_value<
  161. fusion::extension::adt_attribute_proxy<T, N, false>
  162. , Val>
  163. {
  164. static void
  165. call(Val const& val
  166. , fusion::extension::adt_attribute_proxy<T, N, false>& attr)
  167. {
  168. attr = val;
  169. }
  170. };
  171. template <typename T, int N, bool Const, typename Exposed>
  172. struct extract_from_attribute<
  173. fusion::extension::adt_attribute_proxy<T, N, Const>, Exposed>
  174. {
  175. typedef typename remove_const<
  176. typename remove_reference<
  177. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  178. >::type
  179. >::type embedded_type;
  180. typedef
  181. typename spirit::result_of::extract_from<Exposed, embedded_type>::type
  182. type;
  183. template <typename Context>
  184. static type
  185. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val, Context& ctx)
  186. {
  187. return extract_from<Exposed>(val.get(), ctx);
  188. }
  189. };
  190. ///////////////////////////////////////////////////////////////////////////
  191. template <typename T, int N, bool Const>
  192. struct attribute_type<fusion::extension::adt_attribute_proxy<T, N, Const> >
  193. : fusion::extension::adt_attribute_proxy<T, N, Const>
  194. {};
  195. ///////////////////////////////////////////////////////////////////////////
  196. template <typename T, int N, bool Const>
  197. struct optional_attribute<
  198. fusion::extension::adt_attribute_proxy<T, N, Const> >
  199. {
  200. typedef typename result_of::optional_value<
  201. typename remove_reference<
  202. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  203. >::type
  204. >::type type;
  205. static type
  206. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  207. {
  208. return optional_value(val.get());
  209. }
  210. static bool
  211. is_valid(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  212. {
  213. return has_optional_value(val.get());
  214. }
  215. };
  216. ///////////////////////////////////////////////////////////////////////////
  217. template <typename T, int N, typename Attribute, typename Domain>
  218. struct transform_attribute<
  219. fusion::extension::adt_attribute_proxy<T, N, false>
  220. , Attribute
  221. , Domain
  222. , typename disable_if<is_reference<
  223. typename fusion::extension::adt_attribute_proxy<T, N, false>::type
  224. > >::type>
  225. {
  226. typedef Attribute type;
  227. static Attribute
  228. pre(fusion::extension::adt_attribute_proxy<T, N, false>& val)
  229. {
  230. return val;
  231. }
  232. static void
  233. post(
  234. fusion::extension::adt_attribute_proxy<T, N, false>& val
  235. , Attribute const& attr)
  236. {
  237. val = attr;
  238. }
  239. static void
  240. fail(fusion::extension::adt_attribute_proxy<T, N, false>&)
  241. {
  242. }
  243. };
  244. template <
  245. typename T, int N, bool Const, typename Attribute, typename Domain>
  246. struct transform_attribute<
  247. fusion::extension::adt_attribute_proxy<T, N, Const>
  248. , Attribute
  249. , Domain
  250. , typename enable_if<is_reference<
  251. typename fusion::extension::adt_attribute_proxy<
  252. T, N, Const
  253. >::type
  254. > >::type>
  255. {
  256. typedef Attribute& type;
  257. static Attribute&
  258. pre(fusion::extension::adt_attribute_proxy<T, N, Const>& val)
  259. {
  260. return val;
  261. }
  262. static void
  263. post(
  264. fusion::extension::adt_attribute_proxy<T, N, Const>&
  265. , Attribute const&)
  266. {
  267. }
  268. static void
  269. fail(fusion::extension::adt_attribute_proxy<T, N, Const>&)
  270. {
  271. }
  272. };
  273. template <typename T, int N, bool Const>
  274. struct clear_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
  275. {
  276. static void call(
  277. fusion::extension::adt_attribute_proxy<T, N, Const>& val)
  278. {
  279. typedef typename
  280. fusion::extension::adt_attribute_proxy<T, N, Const>::type
  281. type;
  282. clear(type(val));
  283. }
  284. };
  285. template <typename T, int N, bool Const>
  286. struct attribute_size<fusion::extension::adt_attribute_proxy<T, N, Const> >
  287. {
  288. typedef typename remove_const<
  289. typename remove_reference<
  290. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  291. >::type
  292. >::type embedded_type;
  293. typedef typename attribute_size<embedded_type>::type type;
  294. static type
  295. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  296. {
  297. return attribute_size<embedded_type>::call(val.get());
  298. }
  299. };
  300. ///////////////////////////////////////////////////////////////////////////
  301. // customization point specializations for numeric generators
  302. template <typename T, int N, bool Const>
  303. struct absolute_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
  304. {
  305. typedef typename
  306. fusion::extension::adt_attribute_proxy<T, N, Const>::type
  307. type;
  308. static type
  309. call (fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  310. {
  311. return get_absolute_value(val.get());
  312. }
  313. };
  314. template <typename T, int N, bool Const>
  315. struct is_negative<fusion::extension::adt_attribute_proxy<T, N, Const> >
  316. {
  317. static bool
  318. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  319. {
  320. return test_negative(val.get());
  321. }
  322. };
  323. template <typename T, int N, bool Const>
  324. struct is_zero<fusion::extension::adt_attribute_proxy<T, N, Const> >
  325. {
  326. static bool
  327. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  328. {
  329. return test_zero(val.get());
  330. }
  331. };
  332. template <typename T, int N, bool Const>
  333. struct is_nan<fusion::extension::adt_attribute_proxy<T, N, Const> >
  334. {
  335. static bool
  336. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  337. {
  338. return test_nan(val.get());
  339. }
  340. };
  341. template <typename T, int N, bool Const>
  342. struct is_infinite<fusion::extension::adt_attribute_proxy<T, N, Const> >
  343. {
  344. static bool
  345. call(fusion::extension::adt_attribute_proxy<T, N, Const> const& val)
  346. {
  347. return test_infinite(val.get());
  348. }
  349. };
  350. }}}
  351. ///////////////////////////////////////////////////////////////////////////////
  352. namespace boost { namespace spirit { namespace result_of
  353. {
  354. template <typename T, int N, bool Const>
  355. struct optional_value<fusion::extension::adt_attribute_proxy<T, N, Const> >
  356. : result_of::optional_value<
  357. typename remove_const<
  358. typename remove_reference<
  359. typename fusion::extension::adt_attribute_proxy<T, N, Const>::type
  360. >::type
  361. >::type>
  362. {};
  363. }}}
  364. #endif