Array.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2005 Novell, Inc. All rights reserved.
00004 *
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 *
00008 *  - Redistributions of source code must retain the above copyright notice,
00009 *    this list of conditions and the following disclaimer.
00010 *
00011 *  - Redistributions in binary form must reproduce the above copyright notice,
00012 *    this list of conditions and the following disclaimer in the documentation
00013 *    and/or other materials provided with the distribution.
00014 *
00015 *  - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
00016 *    contributors may be used to endorse or promote products derived from this
00017 *    software without specific prior written permission.
00018 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 
00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 // Declare the OutOfBoundsException
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 } // end namespace BLOCXX_NAMESPACE
00530 
00531 #include "blocxx/ArrayImpl.hpp"
00532 
00533 #endif
00534    

Generated on Fri Jun 16 15:39:08 2006 for blocxx by  doxygen 1.4.6