construct.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. http://spirit.sourceforge.net/
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(BOOST_SPIRIT_CONSTRUCT_MAR_24_2007_0629PM)
  8. #define BOOST_SPIRIT_CONSTRUCT_MAR_24_2007_0629PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/config.hpp>
  13. #include <boost/spirit/home/qi/parse.hpp>
  14. #include <boost/spirit/home/support/common_terminals.hpp>
  15. #include <boost/spirit/home/support/attributes_fwd.hpp>
  16. namespace boost { namespace spirit { namespace traits
  17. {
  18. ///////////////////////////////////////////////////////////////////////////
  19. // We provide overloads for the assign_to_attribute_from_iterators
  20. // customization point for all built in types
  21. ///////////////////////////////////////////////////////////////////////////
  22. template <typename Iterator>
  23. struct assign_to_attribute_from_iterators<char, Iterator>
  24. {
  25. static void
  26. call(Iterator const& first, Iterator const&, char& attr)
  27. {
  28. attr = *first;
  29. }
  30. };
  31. template <typename Iterator>
  32. struct assign_to_attribute_from_iterators<signed char, Iterator>
  33. {
  34. static void
  35. call(Iterator const& first, Iterator const&, signed char& attr)
  36. {
  37. attr = *first;
  38. }
  39. };
  40. template <typename Iterator>
  41. struct assign_to_attribute_from_iterators<unsigned char, Iterator>
  42. {
  43. static void
  44. call(Iterator const& first, Iterator const&, unsigned char& attr)
  45. {
  46. attr = *first;
  47. }
  48. };
  49. // wchar_t is intrinsic
  50. template <typename Iterator>
  51. struct assign_to_attribute_from_iterators<wchar_t, Iterator>
  52. {
  53. static void
  54. call(Iterator const& first, Iterator const&, wchar_t& attr)
  55. {
  56. attr = *first;
  57. }
  58. };
  59. #if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
  60. // wchar_t is intrinsic, have separate overload for unsigned short
  61. template <typename Iterator>
  62. struct assign_to_attribute_from_iterators<unsigned short, Iterator>
  63. {
  64. static void
  65. call(Iterator const& first, Iterator const&, unsigned short& attr)
  66. {
  67. attr = *first;
  68. }
  69. };
  70. #endif
  71. template <typename Iterator>
  72. struct assign_to_attribute_from_iterators<bool, Iterator>
  73. {
  74. static void
  75. call(Iterator const& first, Iterator const& last, bool& attr)
  76. {
  77. Iterator first_ = first;
  78. qi::parse(first_, last, bool_type(), attr);
  79. }
  80. };
  81. template <typename Iterator>
  82. struct assign_to_attribute_from_iterators<short, Iterator>
  83. {
  84. static void
  85. call(Iterator const& first, Iterator const& last, short& attr)
  86. {
  87. Iterator first_ = first;
  88. qi::parse(first_, last, short_type(), attr);
  89. }
  90. };
  91. template <typename Iterator>
  92. struct assign_to_attribute_from_iterators<int, Iterator>
  93. {
  94. static void
  95. call(Iterator const& first, Iterator const& last, int& attr)
  96. {
  97. Iterator first_ = first;
  98. qi::parse(first_, last, int_type(), attr);
  99. }
  100. };
  101. template <typename Iterator>
  102. struct assign_to_attribute_from_iterators<unsigned int, Iterator>
  103. {
  104. static void
  105. call(Iterator const& first, Iterator const& last, unsigned int& attr)
  106. {
  107. Iterator first_ = first;
  108. qi::parse(first_, last, uint_type(), attr);
  109. }
  110. };
  111. template <typename Iterator>
  112. struct assign_to_attribute_from_iterators<long, Iterator>
  113. {
  114. static void
  115. call(Iterator const& first, Iterator const& last, long& attr)
  116. {
  117. Iterator first_ = first;
  118. qi::parse(first_, last, long_type(), attr);
  119. }
  120. };
  121. template <typename Iterator>
  122. struct assign_to_attribute_from_iterators<unsigned long, Iterator>
  123. {
  124. static void
  125. call(Iterator const& first, Iterator const& last, unsigned long& attr)
  126. {
  127. Iterator first_ = first;
  128. qi::parse(first_, last, ulong_type(), attr);
  129. }
  130. };
  131. #ifdef BOOST_HAS_LONG_LONG
  132. template <typename Iterator>
  133. struct assign_to_attribute_from_iterators<boost::long_long_type, Iterator>
  134. {
  135. static void
  136. call(Iterator const& first, Iterator const& last, boost::long_long_type& attr)
  137. {
  138. Iterator first_ = first;
  139. qi::parse(first_, last, long_long_type(), attr);
  140. }
  141. };
  142. template <typename Iterator>
  143. struct assign_to_attribute_from_iterators<boost::ulong_long_type, Iterator>
  144. {
  145. static void
  146. call(Iterator const& first, Iterator const& last, boost::ulong_long_type& attr)
  147. {
  148. Iterator first_ = first;
  149. qi::parse(first_, last, ulong_long_type(), attr);
  150. }
  151. };
  152. #endif
  153. template <typename Iterator>
  154. struct assign_to_attribute_from_iterators<float, Iterator>
  155. {
  156. static void
  157. call(Iterator const& first, Iterator const& last, float& attr)
  158. {
  159. Iterator first_ = first;
  160. qi::parse(first_, last, float_type(), attr);
  161. }
  162. };
  163. template <typename Iterator>
  164. struct assign_to_attribute_from_iterators<double, Iterator>
  165. {
  166. static void
  167. call(Iterator const& first, Iterator const& last, double& attr)
  168. {
  169. Iterator first_ = first;
  170. qi::parse(first_, last, double_type(), attr);
  171. }
  172. };
  173. template <typename Iterator>
  174. struct assign_to_attribute_from_iterators<long double, Iterator>
  175. {
  176. static void
  177. call(Iterator const& first, Iterator const& last, long double& attr)
  178. {
  179. Iterator first_ = first;
  180. qi::parse(first_, last, long_double_type(), attr);
  181. }
  182. };
  183. }}}
  184. #endif