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 
00036 #ifndef OWBI1_ARRAY_HPP_INCLUDE_GUARD_
00037 #define OWBI1_ARRAY_HPP_INCLUDE_GUARD_
00038 #include "OWBI1_config.h"
00039 #include "OWBI1_ArrayFwd.hpp"
00040 #include "OWBI1_COWReference.hpp"
00041 #include "OWBI1_Types.hpp"
00042 #include "OWBI1_Exception.hpp"
00043 #include "OWBI1_vector.hpp"
00044 
00045 namespace OWBI1
00046 {
00047 
00048 OWBI1_DECLARE_APIEXCEPTION(OutOfBounds, OWBI1_COMMON_API);
00049 
00060 template<class T> class Array
00061 {
00062    typedef std::vector<T, std::allocator<T> > V;
00063 
00064 #ifdef OWBI1_WIN32
00065 #pragma warning (push)
00066 #pragma warning (disable: 4251)
00067 #endif
00068 
00069    COWReference<V> m_impl;
00070 
00071 #ifdef OWBI1_WIN32
00072 #pragma warning (pop)
00073 #endif
00074 
00075 public:
00076    typedef typename V::value_type value_type;
00077    typedef typename V::pointer pointer;
00078    typedef typename V::const_pointer const_pointer;
00079    typedef typename V::iterator iterator;
00080    typedef typename V::const_iterator const_iterator;
00081    typedef typename V::reference reference;
00082    typedef typename V::const_reference const_reference;
00083    typedef typename V::size_type size_type;
00084    typedef typename V::difference_type difference_type;
00085    typedef typename V::reverse_iterator reverse_iterator;
00086    typedef typename V::const_reverse_iterator const_reverse_iterator;
00087    Array();
00088    ~Array();
00089    explicit Array(V* toWrap);
00090    Array(size_type n, const T& value);
00091    Array(int n, const T& value);
00092    Array(long n, const T& value);
00093    explicit Array(size_type n);
00094    template<class InputIterator>
00095    Array(InputIterator first, InputIterator last);
00096    iterator begin();
00097    const_iterator begin() const;
00098    iterator end();
00099    const_iterator end() const;
00100    reverse_iterator rbegin();
00101    const_reverse_iterator rbegin() const;
00102    reverse_iterator rend();
00103    const_reverse_iterator rend() const;
00104    size_type size() const;
00105    size_type max_size() const;
00106    size_type capacity() const;
00107    bool empty() const;
00108    reference operator[](size_type n);
00109    const_reference operator[](size_type n) const;
00110    Array<T>& operator+= (const T& x);
00111    void reserve(size_type n);
00112    reference front();
00113    const_reference front() const;
00114    reference back();
00115    const_reference back() const;
00116    void push_back(const T& x);
00117    void append(const T& x);
00118    void swap(Array<T>& x);
00119    iterator insert(iterator position, const T& x);
00120    void insert(size_type position, const T& x);
00121    void remove(size_type index);
00122    void remove(size_type begin, size_type end);
00123    template<class InputIterator>
00124    void insert(iterator position, InputIterator first, InputIterator last);
00125    void appendArray(const Array<T>& x);
00126    void pop_back();
00127    iterator erase(iterator position);
00128    iterator erase(iterator first, iterator last);
00129    void resize(size_type new_size, const T& x);
00130    void resize(size_type new_size);
00131    void clear();
00132    friend bool operator== <>(const Array<T>& x, const Array<T>& y);
00133    friend bool operator< <>(const Array<T>& x, const Array<T>& y);
00134 private:
00135 #ifdef OWBI1_CHECK_ARRAY_INDEXING
00136    void checkValidIndex(size_type index) const;
00137 #endif
00138 };
00139 
00140 template <class T>
00141 inline bool operator != (const Array<T>& x, const Array<T>& y)
00142 {
00143    return !(x == y);
00144 }
00145 
00146 template <class T>
00147 inline bool operator <= (const Array<T>& x, const Array<T>& y)
00148 {
00149    return !(y < x);
00150 }
00151 
00152 template <class T>
00153 inline bool operator >= (const Array<T>& x, const Array<T>& y)
00154 {
00155    return !(x < y);
00156 }
00157 
00158 template <class T>
00159 inline bool operator > (const Array<T>& x, const Array<T>& y)
00160 {
00161    return y < x;
00162 }
00163   
00164 typedef Array<UInt8>      UInt8Array;
00165 typedef Array<Int8>       Int8Array;
00166 typedef Array<UInt16>     UInt16Array;
00167 typedef Array<Int16>      Int16Array;
00168 typedef Array<UInt32>     UInt32Array;
00169 typedef Array<Int32>      Int32Array;
00170 typedef Array<UInt64>     UInt64Array;
00171 typedef Array<Int64>      Int64Array;
00172 typedef Array<Real64>     Real64Array;
00173 typedef Array<Real32>     Real32Array;
00174 
00175 } 
00176 
00177 #include "OWBI1_ArrayImpl.hpp"
00178 
00179 #endif
00180