File indexing completed on 2025-01-19 09:47:47
0001
0002
0003
0004
0005
0006
0007 #if !defined(BOOST_SPIRIT_STREAM_MAY_05_2007_1228PM)
0008 #define BOOST_SPIRIT_STREAM_MAY_05_2007_1228PM
0009
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013
0014 #include <boost/spirit/home/qi/detail/string_parse.hpp>
0015 #include <boost/spirit/home/qi/stream/detail/match_manip.hpp>
0016 #include <boost/spirit/home/support/detail/hold_any.hpp>
0017 #include <boost/proto/traits.hpp>
0018 #include <istream>
0019
0020
0021 namespace boost { namespace spirit
0022 {
0023
0024
0025
0026 template <>
0027 struct use_terminal<qi::domain, tag::stream>
0028 : mpl::true_ {};
0029
0030 template <>
0031 struct use_terminal<qi::domain, tag::wstream>
0032 : mpl::true_ {};
0033 }}
0034
0035
0036 namespace boost { namespace spirit { namespace qi
0037 {
0038 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0039 using spirit::stream;
0040 using spirit::wstream;
0041 #endif
0042 using spirit::stream_type;
0043 using spirit::wstream_type;
0044
0045 namespace detail
0046 {
0047 #ifdef _MSC_VER
0048 # pragma warning(push)
0049 # pragma warning(disable: 4512)
0050 #endif
0051 template <typename Iterator>
0052 struct psbuf
0053 : std::basic_streambuf<typename std::iterator_traits<Iterator>::value_type>
0054 {
0055 psbuf(Iterator first_, Iterator const& last_)
0056 : first(first_), last(last_) {}
0057
0058 protected:
0059 typename psbuf::int_type underflow() BOOST_OVERRIDE
0060 {
0061 return first == last ? psbuf::traits_type::eof()
0062 : psbuf::traits_type::to_int_type(*first);
0063 }
0064
0065 typename psbuf::int_type uflow() BOOST_OVERRIDE
0066 {
0067 return first == last ? psbuf::traits_type::eof()
0068 : psbuf::traits_type::to_int_type(*first++);
0069 }
0070
0071 public:
0072 Iterator first;
0073 Iterator const& last;
0074 };
0075 #ifdef _MSC_VER
0076 # pragma warning(pop)
0077 #endif
0078 }
0079
0080 template <typename Char = char, typename T = spirit::basic_hold_any<char> >
0081 struct stream_parser
0082 : primitive_parser<stream_parser<Char, T> >
0083 {
0084 template <typename Context, typename Iterator>
0085 struct attribute
0086 {
0087 typedef T type;
0088 };
0089
0090 template <typename Iterator, typename Context
0091 , typename Skipper, typename Attribute>
0092 bool parse(Iterator& first, Iterator const& last
0093 , Context& , Skipper const& skipper
0094 , Attribute& attr_) const
0095 {
0096 qi::skip_over(first, last, skipper);
0097
0098 detail::psbuf<Iterator> pseudobuf(first, last);
0099 std::basic_istream<Char> in(&pseudobuf);
0100 in >> attr_;
0101
0102
0103 if (in) {
0104 first = pseudobuf.first;
0105 return true;
0106 }
0107
0108 return false;
0109 }
0110
0111 template <typename Context>
0112 info what(Context& ) const
0113 {
0114 return info("stream");
0115 }
0116 };
0117
0118 template <typename T, typename Char = char>
0119 struct typed_stream
0120 : proto::terminal<stream_parser<Char, T> >::type
0121 {
0122 };
0123
0124
0125
0126
0127 template <typename Char>
0128 struct make_stream
0129 {
0130 typedef stream_parser<Char> result_type;
0131 result_type operator()(unused_type, unused_type) const
0132 {
0133 return result_type();
0134 }
0135 };
0136
0137 template <typename Modifiers>
0138 struct make_primitive<tag::stream, Modifiers> : make_stream<char> {};
0139
0140 template <typename Modifiers>
0141 struct make_primitive<tag::wstream, Modifiers> : make_stream<wchar_t> {};
0142 }}}
0143
0144 #endif