Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54217 - in trunk/boost/spirit/home/support/iterators: . detail
From: hartmut.kaiser_at_[hidden]
Date: 2009-06-22 15:42:17


Author: hkaiser
Date: 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
New Revision: 54217
URL: http://svn.boost.org/trac/boost/changeset/54217

Log:
Spirit: fixed base from member initialization problem in multi_pass iterator
Text files modified:
   trunk/boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp | 4 ++--
   trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp | 12 ++++++------
   trunk/boost/spirit/home/support/iterators/detail/functor_input_policy.hpp | 2 +-
   trunk/boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp | 2 +-
   trunk/boost/spirit/home/support/iterators/detail/lex_input_policy.hpp | 2 +-
   trunk/boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp | 8 ++++----
   trunk/boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp | 10 +++++-----
   trunk/boost/spirit/home/support/iterators/multi_pass.hpp | 27 ++++++++++++++++-----------
   8 files changed, 36 insertions(+), 31 deletions(-)

Modified: trunk/boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -58,7 +58,7 @@
             template <typename MultiPass>
             static void check(MultiPass const& mp)
             {
- if (mp.buf_id != mp.shared->shared_buf_id)
+ if (mp.buf_id != mp.shared()->shared_buf_id)
                     boost::throw_exception(illegal_backtracking());
             }
 
@@ -66,7 +66,7 @@
             template <typename MultiPass>
             static void clear_queue(MultiPass& mp)
             {
- ++mp.shared->shared_buf_id;
+ ++mp.shared()->shared_buf_id;
                 ++mp.buf_id;
             }
 

Modified: trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -55,7 +55,7 @@
             static typename MultiPass::reference
             dereference(MultiPass const& mp)
             {
- if (mp.queuePosition == mp.shared->queuedElements.end())
+ if (mp.queuePosition == mp.shared()->queuedElements.end())
                 {
                     return MultiPass::get_input(mp);
                 }
@@ -71,13 +71,13 @@
             template <typename MultiPass>
             static void increment(MultiPass& mp)
             {
- if (mp.queuePosition == mp.shared->queuedElements.end())
+ if (mp.queuePosition == mp.shared()->queuedElements.end())
                 {
                     // don't let the queue get larger than N
- if (mp.shared->queuedElements.size() >= N)
- mp.shared->queuedElements.pop_front();
+ if (mp.shared()->queuedElements.size() >= N)
+ mp.shared()->queuedElements.pop_front();
 
- mp.shared->queuedElements.push_back(MultiPass::get_input(mp));
+ mp.shared()->queuedElements.push_back(MultiPass::get_input(mp));
                     MultiPass::advance_input(mp);
                 }
                 ++mp.queuePosition;
@@ -89,7 +89,7 @@
             template <typename MultiPass>
             static bool is_eof(MultiPass const& mp)
             {
- return mp.queuePosition == mp.shared->queuedElements.end() &&
+ return mp.queuePosition == mp.shared()->queuedElements.end() &&
                        MultiPass::input_at_eof(mp);
             }
 

Modified: trunk/boost/spirit/home/support/iterators/detail/functor_input_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/functor_input_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/functor_input_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -64,7 +64,7 @@
                 // if mp.shared is NULL then this instance of the multi_pass
                 // represents a end iterator, so no advance functionality is
                 // needed
- if (0 != mp.shared)
+ if (0 != mp.shared())
                     t = mp.ftor();
             }
 

Modified: trunk/boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -71,7 +71,7 @@
                 // if mp.shared is NULL then this instance of the multi_pass
                 // represents a end iterator, so no advance functionality is
                 // needed
- if (0 != mp.shared)
+ if (0 != mp.shared())
                     t = *++mp.input;
             }
 

Modified: trunk/boost/spirit/home/support/iterators/detail/lex_input_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/lex_input_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/lex_input_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -42,7 +42,7 @@
                 // if mp.shared is NULL then this instance of the multi_pass
                 // represents a end iterator, so no advance functionality is
                 // needed
