epoc32/include/stdapis/boost/ptr_container/clone_allocator.hpp
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     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/assert.hpp>
    16 #include <boost/checked_delete.hpp>
    17 #include <typeinfo>
    18 
    19 namespace boost
    20 {
    21     /////////////////////////////////////////////////////////////////////////
    22     // Clonable concept 
    23     /////////////////////////////////////////////////////////////////////////
    24     
    25     template< class T >
    26     inline T* new_clone( const T& r )
    27     {
    28         T* res = new T( r );
    29         BOOST_ASSERT( typeid(r) == typeid(*res) &&
    30                       "Default new_clone() sliced object!" );
    31         return res;
    32     }
    33 
    34     template< class T >
    35     inline void delete_clone( const T* r )
    36     {
    37         checked_delete( r );
    38     }
    39 
    40     /////////////////////////////////////////////////////////////////////////
    41     // CloneAllocator concept
    42     /////////////////////////////////////////////////////////////////////////
    43     
    44     struct heap_clone_allocator
    45     {
    46         template< class U >
    47         static U* allocate_clone( const U& r )
    48         {
    49             return new_clone( r );
    50         }
    51 
    52         template< class U >
    53         static void deallocate_clone( const U* r )
    54         {
    55             delete_clone( r );
    56         }
    57 
    58     };
    59 
    60 
    61     
    62     struct view_clone_allocator
    63     {
    64         template< class U >
    65         static U* allocate_clone( const U& r )
    66         {
    67             return const_cast<U*>( &r );
    68         }
    69 
    70         template< class U >
    71         static void deallocate_clone( const U* r )
    72         {
    73             // do nothing
    74         }
    75     };
    76 
    77 } // namespace 'boost'
    78 
    79 #endif
    80