Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60152 - in trunk/boost/spirit/home/support: . iterators iterators/detail
From: hartmut.kaiser_at_[hidden]
Date: 2010-03-04 13:56:04


Author: hkaiser
Date: 2010-03-04 13:56:03 EST (Thu, 04 Mar 2010)
New Revision: 60152
URL: http://svn.boost.org/trac/boost/changeset/60152

Log:
Added buffering_input_iterator to multi_pass suite
Added:
   trunk/boost/spirit/home/support/iterators/detail/buffering_input_iterator_policy.hpp (contents, props changed)
Text files modified:
   trunk/boost/spirit/home/support/iterators/multi_pass_fwd.hpp | 5 +++--
   trunk/boost/spirit/home/support/multi_pass.hpp | 1 +
   2 files changed, 4 insertions(+), 2 deletions(-)

Added: trunk/boost/spirit/home/support/iterators/detail/buffering_input_iterator_policy.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/support/iterators/detail/buffering_input_iterator_policy.hpp 2010-03-04 13:56:03 EST (Thu, 04 Mar 2010)
@@ -0,0 +1,117 @@
+// Copyright (c) 2001 Daniel C. Nuffer
+// Copyright (c) 2001-2010 Hartmut Kaiser
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#if !defined(BOOST_SPIRIT_BUFFERING_ITERATOR_INPUT_ITERATOR_POLICY_MAR_04_2010_1224AM)
+#define BOOST_SPIRIT_BUFFERING_ITERATOR_INPUT_ITERATOR_POLICY_MAR_04_2010_1224AM
+
+#include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
+#include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
+#include <boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp>
+#include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
+#include <boost/assert.hpp>
+
+namespace boost { namespace spirit { namespace iterator_policies
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // class input_iterator
+ //
+ // Implementation of the InputPolicy used by multi_pass, this is different
+ // from the input_iterator policy only as it is buffering the last input
+ // character to allow returning it by reference. This is needed for
+ // wrapping iterators not buffering the last item (such as the
+ // std::istreambuf_iterator). Unfortunately there is no way to
+ // automatically figure this out at compile time.
+ //
+ // The buffering_input_iterator encapsulates an input iterator of type T
+ ///////////////////////////////////////////////////////////////////////////
+ struct buffering_input_iterator
+ {
+ ///////////////////////////////////////////////////////////////////////
+ template <typename T>
+ class unique // : public detail::default_input_policy
+ {
+ private:
+ typedef
+ typename boost::detail::iterator_traits<T>::value_type
+ result_type;
+
+ public:
+ typedef
+ typename boost::detail::iterator_traits<T>::difference_type
+ difference_type;
+ typedef
+ typename boost::detail::iterator_traits<T>::difference_type
+ distance_type;
+ typedef
+ typename boost::detail::iterator_traits<T>::pointer
+ pointer;
+ typedef
+ typename boost::detail::iterator_traits<T>::reference
+ reference;
+ typedef result_type value_type;
+
+ protected:
+ unique() {}
+ explicit unique(T x) {}
+
+ void swap(unique&) {}
+
+ public:
+ template <typename MultiPass>
+ static void destroy(MultiPass&) {}
+
+ template <typename ValueType, typename MultiPass>
+ static ValueType& get_input(MultiPass& mp)
+ {
+ value_type& curtok = mp.shared()->curtok;
+ if (!input_is_valid(mp, curtok))
+ curtok = *mp.shared()->input_++;
+ return curtok;
+ }
+
+ template <typename MultiPass>
+ static void advance_input(MultiPass& mp)
+ {
+ BOOST_ASSERT(0 != mp.shared());
+ mp.shared()->curtok = *mp.shared()->input_++;
+ }
+
+ // test, whether we reached the end of the underlying stream
+ template <typename MultiPass>
+ static bool input_at_eof(MultiPass const& mp)
+ {
+ static T const end_iter;
+ return mp.shared()->input_ == end_iter;
+ }
+
+ template <typename MultiPass>
+ static bool input_is_valid(MultiPass const& mp, value_type const& t)
+ {
+ using namespace input_iterator_is_valid_test_;
+ return token_is_valid(t);
+ }
+
+ // no unique data elements
+ };
+
+ ///////////////////////////////////////////////////////////////////////
+ template <typename T>
+ struct shared
+ {
+ typedef
+ typename boost::detail::iterator_traits<T>::value_type
+ result_type;
+
+ explicit shared(T const& input) : input_(input), curtok(0) {}
+
+ T input_;
+ result_type curtok;
+ };
+ };
+
+}}}
+
+#endif

Modified: trunk/boost/spirit/home/support/iterators/multi_pass_fwd.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/multi_pass_fwd.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/multi_pass_fwd.hpp 2010-03-04 13:56:03 EST (Thu, 04 Mar 2010)
@@ -19,6 +19,7 @@
     {
         // input policies
         struct input_iterator;
+ struct buffering_input_iterator;
         struct istream;
         struct lex_input;
         struct functor_input;
@@ -41,13 +42,13 @@
 #if defined(BOOST_SPIRIT_DEBUG)
         template<typename Ownership = ref_counted
           , typename Checking = buf_id_check
- , typename Input = input_iterator
+ , typename Input = buffering_input_iterator
           , typename Storage = split_std_deque>
         struct default_policy;
 #else
         template<typename Ownership = ref_counted
           , typename Checking = no_check
- , typename Input = input_iterator
+ , typename Input = buffering_input_iterator
           , typename Storage = split_std_deque>
         struct default_policy;
 #endif

Modified: trunk/boost/spirit/home/support/multi_pass.hpp
==============================================================================
--- trunk/boost/spirit/home/support/multi_pass.hpp (original)
+++ trunk/boost/spirit/home/support/multi_pass.hpp 2010-03-04 13:56:03 EST (Thu, 04 Mar 2010)
@@ -17,6 +17,7 @@
 
 // Input policies
 #include <boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp>
+#include <boost/spirit/home/support/iterators/detail/buffering_input_iterator_policy.hpp>
 #include <boost/spirit/home/support/iterators/detail/istream_policy.hpp>
 #include <boost/spirit/home/support/iterators/detail/lex_input_policy.hpp>
 #include <boost/spirit/home/support/iterators/detail/split_functor_input_policy.hpp>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk