OW_Array.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #ifndef OW_ARRAY_HPP_INCLUDE_GUARD_
00037 #define OW_ARRAY_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_ArrayFwd.hpp"
00040 #include "OW_COWReference.hpp"
00041 #include "OW_Types.hpp"
00042 #include "OW_Exception.hpp"
00043 #include "OW_vector.hpp"
00044 
00045 namespace OW_NAMESPACE
00046 {
00047 
00048 OW_DECLARE_APIEXCEPTION(OutOfBounds, OW_COMMON_API);
00049 
00060 template<class T> class Array
00061 {
00062    typedef std::vector<T, std::allocator<T> > V;
00063 
00064 #ifdef OW_WIN32
00065 #pragma warning (push)
00066 #pragma warning (disable: 4251)
00067 #endif
00068 
00069    COWReference<V> m_impl;
00070 
00071 #ifdef OW_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 OW_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 } // end namespace OW_NAMESPACE
00176 
00177 #include "OW_ArrayImpl.hpp"
00178 
00179 #endif
00180    

Generated on Thu Feb 9 08:47:51 2006 for openwbem by  doxygen 1.4.6