- if (0 != mp.shared)
+ if (0 != mp.shared())
                 {
                     extern int yylex();
                     t = yylex();

Modified: trunk/boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -35,8 +35,8 @@
             template <typename MultiPass>
             static void clone(MultiPass& mp)
             {
- if (0 != mp.shared)
- ++mp.shared->count;
+ if (0 != mp.shared())
+ ++mp.shared()->count;
             }
 
             // called when a copy is deleted. Decrement the ref-count. Return
@@ -44,7 +44,7 @@
             template <typename MultiPass>
             static bool release(MultiPass& mp)
             {
- return 0 != mp.shared && 0 == --mp.shared->count;
+ return 0 != mp.shared() && 0 == --mp.shared()->count;
             }
 
             // returns true if there is only one iterator in existence.
@@ -53,7 +53,7 @@
             template <typename MultiPass>
             static bool is_unique(MultiPass const& mp)
             {
- return 0 == mp.shared || 1 == mp.shared->count;
+ return 0 == mp.shared() || 1 == mp.shared()->count;
             }
 
             template <typename MultiPass>

Modified: trunk/boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -52,7 +52,7 @@
             static typename MultiPass::reference
             dereference(MultiPass const& mp)
             {
- queue_type& queue = mp.shared->queued_elements;
+ queue_type& queue = mp.shared()->queued_elements;
                 typename queue_type::size_type size = queue.size();
 
                 BOOST_ASSERT(mp.queued_position > 0 && mp.queued_position <= size);
@@ -69,7 +69,7 @@
             template <typename MultiPass>
             static void increment(MultiPass& mp)
             {
- queue_type& queue = mp.shared->queued_elements;
+ queue_type& queue = mp.shared()->queued_elements;
                 typename queue_type::size_type size = queue.size();
 
                 BOOST_ASSERT(mp.queued_position > 0 && mp.queued_position <= size);
@@ -113,8 +113,8 @@
             template <typename MultiPass>
             static void clear_queue(MultiPass& mp)
             {
- mp.shared->queued_elements.clear();
- mp.shared->queued_elements.push_back(Value(0));
+ mp.shared()->queued_elements.clear();
+ mp.shared()->queued_elements.push_back(Value(0));
                 mp.queued_position = 1;
             }
 
@@ -122,7 +122,7 @@
             template <typename MultiPass>
             static bool is_eof(MultiPass const& mp)
             {
- queue_type& queue = mp.shared->queued_elements;
+ queue_type& queue = mp.shared()->queued_elements;
                 return 0 != mp.queued_position &&
                     mp.queued_position == queue.size() &&
                     MultiPass::input_at_eof(mp, queue[mp.queued_position-1]);

Modified: trunk/boost/spirit/home/support/iterators/multi_pass.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/multi_pass.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/multi_pass.hpp 2009-06-22 15:42:16 EDT (Mon, 22 Jun 2009)
@@ -14,6 +14,7 @@
 #include <boost/spirit/home/support/iterators/detail/combine_policies.hpp>
 #include <boost/limits.hpp>
 #include <boost/detail/workaround.hpp>
+#include <boost/utility/base_from_member.hpp>
 
 namespace boost { namespace spirit
 {
@@ -22,7 +23,9 @@
     ///////////////////////////////////////////////////////////////////////////
     template<typename T, typename Policies>
     class multi_pass
- : public Policies::BOOST_NESTED_TEMPLATE unique<T>
+ : private boost::base_from_member<
+ typename Policies::BOOST_NESTED_TEMPLATE shared<T>*>
+ , public Policies::BOOST_NESTED_TEMPLATE unique<T>
 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
       , typename iterator_base_creator<T, typename Policies::input_policy>::type
 #endif
@@ -34,6 +37,8 @@
         typedef typename Policies::BOOST_NESTED_TEMPLATE shared<T>
             shared_data_type;
 
+ typedef boost::base_from_member<shared_data_type*> member_base;
+
         // define the types the standard embedded iterator typedefs are taken
         // from
 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
@@ -51,7 +56,7 @@
         typedef typename iterator_type::reference reference;
         typedef typename iterator_type::pointer pointer;
 
- multi_pass() : shared(0) {}
+ multi_pass() : member_base((shared_data_type*)0) {}
 
         // Newer versions of gcc (and perhaps other compilers) are known to
         // generate warnings about the base class and the 'shared' member
@@ -60,10 +65,10 @@
         // rely on the fact that their shared part is initialized before their
         // unique part. Please ignore the warnings, these are harmless.
         explicit multi_pass(T input)
- : shared(new shared_data_type(input)), policies_base_type(input) {}
+ : member_base(new shared_data_type(input)), policies_base_type(input) {}
 
         multi_pass(multi_pass const& x)
- : shared(x.shared), policies_base_type(x)
+ : member_base(x.member), policies_base_type(x)
         {
             policies_base_type::clone(*this);
         }
@@ -75,14 +80,14 @@
         // checking code that isn't required by the standard.
         // The workaround is to provide an additional constructor that
         // ignores its int argument and behaves like the default constructor.
- multi_pass(int) : shared(0) {}
+ multi_pass(int) : member(0) {}
 #endif // BOOST_WORKAROUND(__GLIBCPP__, == 20020514)
 
         ~multi_pass()
         {
             if (policies_base_type::release(*this)) {
                 policies_base_type::destroy(*this);
- delete shared;
+ delete this->member;
             }
         }
 
@@ -97,7 +102,7 @@
 
         void swap(multi_pass& x)
         {
- spirit::detail::swap(shared, x.shared);
+ spirit::detail::swap(this->member, x.member);
             this->policies_base_type::swap(x);
         }
 
@@ -143,14 +148,14 @@
             return policies_base_type::less_than(*this, y);
         }
 
+ // allow access to base member
+ shared_data_type* shared() const { return this->member; }
+
     private: // helper functions
         bool is_eof() const
         {
- return (0 == shared) || policies_base_type::is_eof(*this);
+ return (0 == this->member) || policies_base_type::is_eof(*this);
         }
-
- public:
- shared_data_type *shared;
     };
 
 


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