]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/qi/stream/stream.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / spirit / home / qi / stream / stream.hpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
3
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
9
10 #if defined(_MSC_VER)
11 #pragma once
12 #endif
13
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>
18 #include <boost/proto/traits.hpp>
19 #include <iosfwd>
20 #include <sstream>
21
22 ///////////////////////////////////////////////////////////////////////////////
23 namespace boost { namespace spirit
24 {
25 ///////////////////////////////////////////////////////////////////////////
26 // Enablers
27 ///////////////////////////////////////////////////////////////////////////
28 template <>
29 struct use_terminal<qi::domain, tag::stream> // enables stream
30 : mpl::true_ {};
31
32 template <>
33 struct use_terminal<qi::domain, tag::wstream> // enables wstream
34 : mpl::true_ {};
35 }}
36
37 ///////////////////////////////////////////////////////////////////////////////
38 namespace boost { namespace spirit { namespace qi
39 {
40 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
41 using spirit::stream;
42 using spirit::wstream;
43 #endif
44 using spirit::stream_type;
45 using spirit::wstream_type;
46
47 template <typename Char = char, typename T = spirit::basic_hold_any<char> >
48 struct stream_parser
49 : primitive_parser<stream_parser<Char, T> >
50 {
51 template <typename Context, typename Iterator>
52 struct attribute
53 {
54 typedef T type;
55 };
56
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
62 {
63 typedef qi::detail::iterator_source<Iterator> source_device;
64 typedef boost::iostreams::stream<source_device> instream;
65
66 qi::skip_over(first, last, skipper);
67
68 instream in(first, last); // copies 'first'
69 in >> attr_; // use existing operator>>()
70
71 // advance the iterator if everything is ok
72 if (in) {
73 if (!in.eof()) {
74 typedef typename
75 boost::iterator_difference<Iterator>::type diff_type;
76
77 diff_type pos = static_cast<diff_type>(in.tellg());
78 std::advance(first, pos);
79 } else {
80 first = last;
81 }
82 return true;
83 }
84
85 return false;
86 }
87
88 template <typename Context>
89 info what(Context& /*context*/) const
90 {
91 return info("stream");
92 }
93 };
94
95 template <typename T, typename Char = char>
96 struct typed_stream
97 : proto::terminal<stream_parser<Char, T> >::type
98 {
99 };
100
101 ///////////////////////////////////////////////////////////////////////////
102 // Parser generators: make_xxx function (objects)
103 ///////////////////////////////////////////////////////////////////////////
104 template <typename Char>
105 struct make_stream
106 {
107 typedef stream_parser<Char> result_type;
108 result_type operator()(unused_type, unused_type) const
109 {
110 return result_type();
111 }
112 };
113
114 template <typename Modifiers>
115 struct make_primitive<tag::stream, Modifiers> : make_stream<char> {};
116
117 template <typename Modifiers>
118 struct make_primitive<tag::wstream, Modifiers> : make_stream<wchar_t> {};
119 }}}
120
121 #endif