1 /*=============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
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_STREAM_MAY_05_2007_1228PM)
8 #define BOOST_SPIRIT_STREAM_MAY_05_2007_1228PM
14 #include <boost/spirit/home/qi/detail/string_parse.hpp>
15 #include <boost/spirit/home/qi/stream/detail/match_manip.hpp>
16 #include <boost/spirit/home/qi/stream/detail/iterator_source.hpp>
17 #include <boost/spirit/home/support/detail/hold_any.hpp>
22 ///////////////////////////////////////////////////////////////////////////////
23 namespace boost { namespace spirit
25 ///////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////
29 struct use_terminal<qi::domain, tag::stream> // enables stream
33 struct use_terminal<qi::domain, tag::wstream> // enables wstream
37 ///////////////////////////////////////////////////////////////////////////////
38 namespace boost { namespace spirit { namespace qi
40 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
42 using spirit::wstream;
44 using spirit::stream_type;
45 using spirit::wstream_type;
47 template <typename Char = char, typename T = spirit::basic_hold_any<char> >
49 : primitive_parser<stream_parser<Char, T> >
51 template <typename Context, typename Iterator>
57 template <typename Iterator, typename Context
58 , typename Skipper, typename Attribute>
59 bool parse(Iterator& first, Iterator const& last
60 , Context& /*context*/, Skipper const& skipper
61 , Attribute& attr_) const
63 typedef qi::detail::iterator_source<Iterator> source_device;
64 typedef boost::iostreams::stream<source_device> instream;
66 qi::skip_over(first, last, skipper);
68 instream in(first, last); // copies 'first'
69 in >> attr_; // use existing operator>>()
71 // advance the iterator if everything is ok
74 std::streamsize pos = in.tellg();
75 std::advance(first, pos);
85 template <typename Context>
86 info what(Context& /*context*/) const
88 return info("stream");
92 template <typename T, typename Char = char>
94 : proto::terminal<stream_parser<Char, T> >::type
98 ///////////////////////////////////////////////////////////////////////////
99 // Parser generators: make_xxx function (objects)
100 ///////////////////////////////////////////////////////////////////////////
101 template <typename Char>
104 typedef stream_parser<Char> result_type;
105 result_type operator()(unused_type, unused_type) const
107 return result_type();
111 template <typename Modifiers>
112 struct make_primitive<tag::stream, Modifiers> : make_stream<char> {};
114 template <typename Modifiers>
115 struct make_primitive<tag::wstream, Modifiers> : make_stream<wchar_t> {};