1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSG_MIXIN_VECTOR
15#define OSG_MIXIN_VECTOR 1
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.
30 typedef typename std::vector<ValueT> vector_type;
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;
45 explicit MixinVector() : _impl()
49 explicit MixinVector(size_type initial_size, const value_type& fill_value = value_type())
50 : _impl(initial_size, fill_value)
54 template<class InputIterator>
55 MixinVector(InputIterator first, InputIterator last)
60 MixinVector(const vector_type& other)
65 MixinVector(const MixinVector& other)
70 MixinVector& operator=(const vector_type& other)
76 MixinVector& operator=(const MixinVector& other)
82 virtual ~MixinVector() {}
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); }
88 void swap(vector_type& other) { _impl.swap(other); }
89 void swap(MixinVector& other) { _impl.swap(other._impl); }
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(); }
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(); }
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(); }
107 const_reference operator[](size_type index) const { return _impl[index]; }
108 reference operator[](size_type index) { return _impl[index]; }
110 const_reference at(size_type index) const { return _impl.at(index); }
111 reference at(size_type index) { return _impl.at(index); }
113 void assign(size_type count, const value_type& value) { _impl.assign(count, value); }
115 void assign(Iter first, Iter last) { _impl.assign(first, last); }
117 void push_back(const value_type& value) { _impl.push_back(value); }
118 void pop_back() { _impl.pop_back(); }
120 iterator erase(iterator where) { return _impl.erase(where); }
121 iterator erase(iterator first, iterator last) { return _impl.erase(first, last); }
123 iterator insert(iterator where, const value_type& value) { return _impl.insert(where, value); }
125 template<class InputIterator>
126 void insert(iterator where, InputIterator first, InputIterator last)
128 _impl.insert(where, first, last);
131 void insert(iterator where, size_type count, const value_type& value)
133 _impl.insert(where, count, value);
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(); }
141 vector_type& asVector() { return _impl; }
142 const vector_type& asVector() const { return _impl; }
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; }
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; }
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; }
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; }
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; }
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; }
172template<class ValueT> inline
174swap(MixinVector<ValueT>& left,
175 MixinVector<ValueT>& right)
177 std::swap(left.asVector(), right.asVector());
180template<class ValueT> inline
182swap(MixinVector<ValueT>& left,
183 std::vector<ValueT>& right)
185 std::swap(left.asVector(), right);
188template<class ValueT> inline
190swap(std::vector<ValueT>& left,
191 MixinVector<ValueT>& right)
193 std::swap(left, right.asVector());