Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50140 - sandbox/dataflow-rewrite/boost/functional
From: stipe_at_[hidden]
Date: 2008-12-05 13:32:50


Author: srajko
Date: 2008-12-05 13:32:49 EST (Fri, 05 Dec 2008)
New Revision: 50140
URL: http://svn.boost.org/trac/boost/changeset/50140

Log:
updating with trunk versions of functional/factories
Added:
   sandbox/dataflow-rewrite/boost/functional/value_factory.hpp (contents, props changed)
Text files modified:
   sandbox/dataflow-rewrite/boost/functional/factory.hpp | 154 ++++++++++++++++++++++++++-------------
   1 files changed, 101 insertions(+), 53 deletions(-)

Modified: sandbox/dataflow-rewrite/boost/functional/factory.hpp
==============================================================================
--- sandbox/dataflow-rewrite/boost/functional/factory.hpp (original)
+++ sandbox/dataflow-rewrite/boost/functional/factory.hpp 2008-12-05 13:32:49 EST (Fri, 05 Dec 2008)
@@ -15,7 +15,10 @@
 
 # include <new>
 # include <boost/pointee.hpp>
+# include <boost/none_t.hpp>
 # include <boost/get_pointer.hpp>
+# include <boost/non_type.hpp>
+# include <boost/type_traits/remove_cv.hpp>
 
 # ifndef BOOST_FUNCTIONAL_FACTORY_MAX_ARITY
 # define BOOST_FUNCTIONAL_FACTORY_MAX_ARITY 10
@@ -26,88 +29,133 @@
 
 namespace boost
 {
- template< typename Pointer, class Allocator = std::allocator<void> >
- struct factory
+ enum factory_alloc_propagation
     {
- typedef typename boost::remove_cv<Pointer>::type result_type;
- typedef typename boost::pointee<result_type>::type value_type;
- typedef typename Allocator::template rebind<value_type>::other
- allocator_type;
- private:
- mutable allocator_type obj_allocator;
+ factory_alloc_for_pointee_and_deleter,
+ factory_passes_alloc_to_smart_pointer
+ };
 
- class memory;
+ template< typename Pointer, class Allocator = boost::none_t,
+ factory_alloc_propagation AP = factory_alloc_for_pointee_and_deleter >
+ class factory;
+
+ //----- ---- --- -- - - - -
+
+ template< typename Pointer >
+ class factory<Pointer, boost::none_t>
+ {
       public:
+ typedef typename boost::remove_cv<Pointer>::type result_type;
+ typedef typename boost::pointee<result_type>::type value_type;
 
- explicit factory(allocator_type const & a = allocator_type())
- : obj_allocator(a)
+ factory()
         { }
 
- inline result_type operator()() const
- {
- memory m(this->obj_allocator);
- result_type result( new(m.get()) value_type() );
- m.release();
- return result;
- }
-
 # define BOOST_PP_FILENAME_1 <boost/functional/factory.hpp>
-# define BOOST_PP_ITERATION_LIMITS (1,BOOST_FUNCTIONAL_FACTORY_MAX_ARITY)
+# define BOOST_PP_ITERATION_LIMITS (0,BOOST_FUNCTIONAL_FACTORY_MAX_ARITY)
 # include BOOST_PP_ITERATE()
-
     };
 
- template< typename Pointer, class Allocator >
- struct factory<Pointer&, Allocator>;
- // forbidden, would create a dangling reference
-
- template< typename Pointer, class Allocator >
- class factory<Pointer,Allocator>::memory
- // implements scope-guarded memory allocation
+ template< class Pointer, class Allocator, factory_alloc_propagation AP >
+ class factory
+ : Allocator::template rebind< typename boost::pointee<
+ typename boost::remove_cv<Pointer>::type >::type >::other
     {
- allocator_type & ref_allocator;
- value_type * ptr_memory;
       public:
+ typedef typename boost::remove_cv<Pointer>::type result_type;
+ typedef typename boost::pointee<result_type>::type value_type;
+
+ typedef typename Allocator::template rebind<value_type>::other
+ allocator_type;
+
+ explicit factory(allocator_type const & a = allocator_type())
+ : allocator_type(a)
+ { }
+
+ private:
 
- explicit memory(allocator_type & a)
- : ref_allocator(a)
- , ptr_memory(0l)
+ struct deleter
+ : allocator_type
         {
- this->ptr_memory = a.allocate(1);
- }
+ inline deleter(allocator_type const& that)
+ : allocator_type(that)
+ { }
+
+ allocator_type& get_allocator() const
+ {
+ return *const_cast<allocator_type*>(
+ static_cast<allocator_type const*>(this));
+ }
+
+ void operator()(value_type* ptr) const
+ {
+ if (!! ptr) ptr->~value_type();
+ const_cast<allocator_type*>(static_cast<allocator_type const*>(
+ this))->deallocate(ptr,1);
+ }
+ };
 
- value_type * get() const
+ inline allocator_type& get_allocator() const
         {
- return this->ptr_memory;
+ return *const_cast<allocator_type*>(
+ static_cast<allocator_type const*>(this));
         }
 
- void release()
+ inline result_type make_pointer(value_type* ptr, boost::non_type<
+ factory_alloc_propagation,factory_passes_alloc_to_smart_pointer>)
+ const
         {
- this->ptr_memory = 0l;
+ return result_type(ptr,deleter(this->get_allocator()));
         }
-
- ~memory()
+ inline result_type make_pointer(value_type* ptr, boost::non_type<
+ factory_alloc_propagation,factory_alloc_for_pointee_and_deleter>)
+ const
         {
- if (!! this->ptr_memory)
- this->ref_allocator.deallocate(this->ptr_memory,1);
+ return result_type(ptr,deleter(this->get_allocator()),
+ this->get_allocator());
         }
+
+ public:
+
+# define BOOST_TMP_MACRO
+# define BOOST_PP_FILENAME_1 <boost/functional/factory.hpp>
+# define BOOST_PP_ITERATION_LIMITS (0,BOOST_FUNCTIONAL_FACTORY_MAX_ARITY)
+# include BOOST_PP_ITERATE()
+# undef BOOST_TMP_MACRO
     };
