annotate DEPENDENCIES/generic/include/boost/spirit/home/qi/stream/stream.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /*=============================================================================
Chris@16 2 Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 3
Chris@16 4 Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 ==============================================================================*/
Chris@16 7 #if !defined(BOOST_SPIRIT_STREAM_MAY_05_2007_1228PM)
Chris@16 8 #define BOOST_SPIRIT_STREAM_MAY_05_2007_1228PM
Chris@16 9
Chris@16 10 #if defined(_MSC_VER)
Chris@16 11 #pragma once
Chris@16 12 #endif
Chris@16 13
Chris@16 14 #include <boost/spirit/home/qi/detail/string_parse.hpp>
Chris@16 15 #include <boost/spirit/home/qi/stream/detail/match_manip.hpp>
Chris@16 16 #include <boost/spirit/home/qi/stream/detail/iterator_source.hpp>
Chris@16 17 #include <boost/spirit/home/support/detail/hold_any.hpp>
Chris@16 18
Chris@16 19 #include <iosfwd>
Chris@16 20 #include <sstream>
Chris@16 21
Chris@16 22 ///////////////////////////////////////////////////////////////////////////////
Chris@16 23 namespace boost { namespace spirit
Chris@16 24 {
Chris@16 25 ///////////////////////////////////////////////////////////////////////////
Chris@16 26 // Enablers
Chris@16 27 ///////////////////////////////////////////////////////////////////////////
Chris@16 28 template <>
Chris@16 29 struct use_terminal<qi::domain, tag::stream> // enables stream
Chris@16 30 : mpl::true_ {};
Chris@16 31
Chris@16 32 template <>
Chris@16 33 struct use_terminal<qi::domain, tag::wstream> // enables wstream
Chris@16 34 : mpl::true_ {};
Chris@16 35 }}
Chris@16 36
Chris@16 37 ///////////////////////////////////////////////////////////////////////////////
Chris@16 38 namespace boost { namespace spirit { namespace qi
Chris@16 39 {
Chris@16 40 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
Chris@16 41 using spirit::stream;
Chris@16 42 using spirit::wstream;
Chris@16 43 #endif
Chris@16 44 using spirit::stream_type;
Chris@16 45 using spirit::wstream_type;
Chris@16 46
Chris@16 47 template <typename Char = char, typename T = spirit::basic_hold_any<char> >
Chris@16 48 struct stream_parser
Chris@16 49 : primitive_parser<stream_parser<Char, T> >
Chris@16 50 {
Chris@16 51 template <typename Context, typename Iterator>
Chris@16 52 struct attribute
Chris@16 53 {
Chris@16 54 typedef T type;
Chris@16 55 };
Chris@16 56
Chris@16 57 template <typename Iterator, typename Context
Chris@16 58 , typename Skipper, typename Attribute>
Chris@16 59 bool parse(Iterator& first, Iterator const& last
Chris@16 60 , Context& /*context*/, Skipper const& skipper
Chris@16 61 , Attribute& attr_) const
Chris@16 62 {
Chris@16 63 typedef qi::detail::iterator_source<Iterator> source_device;
Chris@16 64 typedef boost::iostreams::stream<source_device> instream;
Chris@16 65
Chris@16 66 qi::skip_over(first, last, skipper);
Chris@16 67
Chris@16 68 instream in(first, last); // copies 'first'
Chris@16 69 in >> attr_; // use existing operator>>()
Chris@16 70
Chris@16 71 // advance the iterator if everything is ok
Chris@16 72 if (in) {
Chris@101 73 if (!in.eof()) {
Chris@101 74 std::streamsize pos = in.tellg();
Chris@101 75 std::advance(first, pos);
Chris@101 76 } else {
Chris@101 77 first = last;
Chris@101 78 }
Chris@16 79 return true;
Chris@16 80 }
Chris@16 81
Chris@16 82 return false;
Chris@16 83 }
Chris@16 84
Chris@16 85 template <typename Context>
Chris@16 86 info what(Context& /*context*/) const
Chris@16 87 {
Chris@16 88 return info("stream");
Chris@16 89 }
Chris@16 90 };
Chris@16 91
Chris@16 92 template <typename T, typename Char = char>
Chris@16 93 struct typed_stream
Chris@16 94 : proto::terminal<stream_parser<Char, T> >::type
Chris@16 95 {
Chris@16 96 };
Chris@16 97
Chris@16 98 ///////////////////////////////////////////////////////////////////////////
Chris@16 99 // Parser generators: make_xxx function (objects)
Chris@16 100 ///////////////////////////////////////////////////////////////////////////
Chris@16 101 template <typename Char>
Chris@16 102 struct make_stream
Chris@16 103 {
Chris@16 104 typedef stream_parser<Char> result_type;
Chris@16 105 result_type operator()(unused_type, unused_type) const
Chris@16 106 {
Chris@16 107 return result_type();
Chris@16 108 }
Chris@16 109 };
Chris@16 110
Chris@16 111 template <typename Modifiers>
Chris@16 112 struct make_primitive<tag::stream, Modifiers> : make_stream<char> {};
Chris@16 113
Chris@16 114 template <typename Modifiers>
Chris@16 115 struct make_primitive<tag::wstream, Modifiers> : make_stream<wchar_t> {};
Chris@16 116 }}}
Chris@16 117
Chris@16 118 #endif