File indexing completed on 2025-01-18 09:51:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_RANGE_DETAIL_ANY_ITERATOR_BUFFER_HPP_INCLUDED
0011 #define BOOST_RANGE_DETAIL_ANY_ITERATOR_BUFFER_HPP_INCLUDED
0012
0013 #include <boost/array.hpp>
0014 #include <boost/assert.hpp>
0015 #include <boost/static_assert.hpp>
0016 #include <boost/noncopyable.hpp>
0017
0018 namespace boost
0019 {
0020 template<std::size_t StackBufferSize>
0021 class any_iterator_buffer
0022 : noncopyable
0023 {
0024 BOOST_STATIC_ASSERT(( StackBufferSize > 0 ));
0025 public:
0026 any_iterator_buffer()
0027 : m_ptr()
0028 {
0029 }
0030
0031 ~any_iterator_buffer()
0032 {
0033 delete [] m_ptr;
0034 }
0035
0036 void* allocate(std::size_t bytes)
0037 {
0038 BOOST_ASSERT( !m_ptr );
0039 if (bytes <= StackBufferSize)
0040 return m_buffer.data();
0041
0042 m_ptr = new char[bytes];
0043 return m_ptr;
0044 }
0045
0046 void deallocate()
0047 {
0048 delete [] m_ptr;
0049 m_ptr = 0;
0050 }
0051
0052 private:
0053
0054
0055
0056
0057 any_iterator_buffer(const any_iterator_buffer&);
0058 void operator=(const any_iterator_buffer&);
0059
0060 char* m_ptr;
0061 boost::array<char, StackBufferSize> m_buffer;
0062 };
0063
0064 class any_iterator_heap_only_buffer
0065 : noncopyable
0066 {
0067 public:
0068 any_iterator_heap_only_buffer()
0069 : m_ptr()
0070 {
0071 }
0072
0073 ~any_iterator_heap_only_buffer()
0074 {
0075 delete [] m_ptr;
0076 }
0077
0078 void* allocate(std::size_t bytes)
0079 {
0080 BOOST_ASSERT( !m_ptr );
0081 m_ptr = new char[bytes];
0082 return m_ptr;
0083 }
0084
0085 void deallocate()
0086 {
0087 delete [] m_ptr;
0088 m_ptr = 0;
0089 }
0090
0091 private:
0092 char* m_ptr;
0093 };
0094
0095 template<std::size_t StackBufferSize>
0096 class any_iterator_stack_only_buffer
0097 {
0098 BOOST_STATIC_ASSERT(( StackBufferSize > 0 ));
0099 public:
0100 void* allocate(std::size_t bytes)
0101 {
0102 BOOST_ASSERT( bytes <= m_buffer.size() );
0103 return m_buffer.data();
0104 }
0105
0106 void deallocate()
0107 {
0108 }
0109
0110 private:
0111 boost::array<char, StackBufferSize> m_buffer;
0112 };
0113
0114 typedef any_iterator_buffer<64> any_iterator_default_buffer;
0115 }
0116
0117 #endif