File indexing completed on 2024-11-15 09:31:57
0001
0002
0003
0004
0005
0006
0007 #if !defined(BOOST_SPIRIT_ISTREAM_POLICY_JAN_04_2010_0130PM)
0008 #define BOOST_SPIRIT_ISTREAM_POLICY_JAN_04_2010_0130PM
0009
0010 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
0011 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
0012
0013 namespace boost { namespace spirit { namespace iterator_policies
0014 {
0015
0016
0017
0018
0019
0020
0021 struct istream
0022 {
0023
0024 template <typename T>
0025 class unique
0026 {
0027 private:
0028 typedef typename T::char_type result_type;
0029
0030 public:
0031 typedef typename T::off_type difference_type;
0032 typedef typename T::off_type distance_type;
0033 typedef result_type const* pointer;
0034 typedef result_type const& reference;
0035 typedef result_type value_type;
0036
0037 protected:
0038 unique() {}
0039 explicit unique(T&) {}
0040
0041 void swap(unique&) {}
0042
0043 public:
0044 template <typename MultiPass>
0045 static void destroy(MultiPass&) {}
0046
0047 template <typename MultiPass>
0048 static typename MultiPass::reference get_input(MultiPass& mp)
0049 {
0050 if (!mp.shared()->initialized_)
0051 mp.shared()->read_one();
0052 return mp.shared()->curtok_;
0053 }
0054
0055 template <typename MultiPass>
0056 static void advance_input(MultiPass& mp)
0057 {
0058
0059
0060
0061
0062
0063 mp.shared()->peek_one();
0064 }
0065
0066
0067 template <typename MultiPass>
0068 static bool input_at_eof(MultiPass const& mp)
0069 {
0070 return mp.shared()->eof_reached_;
0071 }
0072
0073 template <typename MultiPass>
0074 static bool input_is_valid(MultiPass const& mp, value_type const&)
0075 {
0076 return mp.shared()->initialized_;
0077 }
0078
0079
0080 };
0081
0082
0083 template <typename T>
0084 struct shared
0085 {
0086 private:
0087 typedef typename T::char_type result_type;
0088
0089 public:
0090 explicit shared(T& input)
0091 : input_(input), curtok_(-1)
0092 , initialized_(false), eof_reached_(false)
0093 {
0094 peek_one();
0095 }
0096
0097 void read_one()
0098 {
0099 if (!(input_ >> curtok_)) {
0100 initialized_ = false;
0101 eof_reached_ = true;
0102 }
0103 else {
0104 initialized_ = true;
0105 }
0106 }
0107
0108 void peek_one()
0109 {
0110 input_.peek();
0111 initialized_ = false;
0112 eof_reached_ = input_.eof();
0113 }
0114
0115 T& input_;
0116 result_type curtok_;
0117 bool initialized_;
0118 bool eof_reached_;
0119 };
0120 };
0121
0122 }}}
0123
0124 #endif