Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54598 - sandbox/cloneable/boost/cloneable/detail
From: christian.schladetsch_at_[hidden]
Date: 2009-07-02 18:22:32


Author: cschladetsch
Date: 2009-07-02 18:22:32 EDT (Thu, 02 Jul 2009)
New Revision: 54598
URL: http://svn.boost.org/trac/boost/changeset/54598

Log:
renamed to instance

Text files modified:
   sandbox/cloneable/boost/cloneable/detail/pointer.hpp | 110 ++++++++++++++++++++++++++-------------
   1 files changed, 72 insertions(+), 38 deletions(-)

Modified: sandbox/cloneable/boost/cloneable/detail/pointer.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/pointer.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/pointer.hpp 2009-07-02 18:22:32 EDT (Thu, 02 Jul 2009)
@@ -8,51 +8,85 @@
 
 #include <boost/cloneable/detail/prefix.hpp>
 #include <boost/cloneable/base.hpp>
+#include <boost/cloneable/allocator.hpp>
 
 namespace boost
 {
         namespace cloneable
         {
- namespace detail
+ /// a pointer store that can retrieve pointers from up and down
+ /// the inheritance tree. stores the allocator that made it.
+ template <class U, class B, class Alloc>
+ struct instance
                 {
- /// a pointer store that can retrieve pointers from up and down
- /// the inheritance tree.
- template <class U, class B>
- struct pointer
- {
- typedef U derived_type;
- typedef B base_type;
- typedef base<derived_type, base_type> cloneable_type;
- typedef typename cloneable_type::abstract_base_type abstract_base_type;
-
- private:
- cloneable_type *ptr;
-
- public:
- pointer(derived_type *p = 0) : ptr(dynamic_cast<cloneable_type *>(p))
- {
- }
- abstract_base_type *to_abstract() const
- {
- return ptr;
- }
- base_type *to_base() const
- {
- return ptr;
- }
- cloneable_type *to_cloneable() const
- {
- return ptr;
- }
- derived_type *to_derived() const
- {
- if (!ptr)
- return 0;
- return ptr->cloneable_type::self_ptr;
- }
- };
+ typedef U derived_type;
+ typedef B base_type;
+ typedef Alloc allocator_type;
+ typedef base<derived_type, base_type> cloneable_type;
+ typedef typename cloneable_type::abstract_base_type abstract_base_type;
+
+ private:
+ cloneable_type *ptr;
+ allocator_type *alloc;
 
- } // namespace detail
+ public:
+ instance() : ptr(0), alloc(0) { }
+
+ instance(allocator_type &al) : ptr(0), alloc(&al)
+ {
+ allocate();
+ }
+ template <class A0>
+ instance(allocator_type &al, A0 a0) : ptr(0), alloc(&al)
+ {
+ allocate();
+ new (to_derived()) U(a0);
+ }
+ template <class A0, class A1>
+ instance(allocator_type &al, A0 a0, A1 a1) : ptr(0), alloc(&al)
+ {
+ allocate();
+ new (to_derived()) U(a0, a1);
+ }
+ template <class A0, class A1, class A2>
+ instance(allocator_type &al, A0 a0, A1 a1, A2 a2) : ptr(0), alloc(&al)
+ {
+ allocate();
+ new (to_derived()) U(a0, a1);
+ }
+
+ void allocate()
+ {
+ if (!alloc)
+ return;
+ ptr = cloneable::allocate<U>(*alloc);
+ }
+ void release()
+ {
+ if (!alloc)
+ return;
+ cloneable::release(ptr, *alloc);
+ ptr = 0;
+ }
+ abstract_base_type *to_abstract() const
+ {
+ return ptr;
+ }
+ base_type *to_base() const
+ {
+ return ptr;
+ }
+ cloneable_type *to_cloneable() const
+ {
+ return ptr;
+ }
+ derived_type *to_derived() const
+ {
+ if (!ptr)
+ return 0;
+ return ptr->cloneable_type::self_ptr;
+ }
+ };
 
         } // namespace cloneable
 


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