in.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <boost/fusion/sequence/io/detail/manip.hpp>
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  14. #include <boost/fusion/sequence/intrinsic/end.hpp>
  15. #include <boost/fusion/iterator/deref.hpp>
  16. #include <boost/fusion/iterator/next.hpp>
  17. #include <boost/fusion/iterator/equal_to.hpp>
  18. namespace boost { namespace fusion { namespace detail
  19. {
  20. template <typename Tag>
  21. struct delimiter_in
  22. {
  23. // read a delimiter
  24. template <typename IS>
  25. static void
  26. read(IS& is, char const* delim, mpl::false_ = mpl::false_())
  27. {
  28. detail::string_ios_manip<Tag, IS> manip(is);
  29. manip.read(delim);
  30. }
  31. template <typename IS>
  32. static void
  33. read(IS&, char const*, mpl::true_)
  34. {
  35. }
  36. };
  37. struct read_sequence_loop
  38. {
  39. template <typename IS, typename First, typename Last>
  40. static void
  41. call(IS&, First const&, Last const&, mpl::true_)
  42. {
  43. }
  44. template <typename IS, typename First, typename Last>
  45. static void
  46. call(IS& is, First const& first, Last const& last, mpl::false_)
  47. {
  48. result_of::equal_to<
  49. typename result_of::next<First>::type
  50. , Last
  51. >
  52. is_last;
  53. is >> *first;
  54. delimiter_in<tuple_delimiter_tag>::read(is, " ", is_last);
  55. call(is, fusion::next(first), last, is_last);
  56. }
  57. template <typename IS, typename First, typename Last>
  58. static void
  59. call(IS& is, First const& first, Last const& last)
  60. {
  61. result_of::equal_to<First, Last> eq;
  62. call(is, first, last, eq);
  63. }
  64. };
  65. template <typename IS, typename Sequence>
  66. inline void
  67. read_sequence(IS& is, Sequence& seq)
  68. {
  69. delimiter_in<tuple_open_tag>::read(is, "(");
  70. read_sequence_loop::call(is, fusion::begin(seq), fusion::end(seq));
  71. delimiter_in<tuple_close_tag>::read(is, ")");
  72. }
  73. }}}
  74. #endif