$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r71611 - in sandbox/block_ptr: boost boost/detail libs/smart_ptr/example
From: phil_at_[hidden]
Date: 2011-04-29 17:41:46
Author: pbouchard
Date: 2011-04-29 17:41:45 EDT (Fri, 29 Apr 2011)
New Revision: 71611
URL: http://svn.boost.org/trac/boost/changeset/71611
Log:
* Added factory support and made pointee * assignments private
Text files modified: 
   sandbox/block_ptr/boost/block_ptr.hpp                   |    94 ++++++++++++++++++++++++--------------- 
   sandbox/block_ptr/boost/detail/block_base.hpp           |     4                                         
   sandbox/block_ptr/libs/smart_ptr/example/t100.h         |    10 ++--                                    
   sandbox/block_ptr/libs/smart_ptr/example/t100_test1.cpp |     6 +-                                      
   4 files changed, 67 insertions(+), 47 deletions(-)
Modified: sandbox/block_ptr/boost/block_ptr.hpp
==============================================================================
--- sandbox/block_ptr/boost/block_ptr.hpp	(original)
+++ sandbox/block_ptr/boost/block_ptr.hpp	2011-04-29 17:41:45 EDT (Fri, 29 Apr 2011)
@@ -222,6 +222,22 @@
 fast_pool_allocator<block_header> block_header::pool_;
 
 
+#define TEMPLATE_DECL(z, n, text) BOOST_PP_COMMA_IF(n) typename T ## n
+#define ARGUMENT_DECL(z, n, text) BOOST_PP_COMMA_IF(n) T ## n const & t ## n
+#define PARAMETER_DECL(z, n, text) BOOST_PP_COMMA_IF(n) t ## n
+
+#define CONSTRUCT_MAKE_BLOCK(z, n, text)																			    \
+	template <typename V, BOOST_PP_REPEAT(n, TEMPLATE_DECL, 0)>										                    \
+		block_ptr<V> text(BOOST_PP_REPEAT(n, ARGUMENT_DECL, 0))															\
+		{																												\
+			return block_ptr<V>(new block<V>(BOOST_PP_REPEAT(n, PARAMETER_DECL, 0)));									\
+		}
+
+#define BEFRIEND_MAKE_BLOCK(z, n, text)																			    	\
+	template <typename V, BOOST_PP_REPEAT(n, TEMPLATE_DECL, 0)>										                    \
+		friend block_ptr<V> text(BOOST_PP_REPEAT(n, ARGUMENT_DECL, 0));
+
+
 /**
         Deterministic memory manager of constant complexity.
         
@@ -244,24 +260,6 @@
             intrusive_stack::node pn_;				/**< Tag used for enlisting a pointer on the heap to later share the @c block_header it belongs to. */
         };
 
-    public:
-        typedef T                       value_type;
-        typedef block<value_type>     element_type;
-
-
-		/**
-			Initialization of a pointer living on the stack or proper enlistment if living on the heap.
-		*/
-		
-        block_ptr() : ps_(0)
-        {
-            if (! block_base::pool_.is_from(this))
-                ps_ = new block_header();
-            else
-                block_base::pool_.top(this)->ptrs_.push(& pn_);
-        }
-
-		
                 /**
                         Initialization of a pointer living on the stack or proper enlistment if living on the heap.
                         
@@ -286,6 +284,44 @@
 
                 
                 /**
+			Assignment & union of 2 sets if the pointee resides a different @c block_header.
+			
+			@param	p	New pointee object to manage.
+		*/
+		
+        template <typename V>
+            block_ptr & operator = (block<V> * p)
+            {
+                release(false);
+
+                init(p);
+
+                base::operator = (p);
+
+                return * this;
+            }
+
+		BOOST_PP_REPEAT_FROM_TO(1, 10, BEFRIEND_MAKE_BLOCK, make_block)
+
+    public:
+        typedef T                       value_type;
+        typedef block<value_type>     element_type;
+
+
+		/**
+			Initialization of a pointer living on the stack or proper enlistment if living on the heap.
+		*/
+		
+        block_ptr() : ps_(0)
+        {
+            if (! block_base::pool_.is_from(this))
+                ps_ = new block_header();
+            else
+                block_base::pool_.top(this)->ptrs_.push(& pn_);
+        }
+
+		
+		/**
                         Initialization of a pointer living on the stack or proper enlistment if living on the heap.
                         
                         @param	p	New pointer to manage.
@@ -323,25 +359,6 @@
                 /**
                         Assignment & union of 2 sets if the pointee resides a different @c block_header.
                         
-			@param	p	New pointee object to manage.
-		*/
-		
-        template <typename V>
-            block_ptr & operator = (block<V> * p)
-            {
-                release(false);
-
-                init(p);
-
-                base::operator = (p);
-
-                return * this;
-            }
-
-
-		/**
-			Assignment & union of 2 sets if the pointee resides a different @c block_header.
-			
                         @param	p	New pointer to manage.
                 */
                         
