00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef STXXL_SIMPLE_VECTOR_HEADER
00014 #define STXXL_SIMPLE_VECTOR_HEADER
00015
00016 #include <stxxl/bits/noncopyable.h>
00017 #include <stxxl/bits/common/utils.h>
00018
00019
00020 __STXXL_BEGIN_NAMESPACE
00021
00022 template <class _Tp >
00023 class simple_vector : private noncopyable
00024 {
00025 simple_vector()
00026 { }
00027
00028 public:
00029 typedef size_t size_type;
00030 typedef _Tp value_type;
00031
00032
00033 protected:
00034 size_type _size;
00035 value_type * _array;
00036
00037 public:
00038 typedef value_type * iterator;
00039 typedef const value_type * const_iterator;
00040 typedef value_type & reference;
00041 typedef const value_type & const_reference;
00042
00043 simple_vector(size_type sz) : _size(sz)
00044 {
00045
00046
00047 _array = new _Tp[sz];
00048 }
00049 void swap(simple_vector & obj)
00050 {
00051 std::swap(_size, obj._size);
00052 std::swap(_array, obj._array);
00053 }
00054 ~simple_vector()
00055 {
00056
00057 delete[] _array;
00058 }
00059 iterator begin()
00060 {
00061 return _array;
00062 }
00063 const_iterator begin() const
00064 {
00065 return _array;
00066 }
00067 const_iterator cbegin() const
00068 {
00069 return begin();
00070 }
00071 iterator end()
00072 {
00073 return _array + _size;
00074 }
00075 const_iterator end() const
00076 {
00077 return _array + _size;
00078 }
00079 const_iterator cend() const
00080 {
00081 return end();
00082 }
00083 size_type size() const
00084 {
00085 return _size;
00086 }
00087 reference operator [] (size_type i)
00088 {
00089 return *(begin() + i);
00090 }
00091 const_reference operator [] (size_type i) const
00092 {
00093 return *(begin() + i);
00094 }
00095 };
00096 __STXXL_END_NAMESPACE
00097
00098 namespace std
00099 {
00100 template <class Tp_>
00101 void swap(stxxl::simple_vector<Tp_> & a,
00102 stxxl::simple_vector<Tp_> & b)
00103 {
00104 a.swap(b);
00105 }
00106 }
00107
00108 #endif // !STXXL_SIMPLE_VECTOR_HEADER