/src/contrib/boost/spirit/home/classic/phoenix/special_ops.hpp

http://pythonocc.googlecode.com/ · C++ Header · 341 lines · 192 code · 38 blank · 111 comment · 6 complexity · 2a33ea5a90e315057dbe68494bdc244a MD5 · raw file

  1. /*=============================================================================
  2. Phoenix V1.2.1
  3. Copyright (c) 2001-2002 Joel de Guzman
  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. #ifndef PHOENIX_SPECIAL_OPS_HPP
  8. #define PHOENIX_SPECIAL_OPS_HPP
  9. #include <boost/config.hpp>
  10. #ifdef BOOST_NO_STRINGSTREAM
  11. #include <strstream>
  12. #define PHOENIX_SSTREAM strstream
  13. #else
  14. #include <sstream>
  15. #define PHOENIX_SSTREAM stringstream
  16. #endif
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <boost/spirit/home/classic/phoenix/operators.hpp>
  19. #include <iosfwd>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #if defined(_STLPORT_VERSION) && defined(__STL_USE_OWN_NAMESPACE)
  22. #define PHOENIX_STD _STLP_STD
  23. #define PHOENIX_NO_STD_NAMESPACE
  24. #else
  25. #define PHOENIX_STD std
  26. #endif
  27. ///////////////////////////////////////////////////////////////////////////////
  28. //#if !defined(PHOENIX_NO_STD_NAMESPACE)
  29. namespace PHOENIX_STD
  30. {
  31. //#endif
  32. template<typename T> class complex;
  33. //#if !defined(PHOENIX_NO_STD_NAMESPACE)
  34. }
  35. //#endif
  36. ///////////////////////////////////////////////////////////////////////////////
  37. namespace phoenix
  38. {
  39. ///////////////////////////////////////////////////////////////////////////////
  40. //
  41. // The following specializations take into account the C++ standard
  42. // library components. There are a couple of issues that have to be
  43. // dealt with to enable lazy operator overloads for the standard
  44. // library classes.
  45. //
  46. // *iostream (e.g. cout, cin, strstream/ stringstream) uses non-
  47. // canonical shift operator overloads where the lhs is taken in
  48. // by reference.
  49. //
  50. // *I/O manipulators overloads for the RHS of the << and >>
  51. // operators.
  52. //
  53. // *STL iterators can be objects that conform to pointer semantics.
  54. // Some operators need to be specialized for these.
  55. //
  56. // *std::complex is given a rank (see rank class in operators.hpp)
  57. //
  58. ///////////////////////////////////////////////////////////////////////////////
  59. ///////////////////////////////////////////////////////////////////////////////
  60. //
  61. // specialization for rank<std::complex>
  62. //
  63. ///////////////////////////////////////////////////////////////////////////////
  64. template <typename T> struct rank<PHOENIX_STD::complex<T> >
  65. { static int const value = 170 + rank<T>::value; };
  66. ///////////////////////////////////////////////////////////////////////////////
  67. //
  68. // specializations for std::istream
  69. //
  70. ///////////////////////////////////////////////////////////////////////////////
  71. #if defined(__GNUC__) && (__GNUC__ < 3)
  72. #if defined(_STLPORT_VERSION)
  73. #define PHOENIX_ISTREAM _IO_istream_withassign
  74. #else
  75. #define PHOENIX_ISTREAM PHOENIX_STD::_IO_istream_withassign
  76. #endif
  77. #else
  78. // #if (defined(__ICL) && defined(_STLPORT_VERSION))
  79. // #define PHOENIX_ISTREAM istream_withassign
  80. // #else
  81. #define PHOENIX_ISTREAM PHOENIX_STD::istream
  82. // #endif
  83. #endif
  84. //////////////////////////////////
  85. #if defined(__GNUC__) && (__GNUC__ < 3)
  86. // || (defined(__ICL) && defined(_STLPORT_VERSION))
  87. template <typename T1>
  88. struct binary_operator<shift_r_op, PHOENIX_ISTREAM, T1>
  89. {
  90. typedef PHOENIX_STD::istream& result_type;
  91. static result_type eval(PHOENIX_STD::istream& out, T1& rhs)
  92. { return out >> rhs; }
  93. };
  94. #endif
  95. //////////////////////////////////
  96. template <typename T1>
  97. struct binary_operator<shift_r_op, PHOENIX_STD::istream, T1>
  98. {
  99. typedef PHOENIX_STD::istream& result_type;
  100. static result_type eval(PHOENIX_STD::istream& out, T1& rhs)
  101. { return out >> rhs; }
  102. };
  103. //////////////////////////////////
  104. template <typename BaseT>
  105. inline typename impl::make_binary3
  106. <shift_r_op, variable<PHOENIX_ISTREAM>, BaseT>::type
  107. operator>>(PHOENIX_ISTREAM& _0, actor<BaseT> const& _1)
  108. {
  109. return impl::make_binary3
  110. <shift_r_op, variable<PHOENIX_ISTREAM>, BaseT>
  111. ::construct(var(_0), _1);
  112. }
  113. #undef PHOENIX_ISTREAM
  114. ///////////////////////////////////////////////////////////////////////////////
  115. //
  116. // specializations for std::ostream
  117. //
  118. ///////////////////////////////////////////////////////////////////////////////
  119. #if defined(__GNUC__) && (__GNUC__ < 3)
  120. #if defined(_STLPORT_VERSION)
  121. #define PHOENIX_OSTREAM _IO_ostream_withassign
  122. #else
  123. #define PHOENIX_OSTREAM PHOENIX_STD::_IO_ostream_withassign
  124. #endif
  125. #else
  126. // #if (defined(__ICL) && defined(_STLPORT_VERSION))
  127. // #define PHOENIX_OSTREAM ostream_withassign
  128. // #else
  129. #define PHOENIX_OSTREAM PHOENIX_STD::ostream
  130. // #endif
  131. #endif
  132. //////////////////////////////////
  133. #if defined(__GNUC__) && (__GNUC__ < 3)
  134. // || (defined(__ICL) && defined(_STLPORT_VERSION))
  135. template <typename T1>
  136. struct binary_operator<shift_l_op, PHOENIX_OSTREAM, T1>
  137. {
  138. typedef PHOENIX_STD::ostream& result_type;
  139. static result_type eval(PHOENIX_STD::ostream& out, T1 const& rhs)
  140. { return out << rhs; }
  141. };
  142. #endif
  143. //////////////////////////////////
  144. template <typename T1>
  145. struct binary_operator<shift_l_op, PHOENIX_STD::ostream, T1>
  146. {
  147. typedef PHOENIX_STD::ostream& result_type;
  148. static result_type eval(PHOENIX_STD::ostream& out, T1 const& rhs)
  149. { return out << rhs; }
  150. };
  151. //////////////////////////////////
  152. template <typename BaseT>
  153. inline typename impl::make_binary3
  154. <shift_l_op, variable<PHOENIX_OSTREAM>, BaseT>::type
  155. operator<<(PHOENIX_OSTREAM& _0, actor<BaseT> const& _1)
  156. {
  157. return impl::make_binary3
  158. <shift_l_op, variable<PHOENIX_OSTREAM>, BaseT>
  159. ::construct(var(_0), _1);
  160. }
  161. #undef PHOENIX_OSTREAM
  162. ///////////////////////////////////////////////////////////////////////////////
  163. //
  164. // specializations for std::strstream / stringstream
  165. //
  166. ///////////////////////////////////////////////////////////////////////////////
  167. template <typename T1>
  168. struct binary_operator<shift_r_op, PHOENIX_STD::PHOENIX_SSTREAM, T1>
  169. {
  170. typedef PHOENIX_STD::istream& result_type;
  171. static result_type eval(PHOENIX_STD::istream& out, T1& rhs)
  172. { return out >> rhs; }
  173. };
  174. //////////////////////////////////
  175. template <typename BaseT>
  176. inline typename impl::make_binary3
  177. <shift_r_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>::type
  178. operator>>(PHOENIX_STD::PHOENIX_SSTREAM& _0, actor<BaseT> const& _1)
  179. {
  180. return impl::make_binary3
  181. <shift_r_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>
  182. ::construct(var(_0), _1);
  183. }
  184. //////////////////////////////////
  185. template <typename T1>
  186. struct binary_operator<shift_l_op, PHOENIX_STD::PHOENIX_SSTREAM, T1>
  187. {
  188. typedef PHOENIX_STD::ostream& result_type;
  189. static result_type eval(PHOENIX_STD::ostream& out, T1 const& rhs)
  190. { return out << rhs; }
  191. };
  192. //////////////////////////////////
  193. template <typename BaseT>
  194. inline typename impl::make_binary3
  195. <shift_l_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>::type
  196. operator<<(PHOENIX_STD::PHOENIX_SSTREAM& _0, actor<BaseT> const& _1)
  197. {
  198. return impl::make_binary3
  199. <shift_l_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>
  200. ::construct(var(_0), _1);
  201. }
  202. ///////////////////////////////////////////////////////////////////////////////
  203. //
  204. // I/O manipulator specializations
  205. //
  206. ///////////////////////////////////////////////////////////////////////////////
  207. #if (!defined(__GNUC__) || (__GNUC__ > 2))
  208. // && !(defined(__ICL) && defined(_STLPORT_VERSION))
  209. typedef PHOENIX_STD::ios_base& (*iomanip_t)(PHOENIX_STD::ios_base&);
  210. typedef PHOENIX_STD::istream& (*imanip_t)(PHOENIX_STD::istream&);
  211. typedef PHOENIX_STD::ostream& (*omanip_t)(PHOENIX_STD::ostream&);
  212. #if defined(__BORLANDC__)
  213. ///////////////////////////////////////////////////////////////////////////////
  214. //
  215. // Borland does not like i/o manipulators functions such as endl to
  216. // be the rhs of a lazy << operator (Borland incorrectly reports
  217. // ambiguity). To get around the problem, we provide function
  218. // pointer versions of the same name with a single trailing
  219. // underscore.
  220. //
  221. // You can use the same trick for other i/o manipulators.
  222. // Alternatively, you can prefix the manipulator with a '&'
  223. // operator. Example:
  224. //
  225. // cout << arg1 << &endl
  226. //
  227. ///////////////////////////////////////////////////////////////////////////////
  228. imanip_t ws_ = &PHOENIX_STD::ws;
  229. iomanip_t dec_ = &PHOENIX_STD::dec;
  230. iomanip_t hex_ = &PHOENIX_STD::hex;
  231. iomanip_t oct_ = &PHOENIX_STD::oct;
  232. omanip_t endl_ = &PHOENIX_STD::endl;
  233. omanip_t ends_ = &PHOENIX_STD::ends;
  234. omanip_t flush_ = &PHOENIX_STD::flush;
  235. #else // __BORLANDC__
  236. ///////////////////////////////////////////////////////////////////////////////
  237. //
  238. // The following are overloads for I/O manipulators.
  239. //
  240. ///////////////////////////////////////////////////////////////////////////////
  241. template <typename BaseT>
  242. inline typename impl::make_binary1<shift_l_op, BaseT, imanip_t>::type
  243. operator>>(actor<BaseT> const& _0, imanip_t _1)
  244. {
  245. return impl::make_binary1<shift_l_op, BaseT, imanip_t>::construct(_0, _1);
  246. }
  247. //////////////////////////////////
  248. template <typename BaseT>
  249. inline typename impl::make_binary1<shift_l_op, BaseT, iomanip_t>::type
  250. operator>>(actor<BaseT> const& _0, iomanip_t _1)
  251. {
  252. return impl::make_binary1<shift_l_op, BaseT, iomanip_t>::construct(_0, _1);
  253. }
  254. //////////////////////////////////
  255. template <typename BaseT>
  256. inline typename impl::make_binary1<shift_l_op, BaseT, omanip_t>::type
  257. operator<<(actor<BaseT> const& _0, omanip_t _1)
  258. {
  259. return impl::make_binary1<shift_l_op, BaseT, omanip_t>::construct(_0, _1);
  260. }
  261. //////////////////////////////////
  262. template <typename BaseT>
  263. inline typename impl::make_binary1<shift_l_op, BaseT, iomanip_t>::type
  264. operator<<(actor<BaseT> const& _0, iomanip_t _1)
  265. {
  266. return impl::make_binary1<shift_l_op, BaseT, iomanip_t>::construct(_0, _1);
  267. }
  268. #endif // __BORLANDC__
  269. #endif // !defined(__GNUC__) || (__GNUC__ > 2)
  270. ///////////////////////////////////////////////////////////////////////////////
  271. //
  272. // specializations for stl iterators and containers
  273. //
  274. ///////////////////////////////////////////////////////////////////////////////
  275. template <typename T>
  276. struct unary_operator<dereference_op, T>
  277. {
  278. typedef typename T::reference result_type;
  279. static result_type eval(T const& iter)
  280. { return *iter; }
  281. };
  282. //////////////////////////////////
  283. template <typename T0, typename T1>
  284. struct binary_operator<index_op, T0, T1>
  285. {
  286. typedef typename T0::reference result_type;
  287. static result_type eval(T0& container, T1 const& index)
  288. { return container[index]; }
  289. };
  290. //////////////////////////////////
  291. template <typename T0, typename T1>
  292. struct binary_operator<index_op, T0 const, T1>
  293. {
  294. typedef typename T0::const_reference result_type;
  295. static result_type eval(T0 const& container, T1 const& index)
  296. { return container[index]; }
  297. };
  298. ///////////////////////////////////////////////////////////////////////////////
  299. } // namespace phoenix
  300. #undef PHOENIX_SSTREAM
  301. #undef PHOENIX_STD
  302. #endif