| 1 | // |
|---|
| 2 | // Boost.Pointer Container |
|---|
| 3 | // |
|---|
| 4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and |
|---|
| 5 | // distribution is subject to the Boost Software License, Version |
|---|
| 6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | // |
|---|
| 9 | // For more information, see http://www.boost.org/libs/ptr_container/ |
|---|
| 10 | // |
|---|
| 11 | |
|---|
| 12 | #ifndef BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP |
|---|
| 13 | #define BOOST_PTR_CONTAINER_CLONE_ALLOCATOR_HPP |
|---|
| 14 | |
|---|
| 15 | #include <boost/checked_delete.hpp> |
|---|
| 16 | |
|---|
| 17 | namespace boost |
|---|
| 18 | { |
|---|
| 19 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 20 | // Clonable concept |
|---|
| 21 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 22 | |
|---|
| 23 | template< class T > |
|---|
| 24 | inline T* new_clone( const T& r ) |
|---|
| 25 | { |
|---|
| 26 | return new T( r ); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | template< class T > |
|---|
| 30 | inline void delete_clone( const T* r ) |
|---|
| 31 | { |
|---|
| 32 | checked_delete( r ); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 36 | // CloneAllocator concept |
|---|
| 37 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 38 | |
|---|
| 39 | struct heap_clone_allocator |
|---|
| 40 | { |
|---|
| 41 | template< class U > |
|---|
| 42 | static U* allocate_clone( const U& r ) |
|---|
| 43 | { |
|---|
| 44 | return new_clone( r ); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | template< class U > |
|---|
| 48 | static void deallocate_clone( const U* r ) |
|---|
| 49 | { |
|---|
| 50 | delete_clone( r ); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | struct view_clone_allocator |
|---|
| 58 | { |
|---|
| 59 | template< class U > |
|---|
| 60 | static U* allocate_clone( const U& r ) |
|---|
| 61 | { |
|---|
| 62 | return const_cast<U*>( &r ); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | template< class U > |
|---|
| 66 | static void deallocate_clone( const U* r ) |
|---|
| 67 | { |
|---|
| 68 | // do nothing |
|---|
| 69 | } |
|---|
| 70 | }; |
|---|
| 71 | |
|---|
| 72 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 73 | // MapCloneAllocator concept |
|---|
| 74 | ///////////////////////////////////////////////////////////////////////// |
|---|
| 75 | |
|---|
| 76 | template< class T > |
|---|
| 77 | inline T* new_default_clone( const T* ) |
|---|
| 78 | { |
|---|
| 79 | return new T(); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | struct map_heap_clone_allocator : heap_clone_allocator |
|---|
| 83 | { |
|---|
| 84 | template< class U > |
|---|
| 85 | static U* allocate_default_clone() |
|---|
| 86 | { |
|---|
| 87 | static const U* ptr = 0; |
|---|
| 88 | return new_default_clone(ptr); |
|---|
| 89 | } |
|---|
| 90 | }; |
|---|
| 91 | |
|---|
| 92 | } // namespace 'boost' |
|---|
| 93 | |
|---|
| 94 | #endif |
|---|
| 95 | |
|---|