in.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*=============================================================================
  2. Copyright (c) 1999-2003 Jaakko Jarvi
  3. Copyright (c) 1999-2003 Jeremiah Willcock
  4. Copyright (c) 2001-2011 Joel de Guzman
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #if !defined(FUSION_IN_05052005_0121)
  9. #define FUSION_IN_05052005_0121
  10. #include <boost/fusion/support/config.hpp>
  11. #include <istream>
  12. #include <boost/fusion/sequence/io/detail/manip.hpp>
  13. #include <boost/mpl/bool.hpp>
  14. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  15. #include <boost/fusion/sequence/intrinsic/end.hpp>
  16. #include <boost/fusion/iterator/deref.hpp>
  17. #include <boost/fusion/iterator/next.hpp>
  18. #include <boost/fusion/iterator/equal_to.hpp>
  19. namespace boost { namespace fusion { namespace detail
  20. {
  21. template <typename Tag>
  22. struct delimiter_in
  23. {
  24. // read a delimiter
  25. template <typename IS>
  26. static void
  27. read(IS& is, char const* delim, mpl::false_ = mpl::false_())
  28. {
  29. detail::string_ios_manip<Tag, IS> manip(is);
  30. manip.read(delim);
  31. }
  32. template <typename IS>
  33. static void
  34. read(IS&, char const*, mpl::true_)
  35. {
  36. }
  37. };
  38. struct read_sequence_loop
  39. {
  40. template <typename IS, typename First, typename Last>
  41. static void
  42. call(IS&, First const&, Last const&, mpl::true_)
  43. {
  44. }
  45. template <typename IS, typename First, typename Last>
  46. static void
  47. call(IS& is, First const& first, Last const& last, mpl::false_)
  48. {
  49. result_of::equal_to<
  50. typename result_of::next<First>::type
  51. , Last
  52. >
  53. is_last;
  54. is >> *first;
  55. delimiter_in<tuple_delimiter_tag>::read(is, " ", is_last);
  56. call(is, fusion::next(first), last, is_last);
  57. }
  58. template <typename IS, typename First, typename Last>
  59. static void
  60. call(IS& is, First const& first, Last const& last)
  61. {
  62. result_of::equal_to<First, Last> eq;
  63. call(is, first, last, eq);
  64. }
  65. };
  66. template <typename IS, typename Sequence>
  67. inline void
  68. read_sequence(IS& is, Sequence& seq)
  69. {
  70. delimiter_in<tuple_open_tag>::read(is, "(");
  71. read_sequence_loop::call(is, fusion::begin(seq), fusion::end(seq));
  72. delimiter_in<tuple_close_tag>::read(is, ")");
  73. }
  74. }}}
  75. #endif