@@ -435,12 +452,15 @@
     };
 
 
+BOOST_PP_REPEAT_FROM_TO(1, 10, CONSTRUCT_MAKE_BLOCK, make_block)
+
 } // namespace sh
 
 } // namespace detail
 
 using detail::sh::block_ptr;
 using detail::sh::block;
+using detail::sh::make_block;
 
 } // namespace boost
 
Modified: sandbox/block_ptr/boost/detail/block_base.hpp
==============================================================================
--- sandbox/block_ptr/boost/detail/block_base.hpp	(original)
+++ sandbox/block_ptr/boost/detail/block_base.hpp	2011-04-29 17:41:45 EDT (Fri, 29 Apr 2011)
@@ -181,7 +181,7 @@
 #define ARGUMENT_DECL(z, n, text) BOOST_PP_COMMA_IF(n) T ## n const & t ## n
 #define PARAMETER_DECL(z, n, text) BOOST_PP_COMMA_IF(n) t ## n
 
-#define CONSTRUCT_OWNED(z, n, text)																			    \
+#define CONSTRUCT_BLOCK(z, n, text)																			    \
         template <BOOST_PP_REPEAT(n, TEMPLATE_DECL, 0)>										                        \
                 text(BOOST_PP_REPEAT(n, ARGUMENT_DECL, 0)) : elem_(BOOST_PP_REPEAT(n, PARAMETER_DECL, 0)) {}																										
 
@@ -204,7 +204,7 @@
         {
         }
 
-        BOOST_PP_REPEAT_FROM_TO(1, 10, CONSTRUCT_OWNED, block)
+        BOOST_PP_REPEAT_FROM_TO(1, 10, CONSTRUCT_BLOCK, block)
 
 
                 /**
Modified: sandbox/block_ptr/libs/smart_ptr/example/t100.h
==============================================================================
--- sandbox/block_ptr/libs/smart_ptr/example/t100.h	(original)
+++ sandbox/block_ptr/libs/smart_ptr/example/t100.h	2011-04-29 17:41:45 EDT (Fri, 29 Apr 2011)
@@ -82,14 +82,14 @@
         
         static map_sn_t search_;
     
-        neuron(std::string const & s, pointee * p1 = 0, pointee * p2 = 0, pointee * p3 = 0) : neuron_base(s)
+        neuron(std::string const & s) : neuron_base(s)
         {
             /// FIXME
             //search_[s] = (pointee *) (typename pointee::roofof) static_cast<neuron *>(rootof<is_polymorphic<neuron>::value>::get(this));
-        
-            if (p1) sub_[0].second = p1;
-            if (p2) sub_[1].second = p2;
-            if (p3) sub_[2].second = p3;
+
+            //if (p1) sub_[0].second = p1;
+            //if (p2) sub_[1].second = p2;
+            //if (p3) sub_[2].second = p3;
         }
 
         double operator () (std::string const & input)
Modified: sandbox/block_ptr/libs/smart_ptr/example/t100_test1.cpp
==============================================================================
--- sandbox/block_ptr/libs/smart_ptr/example/t100_test1.cpp	(original)
+++ sandbox/block_ptr/libs/smart_ptr/example/t100_test1.cpp	2011-04-29 17:41:45 EDT (Fri, 29 Apr 2011)
@@ -18,9 +18,9 @@
 
 int main(int argv, char * argc[])
 {
-    block_ptr<neuron_sight> t100 = new block<neuron_sight>("I eat ([a-z]+) then drink ([a-z]+)");
-	t100->sub_[0].second = new block<neuron_sight>("beef|chicken");
-	t100->sub_[1].second = new block<neuron_sight>("vodka|water");
+    block_ptr<neuron_sight> t100 = make_block<neuron_sight>("I eat ([a-z]+) then drink ([a-z]+)");
+	t100->sub_[0].second = make_block<neuron_sight>("beef|chicken");
+	t100->sub_[1].second = make_block<neuron_sight>("vodka|water");
 
     cout << (* t100)("I eat beef then drink wine") << endl;
     cout << (* t100)("I eat beef then drink wine") << endl;