• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

simple_vector.h

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

Generated on Sun Oct 17 2010 06:13:44 for Stxxl by  doxygen 1.7.1