+
+ template< typename Pointer, class Allocator >
+ class factory<Pointer&, Allocator>;
+ // forbidden, would create a dangling reference
 }
 
 # define BOOST_FUNCTIONAL_FACTORY_HPP_INCLUDED
 # else // defined(BOOST_PP_IS_ITERATING)
 # define N BOOST_PP_ITERATION()
-
- template< BOOST_PP_ENUM_PARAMS(N, typename T) >
- inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
- {
- memory m(this->obj_allocator);
- result_type result( new(m.get()) value_type(
- BOOST_PP_ENUM_PARAMS(N, a)) );
- m.release();
- return result;
+# if !defined(BOOST_TMP_MACRO)
+# if N > 0
+ template< BOOST_PP_ENUM_PARAMS(N, typename T) >
+# endif
+ inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
+ {
+ return result_type( new value_type(BOOST_PP_ENUM_PARAMS(N,a)) );
+ }
+# else // defined(BOOST_TMP_MACRO)
+# if N > 0
+ template< BOOST_PP_ENUM_PARAMS(N, typename T) >
+# endif
+ inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
+ {
+ value_type* memory = this->get_allocator().allocate(1);
+ try
+ {
+ return make_pointer(
+ new(memory) value_type(BOOST_PP_ENUM_PARAMS(N,a)),
+ boost::non_type<factory_alloc_propagation,AP>() );
         }
-
+ catch (...) { this->get_allocator().deallocate(memory,1); throw; }
+ }
+# endif
 # undef N
 # endif // defined(BOOST_PP_IS_ITERATING)
 

Added: sandbox/dataflow-rewrite/boost/functional/value_factory.hpp
==============================================================================
--- (empty file)
+++ sandbox/dataflow-rewrite/boost/functional/value_factory.hpp 2008-12-05 13:32:49 EST (Fri, 05 Dec 2008)
@@ -0,0 +1,70 @@
+/*=============================================================================
+ Copyright (c) 2007 Tobias Schwinger
+
+ Use modification and distribution are subject to 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).
+==============================================================================*/
+
+#ifndef BOOST_FUNCTIONAL_VALUE_FACTORY_HPP_INCLUDED
+# ifndef BOOST_PP_IS_ITERATING
+
+# include <boost/preprocessor/iteration/iterate.hpp>
+# include <boost/preprocessor/repetition/enum_params.hpp>
+# include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+# include <new>
+# include <boost/pointee.hpp>
+# include <boost/none_t.hpp>
+# include <boost/get_pointer.hpp>
+# include <boost/non_type.hpp>
+# include <boost/type_traits/remove_cv.hpp>
+
+# ifndef BOOST_FUNCTIONAL_VALUE_FACTORY_MAX_ARITY
+# define BOOST_FUNCTIONAL_VALUE_FACTORY_MAX_ARITY 10
+# elif BOOST_FUNCTIONAL_VALUE_FACTORY_MAX_ARITY < 3
+# undef BOOST_FUNCTIONAL_VALUE_FACTORY_MAX_ARITY
+# define BOOST_FUNCTIONAL_VALUE_FACTORY_MAX_ARITY 3
+# endif
+
+namespace boost
+{
+ template< typename T >
+ class value_factory;
+
+ //----- ---- --- -- - - - -
+
+ template< typename T >
+ class value_factory
+ {
+ public:
+ typedef T result_type;
+
+ value_factory()
+ { }
+
+# define BOOST_PP_FILENAME_1 <boost/functional/value_factory.hpp>
+# define BOOST_PP_ITERATION_LIMITS (0,BOOST_FUNCTIONAL_VALUE_FACTORY_MAX_ARITY)
+# include BOOST_PP_ITERATE()
+ };
+
+ template< typename T > class value_factory<T&>;
+ // forbidden, would create a dangling reference
+}
+# define BOOST_FUNCTIONAL_VALUE_FACTORY_HPP_INCLUDED
+# else // defined(BOOST_PP_IS_ITERATING)
+
+# define N BOOST_PP_ITERATION()
+# if N > 0
+ template< BOOST_PP_ENUM_PARAMS(N, typename T) >
+# endif
+ inline result_type operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
+ {
+ return result_type(BOOST_PP_ENUM_PARAMS(N,a));
+ }
+# undef N
+
+# endif // defined(BOOST_PP_IS_ITERATING)
+
+#endif // include guard
+


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