1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/ptr_container/ptr_array.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,239 @@
1.4 +//
1.5 +// Boost.Pointer Container
1.6 +//
1.7 +// Copyright Thorsten Ottosen 2003-2005. Use, modification and
1.8 +// distribution is subject to the Boost Software License, Version
1.9 +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.10 +// http://www.boost.org/LICENSE_1_0.txt)
1.11 +//
1.12 +// For more information, see http://www.boost.org/libs/ptr_container/
1.13 +//
1.14 +
1.15 +#ifndef BOOST_PTR_CONTAINER_PTR_ARRAY_HPP
1.16 +#define BOOST_PTR_CONTAINER_PTR_ARRAY_HPP
1.17 +
1.18 +#if defined(_MSC_VER) && (_MSC_VER >= 1200)
1.19 +# pragma once
1.20 +#endif
1.21 +
1.22 +#include <boost/array.hpp>
1.23 +#include <boost/static_assert.hpp>
1.24 +#include <boost/ptr_container/ptr_sequence_adapter.hpp>
1.25 +
1.26 +namespace boost
1.27 +{
1.28 +
1.29 + namespace ptr_container_detail
1.30 + {
1.31 + template
1.32 + <
1.33 + class T,
1.34 + size_t N,
1.35 + class Allocator = int // dummy
1.36 + >
1.37 + class ptr_array_impl : public boost::array<T,N>
1.38 + {
1.39 + public:
1.40 + typedef Allocator allocator_type;
1.41 +
1.42 + ptr_array_impl( Allocator a = Allocator() )
1.43 + {
1.44 + this->assign( 0 );
1.45 + }
1.46 +
1.47 + ptr_array_impl( size_t, T*, Allocator a = Allocator() )
1.48 + {
1.49 + this->assign( 0 );
1.50 + }
1.51 + };
1.52 + }
1.53 +
1.54 + template
1.55 + <
1.56 + class T,
1.57 + size_t N,
1.58 + class CloneAllocator = heap_clone_allocator
1.59 + >
1.60 + class ptr_array : public
1.61 + ptr_sequence_adapter< T,
1.62 + ptr_container_detail::ptr_array_impl<void*,N>,
1.63 + CloneAllocator >
1.64 + {
1.65 + private:
1.66 + typedef ptr_sequence_adapter< T,
1.67 + ptr_container_detail::ptr_array_impl<void*,N>,
1.68 + CloneAllocator >
1.69 + base_class;
1.70 +
1.71 + typedef BOOST_DEDUCED_TYPENAME remove_nullable<T>::type U;
1.72 +
1.73 + typedef ptr_array<T,N,CloneAllocator>
1.74 + this_type;
1.75 +
1.76 + ptr_array( const this_type& );
1.77 + void operator=( const this_type& );
1.78 +
1.79 + public:
1.80 + typedef std::size_t size_type;
1.81 + typedef U* value_type;
1.82 + typedef U* pointer;
1.83 + typedef U& reference;
1.84 + typedef const U& const_reference;
1.85 + typedef BOOST_DEDUCED_TYPENAME base_class::auto_type
1.86 + auto_type;
1.87 +
1.88 + public: // constructors
1.89 + ptr_array() : base_class()
1.90 + { }
1.91 +
1.92 + ptr_array( std::auto_ptr<this_type> r )
1.93 + : base_class( r ) { }
1.94 +
1.95 + void operator=( std::auto_ptr<this_type> r )
1.96 + {
1.97 + base_class::operator=(r);
1.98 + }
1.99 +
1.100 + std::auto_ptr<this_type> release()
1.101 + {
1.102 + std::auto_ptr<this_type> ptr( new this_type );
1.103 + this->swap( *ptr );
1.104 + return ptr;
1.105 + }
1.106 +
1.107 + std::auto_ptr<this_type> clone() const
1.108 + {
1.109 + std::auto_ptr<this_type> pa( new this_type );
1.110 + for( size_t i = 0; i != N; ++i )
1.111 + {
1.112 + if( ! is_null(i) )
1.113 + pa->replace( i, CloneAllocator::allocate_clone( (*this)[i] ) );
1.114 + }
1.115 + return pa;
1.116 + }
1.117 +
1.118 + private: // hide some members
1.119 + using base_class::insert;
1.120 + using base_class::erase;
1.121 + using base_class::push_back;
1.122 + using base_class::push_front;
1.123 + using base_class::pop_front;
1.124 + using base_class::pop_back;
1.125 + using base_class::transfer;
1.126 + using base_class::get_allocator;
1.127 +
1.128 + public: // compile-time interface
1.129 +
1.130 + template< size_t idx >
1.131 + auto_type replace( U* r ) // strong
1.132 + {
1.133 + BOOST_STATIC_ASSERT( idx < N );
1.134 +
1.135 + this->enforce_null_policy( r, "Null pointer in 'ptr_array::replace()'" );
1.136 +
1.137 + auto_type res( static_cast<U*>( this->c_private()[idx] ) ); // nothrow
1.138 + this->c_private()[idx] = r; // nothrow
1.139 + return move(res); // nothrow
1.140 + }
1.141 +
1.142 + template< size_t idx, class V >
1.143 + auto_type replace( std::auto_ptr<V> r )
1.144 + {
1.145 + return replace<idx>( r.release() );
1.146 + }
1.147 +
1.148 + auto_type replace( size_t idx, U* r ) // strong
1.149 + {
1.150 + this->enforce_null_policy( r, "Null pointer in 'ptr_array::replace()'" );
1.151 +
1.152 + auto_type ptr( r );
1.153 +
1.154 + BOOST_PTR_CONTAINER_THROW_EXCEPTION( idx >= N, bad_index,
1.155 + "'replace()' aout of bounds" );
1.156 +
1.157 + auto_type res( static_cast<U*>( this->c_private()[idx] ) ); // nothrow
1.158 + this->c_private()[idx] = ptr.release(); // nothrow
1.159 + return move(res); // nothrow
1.160 + }
1.161 +
1.162 + template< class V >
1.163 + auto_type replace( size_t idx, std::auto_ptr<V> r )
1.164 + {
1.165 + return replace( idx, r.release() );
1.166 + }
1.167 +
1.168 + using base_class::at;
1.169 +
1.170 + template< size_t idx >
1.171 + T& at()
1.172 + {
1.173 + BOOST_STATIC_ASSERT( idx < N );
1.174 + return (*this)[idx];
1.175 + }
1.176 +
1.177 + template< size_t idx >
1.178 + const T& at() const
1.179 + {
1.180 + BOOST_STATIC_ASSERT( idx < N );
1.181 + return (*this)[idx];
1.182 + }
1.183 +
1.184 + bool is_null( size_t idx ) const
1.185 + {
1.186 + return base_class::is_null(idx);
1.187 + }
1.188 +
1.189 + template< size_t idx >
1.190 + bool is_null() const
1.191 + {
1.192 + BOOST_STATIC_ASSERT( idx < N );
1.193 + return this->c_private()[idx] == 0;
1.194 + }
1.195 +
1.196 + public: // serialization
1.197 +
1.198 + template< class Archive >
1.199 + void save( Archive& ar, const unsigned ) const
1.200 + {
1.201 + this->save_helper( ar );
1.202 + }
1.203 +
1.204 + template< class Archive >
1.205 + void load( Archive& ar, const unsigned ) // basic
1.206 + {
1.207 + for( size_type i = 0u; i != N; ++i )
1.208 + {
1.209 + //
1.210 + // Remark: pointers are not tracked,
1.211 + // so we need not call ar.reset_object_address(v, u)
1.212 + //
1.213 + T* p;
1.214 + ar & p;
1.215 + this->replace( i, p );
1.216 + }
1.217 + }
1.218 +
1.219 + BOOST_SERIALIZATION_SPLIT_MEMBER()
1.220 +
1.221 + };
1.222 +
1.223 + //////////////////////////////////////////////////////////////////////////////
1.224 + // clonability
1.225 +
1.226 + template< typename T, size_t size, typename CA >
1.227 + inline ptr_array<T,size,CA>* new_clone( const ptr_array<T,size,CA>& r )
1.228 + {
1.229 + return r.clone().release();
1.230 + }
1.231 +
1.232 + /////////////////////////////////////////////////////////////////////////
1.233 + // swap
1.234 +
1.235 + template< typename T, size_t size, typename CA >
1.236 + inline void swap( ptr_array<T,size,CA>& l, ptr_array<T,size,CA>& r )
1.237 + {
1.238 + l.swap(r);
1.239 + }
1.240 +}
1.241 +
1.242 +#endif