00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00038 #ifndef BLOCXX_ARRAY_HPP_INCLUDE_GUARD_
00039 #define BLOCXX_ARRAY_HPP_INCLUDE_GUARD_
00040 #include "blocxx/BLOCXX_config.h"
00041 #include "blocxx/ArrayFwd.hpp"
00042 #include "blocxx/COWReference.hpp"
00043 #include "blocxx/Types.hpp"
00044 #include "blocxx/Exception.hpp"
00045 #include "blocxx/vector.hpp"
00046
00047 namespace BLOCXX_NAMESPACE
00048 {
00049
00050
00051 BLOCXX_DECLARE_APIEXCEPTION(OutOfBounds, BLOCXX_COMMON_API);
00052
00063 template<class T> class Array
00064 {
00065 typedef std::vector<T, std::allocator<T> > V;
00066
00067 #ifdef BLOCXX_WIN32
00068 #pragma warning (push)
00069 #pragma warning (disable: 4251)
00070 #endif
00071
00072 COWReference<V> m_impl;
00073
00074 #ifdef BLOCXX_WIN32
00075 #pragma warning (pop)
00076 #endif
00077
00078 public:
00079 typedef typename V::value_type value_type;
00080 typedef typename V::pointer pointer;
00081 typedef typename V::const_pointer const_pointer;
00082 typedef typename V::iterator iterator;
00083 typedef typename V::const_iterator const_iterator;
00084 typedef typename V::reference reference;
00085 typedef typename V::const_reference const_reference;
00086 typedef typename V::size_type size_type;
00087 typedef typename V::difference_type difference_type;
00088 typedef typename V::reverse_iterator reverse_iterator;
00089 typedef typename V::const_reverse_iterator const_reverse_iterator;
00090
00094 Array();
00098 ~Array();
00103 explicit Array(V* toWrap);
00111 Array(size_type n, const T& value);
00119 Array(int n, const T& value);
00127 Array(long n, const T& value);
00134 explicit Array(size_type n);
00140 template<class InputIterator>
00141 Array(InputIterator first, InputIterator last);
00147 iterator begin();
00153 const_iterator begin() const;
00159 iterator end();
00165 const_iterator end() const;
00171 reverse_iterator rbegin();
00177 const_reverse_iterator rbegin() const;
00183 reverse_iterator rend();
00189 const_reverse_iterator rend() const;
00193 size_type size() const;
00197 size_type max_size() const;
00202 size_type capacity() const;
00206 bool empty() const;
00213 reference operator[](size_type n);
00220 const_reference operator[](size_type n) const;
00226 Array<T>& operator+= (const T& x);
00233 void reserve(size_type n);
00237 reference front();
00241 const_reference front() const;
00245 reference back();
00249 const_reference back() const;
00254 void push_back(const T& x);
00260 void append(const T& x);
00265 void swap(Array<T>& x);
00275 iterator insert(iterator position, const T& x);
00283 void insert(size_type position, const T& x);
00287 void remove(size_type index);
00294 void remove(size_type begin, size_type end);
00302 template<class InputIterator>
00303 void insert(iterator position, InputIterator first, InputIterator last);
00308 void appendArray(const Array<T>& x);
00312 void pop_back();
00319 iterator erase(iterator position);
00328 iterator erase(iterator first, iterator last);
00335 void resize(size_type new_size, const T& x);
00342 void resize(size_type new_size);
00347 void clear();
00357 const_iterator find(const T &x, const_iterator first,
00358 const_iterator last) const;
00365 const_iterator find(const T &x) const;
00375 iterator find(const T &x, iterator first, iterator last);
00382 iterator find(const T &x);
00392 bool contains(const T& x, const_iterator first,
00393 const_iterator last) const;
00399 bool contains(const T& x) const;
00400
00409 friend bool operator== <>(const Array<T>& x, const Array<T>& y);
00410
00428 friend bool operator< <>(const Array<T>& x, const Array<T>& y);
00429 private:
00430 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00431 void checkValidIndex(size_type index) const;
00432 #endif
00433 };
00434
00443 template <class T>
00444 inline bool operator != (const Array<T>& x, const Array<T>& y)
00445 {
00446 return !(x == y);
00447 }
00448
00466 template <class T>
00467 inline bool operator <= (const Array<T>& x, const Array<T>& y)
00468 {
00469 return !(y < x);
00470 }
00471
00489 template <class T>
00490 inline bool operator >= (const Array<T>& x, const Array<T>& y)
00491 {
00492 return !(x < y);
00493 }
00494
00512 template <class T>
00513 inline bool operator > (const Array<T>& x, const Array<T>& y)
00514 {
00515 return y < x;
00516 }
00517
00518 typedef Array<UInt8> UInt8Array;
00519 typedef Array<Int8> Int8Array;
00520 typedef Array<UInt16> UInt16Array;
00521 typedef Array<Int16> Int16Array;
00522 typedef Array<UInt32> UInt32Array;
00523 typedef Array<Int32> Int32Array;
00524 typedef Array<UInt64> UInt64Array;
00525 typedef Array<Int64> Int64Array;
00526 typedef Array<Real64> Real64Array;
00527 typedef Array<Real32> Real32Array;
00528
00529 }
00530
00531 #include "blocxx/ArrayImpl.hpp"
00532
00533 #endif
00534