OW_List.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_LIST_HPP_INCLUDE_GUARD_
00037 #define OW_LIST_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_COWReference.hpp"
00040 #include <list>
00041 
00042 namespace OW_NAMESPACE
00043 {
00044 
00045 // forward declarations are necessary for template friends.
00046 template<class T> class List;
00047 
00048 template <class T>
00049 inline bool operator==(const List<T>& x, const List<T>& y);
00050 
00051 template <class T>
00052 inline bool operator<(const List<T>& x, const List<T>& y);
00053 
00054    
00058 template<class T> class List
00059 {
00060 private:
00061    typedef std::list<T> L;
00062    COWReference<L> m_impl;
00063 public:
00064    typedef typename L::value_type value_type;
00065    typedef typename L::pointer pointer;
00066    typedef typename L::const_pointer const_pointer;
00067    typedef typename L::reference reference;
00068    typedef typename L::const_reference const_reference;
00069    typedef typename L::size_type size_type;
00070    typedef typename L::difference_type difference_type;
00071    typedef typename L::iterator iterator;
00072    typedef typename L::const_iterator const_iterator;
00073    typedef typename L::reverse_iterator reverse_iterator;
00074    typedef typename L::const_reverse_iterator const_reverse_iterator;
00075    List() : m_impl(new L) {}
00076    explicit List(L* toWrap) : m_impl(toWrap)
00077    {  }
00078    template<class InputIterator>
00079    List(InputIterator first, InputIterator last) : m_impl(new L(first, last))
00080    {
00081    }
00082    List(size_type n, const T& value) : m_impl(new L(n, value))
00083    {
00084    }
00085    List(int n, const T& value) : m_impl(new L(n, value))
00086    {
00087    }
00088    List(long n, const T& value) : m_impl(new L(n, value))
00089    {
00090    }
00091    explicit List(size_type n) : m_impl(new L(n))
00092    {
00093    }
00094    L* getImpl()
00095    {
00096       return &*m_impl;
00097    }
00098    iterator begin()
00099    {
00100       return m_impl->begin();
00101    }
00102    const_iterator begin() const
00103    {
00104       return m_impl->begin();
00105    }
00106    iterator end()
00107    {
00108       return m_impl->end();
00109    }
00110    const_iterator end() const
00111    {
00112       return m_impl->end();
00113    }
00114    reverse_iterator rbegin()
00115    {
00116       return m_impl->rbegin();
00117    }
00118    const_reverse_iterator rbegin() const
00119    {
00120       return m_impl->rbegin();
00121    }
00122    reverse_iterator rend()
00123    {
00124       return m_impl->rend();
00125    }
00126    const_reverse_iterator rend() const
00127    {
00128       return m_impl->rend();
00129    }
00130    bool empty() const
00131    {
00132       return m_impl->empty();
00133    }
00134    size_type size() const
00135    {
00136       return m_impl->size();
00137    }
00138    size_type max_size() const
00139    {
00140       return m_impl->max_size();
00141    }
00142    reference front()
00143    {
00144       return m_impl->front();
00145    }
00146    const_reference front() const
00147    {
00148       return m_impl->front();
00149    }
00150    reference back()
00151    {
00152       return m_impl->back();
00153    }
00154    const_reference back() const
00155    {
00156       return m_impl->back();
00157    }
00158    void swap(List<T>& x)
00159    {
00160       m_impl.swap(x.m_impl);
00161    }
00162    iterator insert(iterator position, const T& x)
00163    {
00164       return m_impl->insert(position, x);
00165    }
00166    iterator insert(iterator position)
00167    {
00168       return m_impl->insert(position);
00169    }
00170    template<class InputIterator>
00171    void insert(iterator position, InputIterator first, InputIterator last)
00172    {
00173       m_impl->insert(position, first, last);
00174    }
00175    void insert(iterator pos, size_type n, const T& x)
00176    {
00177       m_impl->insert(pos, n, x);
00178    }
00179    void insert(iterator pos, int n, const T& x)
00180    {
00181       m_impl->insert(pos, n, x);
00182    }
00183    void insert(iterator pos, long n, const T& x)
00184    {
00185       m_impl->insert(pos, n, x);
00186    }
00187    void push_front(const T& x)
00188    {
00189       m_impl->push_front(x);
00190    }
00191    void push_back(const T& x)
00192    {
00193       m_impl->push_back(x);
00194    }
00195    iterator erase(iterator position)
00196    {
00197       return m_impl->erase(position);
00198    }
00199    iterator erase(iterator first, iterator last)
00200    {
00201       return m_impl->erase(first, last);
00202    }
00203    void resize(size_type new_size, const T& x)
00204    {
00205       m_impl->resize(new_size, x);
00206    }
00207    void resize(size_type new_size)
00208    {
00209       m_impl->resize(new_size);
00210    }
00211    void clear()
00212    {
00213       m_impl->clear();
00214    }
00215    void pop_front()
00216    {
00217       m_impl->pop_front();
00218    }
00219    void pop_back()
00220    {
00221       m_impl->pop_back();
00222    }
00223    void splice(iterator position, List& x)
00224    {
00225       m_impl->splice(position, *x.m_impl);
00226    }
00227    void splice(iterator position, List& x, iterator i)
00228    {
00229       m_impl->splice(position, *x.m_impl, i);
00230    }
00231    void splice(iterator position, List& x, iterator first, iterator last)
00232    {
00233       m_impl->splice(position, *x.m_impl, first, last);
00234    }
00235    void remove(const T& value)
00236    {
00237       m_impl->remove(value);
00238    }
00239    void unique()
00240    {
00241       m_impl->unique();
00242    }
00243    void merge(List& x)
00244    {
00245       m_impl->merge(*x.m_impl);
00246    }
00247    void reverse()
00248    {
00249       m_impl->reverse();
00250    }
00251    void sort()
00252    {
00253       m_impl->sort();
00254    }
00255    template<class Predicate> void remove_if (Predicate p)
00256    {
00257       m_impl->remove_if (p);
00258    }
00259    template<class BinaryPredicate> void unique(BinaryPredicate bp)
00260    {
00261       m_impl->unique(bp);
00262    }
00263    template<class StrictWeakOrdering> void merge(List& x, StrictWeakOrdering swo)
00264    {
00265       m_impl->merge(*x.m_impl, swo);
00266    }
00267    template<class StrictWeakOrdering> void
00268       sort(StrictWeakOrdering swo)
00269    {
00270       m_impl->sort(swo);
00271    }
00272    friend bool operator== <>(const List<T>& x,
00273       const List<T>& y);
00274    friend bool operator< <>(const List<T>& x,
00275       const List<T>& y);
00276 };
00277 template <class T>
00278 inline bool operator==(const List<T>& x, const List<T>& y)
00279 {
00280    return *x.m_impl == *y.m_impl;
00281 }
00282 template <class T>
00283 inline bool operator<(const List<T>& x, const List<T>& y)
00284 {
00285    return *x.m_impl < *y.m_impl;
00286 }
00287 template <class T>
00288 inline void swap(List<T>& x, List<T>& y)
00289 {
00290    x.swap(y);
00291 }
00292 template <class T>
00293 std::list<T>* COWReferenceClone(std::list<T>* obj)
00294 {
00295    return new std::list<T>(*obj);
00296 }
00297 
00298 } // end namespace OW_NAMESPACE
00299 
00300 #endif

Generated on Thu Feb 9 08:48:03 2006 for openwbem by  doxygen 1.4.6