Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/common/simple_vector.h 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de> 00007 * Copyright (C) 2008, 2011 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00008 * 00009 * Distributed under the Boost Software License, Version 1.0. 00010 * (See accompanying file LICENSE_1_0.txt or copy at 00011 * http://www.boost.org/LICENSE_1_0.txt) 00012 **************************************************************************/ 00013 00014 #ifndef STXXL_SIMPLE_VECTOR_HEADER 00015 #define STXXL_SIMPLE_VECTOR_HEADER 00016 00017 #include <algorithm> 00018 #include <stxxl/bits/noncopyable.h> 00019 #include <stxxl/bits/common/types.h> 00020 00021 00022 __STXXL_BEGIN_NAMESPACE 00023 00024 template <class _Tp /*, class _Alloc=__STL_DEFAULT_ALLOCATOR(_Tp) */> 00025 class simple_vector : private noncopyable 00026 { 00027 public: 00028 typedef unsigned_type size_type; 00029 typedef _Tp value_type; 00030 // typedef simple_alloc<_Tp, _Alloc> _data_allocator; 00031 00032 protected: 00033 size_type _size; 00034 value_type * _array; 00035 00036 public: 00037 typedef value_type * iterator; 00038 typedef const value_type * const_iterator; 00039 typedef value_type & reference; 00040 typedef const value_type & const_reference; 00041 00042 simple_vector(size_type sz) : _size(sz), _array(NULL) 00043 { 00044 // _array = _data_allocator.allocate(sz); 00045 if (size() > 0) 00046 _array = new _Tp[size()]; 00047 } 00048 void swap(simple_vector & obj) 00049 { 00050 std::swap(_size, obj._size); 00051 std::swap(_array, obj._array); 00052 } 00053 ~simple_vector() 00054 { 00055 // _data_allocator.deallocate(_array,_size); 00056 delete[] _array; 00057 } 00058 iterator begin() 00059 { 00060 return _array; 00061 } 00062 const_iterator begin() const 00063 { 00064 return _array; 00065 } 00066 const_iterator cbegin() const 00067 { 00068 return begin(); 00069 } 00070 iterator end() 00071 { 00072 return _array + _size; 00073 } 00074 const_iterator end() const 00075 { 00076 return _array + _size; 00077 } 00078 const_iterator cend() const 00079 { 00080 return end(); 00081 } 00082 size_type size() const 00083 { 00084 return _size; 00085 } 00086 reference operator [] (size_type i) 00087 { 00088 return *(begin() + i); 00089 } 00090 const_reference operator [] (size_type i) const 00091 { 00092 return *(begin() + i); 00093 } 00094 }; 00095 __STXXL_END_NAMESPACE 00096 00097 namespace std 00098 { 00099 template <class Tp_> 00100 void swap(stxxl::simple_vector<Tp_> & a, 00101 stxxl::simple_vector<Tp_> & b) 00102 { 00103 a.swap(b); 00104 } 00105 } 00106 00107 #endif // !STXXL_SIMPLE_VECTOR_HEADER