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
00033
00034
00040 #ifndef BLOCXX_ARRAY_HPP_INCLUDE_GUARD_
00041 #define BLOCXX_ARRAY_HPP_INCLUDE_GUARD_
00042 #include "blocxx/BLOCXX_config.h"
00043 #include "blocxx/ArrayFwd.hpp"
00044 #include "blocxx/COWReference.hpp"
00045 #include "blocxx/Types.hpp"
00046 #include "blocxx/Exception.hpp"
00047 #include "blocxx/vector.hpp"
00048
00049 namespace BLOCXX_NAMESPACE
00050 {
00051
00052
00053 BLOCXX_DECLARE_APIEXCEPTION(OutOfBounds, BLOCXX_COMMON_API);
00054
00065 template<class T> class Array
00066 {
00067 typedef std::vector<T, std::allocator<T> > V;
00068
00069 #ifdef BLOCXX_WIN32
00070 #pragma warning (push)
00071 #pragma warning (disable: 4251)
00072 #endif
00073
00074 COWReference<V> m_impl;
00075
00076 #ifdef BLOCXX_WIN32
00077 #pragma warning (pop)
00078 #endif
00079
00080 public:
00081 typedef typename V::value_type value_type;
00082 typedef typename V::pointer pointer;
00083 typedef typename V::const_pointer const_pointer;
00084 typedef typename V::iterator iterator;
00085 typedef typename V::const_iterator const_iterator;
00086 typedef typename V::reference reference;
00087 typedef typename V::const_reference const_reference;
00088 typedef typename V::size_type size_type;
00089 typedef typename V::difference_type difference_type;
00090 typedef typename V::reverse_iterator reverse_iterator;
00091 typedef typename V::const_reverse_iterator const_reverse_iterator;
00092
00096 Array();
00100 ~Array();
00105 explicit Array(V* toWrap);
00113 Array(size_type n, const T& value);
00121 Array(int n, const T& value);
00129 Array(long n, const T& value);
00136 explicit Array(size_type n);
00142 template<class InputIterator>
00143 Array(InputIterator first, InputIterator last);
00149 iterator begin();
00155 const_iterator begin() const;
00161 iterator end();
00167 const_iterator end() const;
00173 reverse_iterator rbegin();
00179 const_reverse_iterator rbegin() const;
00185 reverse_iterator rend();
00191 const_reverse_iterator rend() const;
00195 size_type size() const;
00199 size_type max_size() const;
00204 size_type capacity() const;
00208 bool empty() const;
00215 reference operator[](size_type n);
00222 const_reference operator[](size_type n) const;
00228 Array<T>& operator+= (const T& x);
00235 void reserve(size_type n);
00239 reference front();
00243 const_reference front() const;
00247 reference back();
00251 const_reference back() const;
00256 void push_back(const T& x);
00262 void append(const T& x);
00267 void swap(Array<T>& x);
00277 iterator insert(iterator position, const T& x);
00285 void insert(size_type position, const T& x);
00289 void remove(size_type index);
00296 void remove(size_type begin, size_type end);
00304 template<class InputIterator>
00305 void insert(iterator position, InputIterator first, InputIterator last);
00310 void appendArray(const Array<T>& x);
00314 void pop_back();
00321 iterator erase(iterator position);
00330 iterator erase(iterator first, iterator last);
00337 void resize(size_type new_size, const T& x);
00344 void resize(size_type new_size);
00349 void clear();
00359 const_iterator find(const T &x, const_iterator first,
00360 const_iterator last) const;
00367 const_iterator find(const T &x) const;
00377 iterator find(const T &x, iterator first, iterator last);
00384 iterator find(const T &x);
00394 bool contains(const T& x, const_iterator first,
00395 const_iterator last) const;
00401 bool contains(const T& x) const;
00402
00411 friend bool operator== <>(const Array<T>& x, const Array<T>& y);
00412
00430 friend bool operator< <>(const Array<T>& x, const Array<T>& y);
00431 private:
00432 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00433 void checkValidIndex(size_type index) const;
00434 #endif
00435 };
00436
00445 template <class T>
00446 inline bool operator != (const Array<T>& x, const Array<T>& y)
00447 {
00448 return !(x == y);
00449 }
00450
00468 template <class T>
00469 inline bool operator <= (const Array<T>& x, const Array<T>& y)
00470 {
00471 return !(y < x);
00472 }
00473
00491 template <class T>
00492 inline bool operator >= (const Array<T>& x, const Array<T>& y)
00493 {
00494 return !(x < y);
00495 }
00496
00514 template <class T>
00515 inline bool operator > (const Array<T>& x, const Array<T>& y)
00516 {
00517 return y < x;
00518 }
00519
00520 typedef Array<UInt8> UInt8Array;
00521 typedef Array<Int8> Int8Array;
00522 typedef Array<UInt16> UInt16Array;
00523 typedef Array<Int16> Int16Array;
00524 typedef Array<UInt32> UInt32Array;
00525 typedef Array<Int32> Int32Array;
00526 typedef Array<UInt64> UInt64Array;
00527 typedef Array<Int64> Int64Array;
00528 typedef Array<Real64> Real64Array;
00529 typedef Array<Real32> Real32Array;
00530
00531 }
00532
00533 #include "blocxx/ArrayImpl.hpp"
00534
00535 #endif
00536