root/OpenSceneGraph/trunk/include/osg/MixinVector @ 13041

Revision 13041, 7.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_MIXIN_VECTOR
15#define OSG_MIXIN_VECTOR 1
16
17#include <vector>
18
19namespace osg {
20
21/** MixinVector is a base class that allows inheritance to be used to easily
22 *  emulate derivation from std::vector but without introducing undefined
23 *  behaviour through violation of virtual destructor rules.
24 *
25 *  @author Neil Groves
26 */
27template<class ValueT>
28class MixinVector
29{
30    typedef typename std::vector<ValueT> vector_type;
31public:
32    typedef typename vector_type::allocator_type allocator_type;
33    typedef typename vector_type::value_type value_type;
34    typedef typename vector_type::const_pointer const_pointer;
35    typedef typename vector_type::pointer pointer;
36    typedef typename vector_type::const_reference const_reference;
37    typedef typename vector_type::reference reference;
38    typedef typename vector_type::const_iterator const_iterator;
39    typedef typename vector_type::iterator iterator;
40    typedef typename vector_type::const_reverse_iterator const_reverse_iterator;
41    typedef typename vector_type::reverse_iterator reverse_iterator;
42    typedef typename vector_type::size_type size_type;
43    typedef typename vector_type::difference_type difference_type;
44
45    explicit MixinVector() : _impl()
46    {
47    }
48
49    explicit MixinVector(size_type initial_size, const value_type& fill_value = value_type())
50    : _impl(initial_size, fill_value)
51    {
52    }
53
54    template<class InputIterator>
55    MixinVector(InputIterator first, InputIterator last)
56    : _impl(first, last)
57    {
58    }
59
60    MixinVector(const vector_type& other)
61    : _impl(other)
62    {
63    }
64
65    MixinVector(const MixinVector& other)
66    : _impl(other._impl)
67    {
68    }
69
70    MixinVector& operator=(const vector_type& other)
71    {
72        _impl = other;
73        return *this;
74    }
75
76    MixinVector& operator=(const MixinVector& other)
77    {
78        _impl = other._impl;
79        return *this;
80    }
81
82    virtual ~MixinVector() {}
83
84    void clear() { _impl.clear(); }
85    void resize(size_type new_size, const value_type& fill_value = value_type()) { _impl.resize(new_size, fill_value); }
86    void reserve(size_type new_capacity) { _impl.reserve(new_capacity); }
87
88    void swap(vector_type& other) { _impl.swap(other); }
89    void swap(MixinVector& other) { _impl.swap(other._impl); }
90
91    bool empty() const { return _impl.empty(); }
92    size_type size() const { return _impl.size(); }
93    size_type capacity() const { return _impl.capacity(); }
94    size_type max_size() const { return _impl.max_size(); }
95    allocator_type get_allocator() const { return _impl.get_allocator(); }
96
97    const_iterator begin() const { return _impl.begin(); }
98    iterator begin() { return _impl.begin(); }
99    const_iterator end() const { return _impl.end(); }
100    iterator end() { return _impl.end(); }
101
102    const_reverse_iterator rbegin() const { return _impl.rbegin(); }
103    reverse_iterator rbegin() { return _impl.rbegin(); }
104    const_reverse_iterator rend() const { return _impl.rend(); }
105    reverse_iterator rend() { return _impl.rend(); }
106
107    const_reference operator[](size_type index) const { return _impl[index]; }
108    reference operator[](size_type index) { return _impl[index]; }
109
110    const_reference at(size_type index) const { return _impl.at(index); }
111    reference at(size_type index) { return _impl.at(index); }
112
113    void assign(size_type count, const value_type& value) { _impl.assign(count, value); }
114    template<class Iter>
115    void assign(Iter first, Iter last) { _impl.assign(first, last); }
116
117    void push_back(const value_type& value) { _impl.push_back(value); }
118    void pop_back() { _impl.pop_back(); }
119
120    iterator erase(iterator where) { return _impl.erase(where); }
121    iterator erase(iterator first, iterator last) { return _impl.erase(first, last); }
122
123    iterator insert(iterator where, const value_type& value) { return _impl.insert(where, value); }
124
125    template<class InputIterator>
126    void insert(iterator where, InputIterator first, InputIterator last)
127    {
128        _impl.insert(where, first, last);
129    }
130
131    void insert(iterator where, size_type count, const value_type& value)
132    {
133        _impl.insert(where, count, value);
134    }
135
136    const_reference back() const { return _impl.back(); }
137    reference back() { return _impl.back(); }
138    const_reference front() const { return _impl.front(); }
139    reference front() { return _impl.front(); }
140
141    vector_type& asVector() { return _impl; }
142    const vector_type& asVector() const { return _impl; }
143
144    friend inline bool operator==(const MixinVector<ValueT>& left, const MixinVector<ValueT>& right) { return left._impl == right._impl; }
145    friend inline bool operator==(const MixinVector<ValueT>& left, const std::vector<ValueT>& right) { return left._impl == right; }
146    friend inline bool operator==(const std::vector<ValueT>& left, const MixinVector<ValueT>& right) { return left == right._impl; }
147
148    friend inline bool operator!=(const MixinVector<ValueT>& left, const MixinVector<ValueT>& right) { return left._impl != right._impl; }
149    friend inline bool operator!=(const MixinVector<ValueT>& left, const std::vector<ValueT>& right) { return left._impl != right; }
150    friend inline bool operator!=(const std::vector<ValueT>& left, const MixinVector<ValueT>& right) { return left != right._impl; }
151
152    friend inline bool operator<(const MixinVector<ValueT>& left, const MixinVector<ValueT>& right) { return left._impl < right._impl; }
153    friend inline bool operator<(const MixinVector<ValueT>& left, const std::vector<ValueT>& right) { return left._impl < right; }
154    friend inline bool operator<(const std::vector<ValueT>& left, const MixinVector<ValueT>& right) { return left < right._impl; }
155
156    friend inline bool operator>(const MixinVector<ValueT>& left, const MixinVector<ValueT>& right) { return left._impl > right._impl; }
157    friend inline bool operator>(const MixinVector<ValueT>& left, const std::vector<ValueT>& right) { return left._impl > right; }
158    friend inline bool operator>(const std::vector<ValueT>& left, const MixinVector<ValueT>& right) { return left > right._impl; }
159
160    friend inline bool operator<=(const MixinVector<ValueT>& left, const MixinVector<ValueT>& right) { return left._impl <= right._impl; }
161    friend inline bool operator<=(const MixinVector<ValueT>& left, const std::vector<ValueT>& right) { return left._impl <= right; }
162    friend inline bool operator<=(const std::vector<ValueT>& left, const MixinVector<ValueT>& right) { return left <= right._impl; }
163
164    friend inline bool operator>=(const MixinVector<ValueT>& left, const MixinVector<ValueT>& right) { return left._impl >= right._impl; }
165    friend inline bool operator>=(const MixinVector<ValueT>& left, const std::vector<ValueT>& right) { return left._impl >= right; }
166    friend inline bool operator>=(const std::vector<ValueT>& left, const MixinVector<ValueT>& right) { return left >= right._impl; }
167
168private:
169    vector_type _impl;
170};
171
172template<class ValueT> inline
173void
174swap(MixinVector<ValueT>& left,
175     MixinVector<ValueT>& right)
176{
177    std::swap(left.asVector(), right.asVector());
178}
179
180template<class ValueT> inline
181void
182swap(MixinVector<ValueT>& left,
183     std::vector<ValueT>& right)
184{
185    std::swap(left.asVector(), right);
186}
187
188template<class ValueT> inline
189void
190swap(std::vector<ValueT>& left,
191     MixinVector<ValueT>& right)
192{
193    std::swap(left, right.asVector());
194}
195
196} // namespace osg
197
198#endif
199
Note: See TracBrowser for help on using the browser.