xref: /AOO42X/main/autodoc/inc/cosv/tpl/vvector.hxx (revision 9bce9b0d387299c68bd81d539e1478357a103de5)
1*8a106958SDamjan Jovanovic /**************************************************************
2*8a106958SDamjan Jovanovic  *
3*8a106958SDamjan Jovanovic  * Licensed to the Apache Software Foundation (ASF) under one
4*8a106958SDamjan Jovanovic  * or more contributor license agreements.  See the NOTICE file
5*8a106958SDamjan Jovanovic  * distributed with this work for additional information
6*8a106958SDamjan Jovanovic  * regarding copyright ownership.  The ASF licenses this file
7*8a106958SDamjan Jovanovic  * to you under the Apache License, Version 2.0 (the
8*8a106958SDamjan Jovanovic  * "License"); you may not use this file except in compliance
9*8a106958SDamjan Jovanovic  * with the License.  You may obtain a copy of the License at
10*8a106958SDamjan Jovanovic  *
11*8a106958SDamjan Jovanovic  *   http://www.apache.org/licenses/LICENSE-2.0
12*8a106958SDamjan Jovanovic  *
13*8a106958SDamjan Jovanovic  * Unless required by applicable law or agreed to in writing,
14*8a106958SDamjan Jovanovic  * software distributed under the License is distributed on an
15*8a106958SDamjan Jovanovic  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*8a106958SDamjan Jovanovic  * KIND, either express or implied.  See the License for the
17*8a106958SDamjan Jovanovic  * specific language governing permissions and limitations
18*8a106958SDamjan Jovanovic  * under the License.
19*8a106958SDamjan Jovanovic  *
20*8a106958SDamjan Jovanovic  *************************************************************/
21*8a106958SDamjan Jovanovic 
22*8a106958SDamjan Jovanovic 
23*8a106958SDamjan Jovanovic 
24*8a106958SDamjan Jovanovic #ifndef CSV_VVECTOR_HXX
25*8a106958SDamjan Jovanovic #define CSV_VVECTOR_HXX
26*8a106958SDamjan Jovanovic 
27*8a106958SDamjan Jovanovic #include <cstddef>      // for ptrdiff_t
28*8a106958SDamjan Jovanovic 
29*8a106958SDamjan Jovanovic // USED SERVICES
30*8a106958SDamjan Jovanovic #include <vector>
31*8a106958SDamjan Jovanovic #include <cosv/tpl/tpltools.hxx>
32*8a106958SDamjan Jovanovic 
33*8a106958SDamjan Jovanovic 
34*8a106958SDamjan Jovanovic 
35*8a106958SDamjan Jovanovic 
36*8a106958SDamjan Jovanovic namespace csv
37*8a106958SDamjan Jovanovic {
38*8a106958SDamjan Jovanovic namespace vvector
39*8a106958SDamjan Jovanovic {
40*8a106958SDamjan Jovanovic 
41*8a106958SDamjan Jovanovic 
42*8a106958SDamjan Jovanovic template <class TYPE>
43*8a106958SDamjan Jovanovic struct delete_ptrs
44*8a106958SDamjan Jovanovic {
Destructcsv::vvector::delete_ptrs45*8a106958SDamjan Jovanovic     static void         Destruct(
46*8a106958SDamjan Jovanovic                             std::vector< TYPE* > &
47*8a106958SDamjan Jovanovic                                                 v)
48*8a106958SDamjan Jovanovic                         { csv::erase_container_of_heap_ptrs(v); }
49*8a106958SDamjan Jovanovic 
50*8a106958SDamjan Jovanovic     /// @precond ->it is a valid iterator within v
Erasecsv::vvector::delete_ptrs51*8a106958SDamjan Jovanovic     static void         Erase(
52*8a106958SDamjan Jovanovic                             std::vector< TYPE* > &
53*8a106958SDamjan Jovanovic                                                 v,
54*8a106958SDamjan Jovanovic                             typename std::vector< TYPE* >::iterator
55*8a106958SDamjan Jovanovic                                                 it2erase )
56*8a106958SDamjan Jovanovic                         { delete *it2erase; v.erase(it2erase); }
57*8a106958SDamjan Jovanovic 
58*8a106958SDamjan Jovanovic     /// @precond ->v.size() > 0
PopBackcsv::vvector::delete_ptrs59*8a106958SDamjan Jovanovic     static void         PopBack(
60*8a106958SDamjan Jovanovic                             std::vector< TYPE* > &
61*8a106958SDamjan Jovanovic                                                 v )
62*8a106958SDamjan Jovanovic                         { delete v.back(); v.pop_back(); }
63*8a106958SDamjan Jovanovic 
64*8a106958SDamjan Jovanovic     /// @precond ->it is a valid iterator
ReplacePtrcsv::vvector::delete_ptrs65*8a106958SDamjan Jovanovic     static void         ReplacePtr(
66*8a106958SDamjan Jovanovic                             typename std::vector< TYPE* >::iterator
67*8a106958SDamjan Jovanovic                                                 it,
68*8a106958SDamjan Jovanovic                             DYN TYPE *          pass_new )
69*8a106958SDamjan Jovanovic                         { delete *it; *it = pass_new; }
70*8a106958SDamjan Jovanovic };
71*8a106958SDamjan Jovanovic 
72*8a106958SDamjan Jovanovic 
73*8a106958SDamjan Jovanovic /** One helper class for the ->csv::VirtualVector.
74*8a106958SDamjan Jovanovic     Implements a
75*8a106958SDamjan Jovanovic */
76*8a106958SDamjan Jovanovic template <class TYPE>
77*8a106958SDamjan Jovanovic struct keep_ptrs
78*8a106958SDamjan Jovanovic {
Destructcsv::vvector::keep_ptrs79*8a106958SDamjan Jovanovic     static void         Destruct(std::vector< TYPE* > & v)
80*8a106958SDamjan Jovanovic                         {}
81*8a106958SDamjan Jovanovic 
Erasecsv::vvector::keep_ptrs82*8a106958SDamjan Jovanovic     static void         Erase(
83*8a106958SDamjan Jovanovic                             std::vector< TYPE* > &
84*8a106958SDamjan Jovanovic                                                 v,
85*8a106958SDamjan Jovanovic                             typename std::vector< TYPE* >::iterator
86*8a106958SDamjan Jovanovic                                                 it2erase )
87*8a106958SDamjan Jovanovic                         { v.erase(it2erase); }
88*8a106958SDamjan Jovanovic 
PopBackcsv::vvector::keep_ptrs89*8a106958SDamjan Jovanovic     static void         PopBack(
90*8a106958SDamjan Jovanovic                             std::vector< TYPE* > &
91*8a106958SDamjan Jovanovic                                                 v )
92*8a106958SDamjan Jovanovic                         { v.pop_back(); }
93*8a106958SDamjan Jovanovic 
94*8a106958SDamjan Jovanovic     /// @precond ->it is a valid iterator
ReplacePtrcsv::vvector::keep_ptrs95*8a106958SDamjan Jovanovic     static void         ReplacePtr(
96*8a106958SDamjan Jovanovic                             typename std::vector< TYPE* >::iterator
97*8a106958SDamjan Jovanovic                                                 it,
98*8a106958SDamjan Jovanovic                             TYPE *              io_new )
99*8a106958SDamjan Jovanovic                         { *it = io_new; }
100*8a106958SDamjan Jovanovic };
101*8a106958SDamjan Jovanovic 
102*8a106958SDamjan Jovanovic 
103*8a106958SDamjan Jovanovic }   // namespace vvector
104*8a106958SDamjan Jovanovic 
105*8a106958SDamjan Jovanovic 
106*8a106958SDamjan Jovanovic 
107*8a106958SDamjan Jovanovic 
108*8a106958SDamjan Jovanovic /** Implements a vector of different implementations of a base
109*8a106958SDamjan Jovanovic     class.
110*8a106958SDamjan Jovanovic 
111*8a106958SDamjan Jovanovic     Implementation has to be by pointers to get the polymorphic
112*8a106958SDamjan Jovanovic     behaviour, however access is by references to the base class.
113*8a106958SDamjan Jovanovic 
114*8a106958SDamjan Jovanovic     @tpl XX
115*8a106958SDamjan Jovanovic     The common base class of vector elements.
116*8a106958SDamjan Jovanovic 
117*8a106958SDamjan Jovanovic     @tpl PTRDEL
118*8a106958SDamjan Jovanovic     Has two possible values:
119*8a106958SDamjan Jovanovic         vvector::delete_ptrs<XX>    Elements have to be on the heap and
120*8a106958SDamjan Jovanovic                                     are deleted when removed (default).
121*8a106958SDamjan Jovanovic         vvector::keep_ptrs<XX>      Elements are only referenced and not
122*8a106958SDamjan Jovanovic                                     deleted when removed.
123*8a106958SDamjan Jovanovic 
124*8a106958SDamjan Jovanovic */
125*8a106958SDamjan Jovanovic template <class XX, class PTRDEL = vvector::delete_ptrs<XX> >
126*8a106958SDamjan Jovanovic class VirtualVector
127*8a106958SDamjan Jovanovic {
128*8a106958SDamjan Jovanovic   public:
129*8a106958SDamjan Jovanovic     typedef VirtualVector<XX,PTRDEL>            self;
130*8a106958SDamjan Jovanovic     typedef std::vector< DYN XX* >              impl_type;
131*8a106958SDamjan Jovanovic     typedef typename impl_type::size_type       size_type;
132*8a106958SDamjan Jovanovic     typedef ptrdiff_t                           difference_type;
133*8a106958SDamjan Jovanovic 
134*8a106958SDamjan Jovanovic     class const_iterator;
135*8a106958SDamjan Jovanovic     class iterator;
136*8a106958SDamjan Jovanovic 
137*8a106958SDamjan Jovanovic     // LIFECYCLE
138*8a106958SDamjan Jovanovic                         VirtualVector();
139*8a106958SDamjan Jovanovic     explicit            VirtualVector(
140*8a106958SDamjan Jovanovic                             int                 i_size );
141*8a106958SDamjan Jovanovic                         ~VirtualVector();
142*8a106958SDamjan Jovanovic 
143*8a106958SDamjan Jovanovic     // OPERATORS
144*8a106958SDamjan Jovanovic     const XX &          operator[](
145*8a106958SDamjan Jovanovic                             size_type           i_pos ) const;
146*8a106958SDamjan Jovanovic     XX &                operator[](
147*8a106958SDamjan Jovanovic                             size_type           i_pos );
148*8a106958SDamjan Jovanovic 
149*8a106958SDamjan Jovanovic     // OPERATIONS
150*8a106958SDamjan Jovanovic     void                push_back(
151*8a106958SDamjan Jovanovic                             DYN XX &            i_drElement );
152*8a106958SDamjan Jovanovic     void                pop_back();
153*8a106958SDamjan Jovanovic 
154*8a106958SDamjan Jovanovic     iterator            insert(
155*8a106958SDamjan Jovanovic                             iterator            i_pos,
156*8a106958SDamjan Jovanovic                             DYN XX &            i_drElement );
157*8a106958SDamjan Jovanovic     void                erase(
158*8a106958SDamjan Jovanovic                             iterator            i_pos );
159*8a106958SDamjan Jovanovic     void                replace(
160*8a106958SDamjan Jovanovic                             iterator            i_pos,
161*8a106958SDamjan Jovanovic                             DYN XX &            i_drElement );
162*8a106958SDamjan Jovanovic     void                reserve(
163*8a106958SDamjan Jovanovic                             size_type           i_size );
164*8a106958SDamjan Jovanovic 
165*8a106958SDamjan Jovanovic     // INQUIRY
166*8a106958SDamjan Jovanovic     bool                empty() const;
167*8a106958SDamjan Jovanovic     size_t              size() const;
168*8a106958SDamjan Jovanovic     const_iterator      begin() const;
169*8a106958SDamjan Jovanovic     const_iterator      end() const;
170*8a106958SDamjan Jovanovic     const XX &          front() const;
171*8a106958SDamjan Jovanovic     const XX &          back() const;
172*8a106958SDamjan Jovanovic 
173*8a106958SDamjan Jovanovic     // ACCESS
174*8a106958SDamjan Jovanovic     iterator            begin();
175*8a106958SDamjan Jovanovic     iterator            end();
176*8a106958SDamjan Jovanovic     XX &                front();
177*8a106958SDamjan Jovanovic     XX &                back();
178*8a106958SDamjan Jovanovic 
179*8a106958SDamjan Jovanovic   private:
180*8a106958SDamjan Jovanovic     // Forbidden:
181*8a106958SDamjan Jovanovic                         VirtualVector(const VirtualVector&);
182*8a106958SDamjan Jovanovic     VirtualVector &     operator=(const VirtualVector&);
183*8a106958SDamjan Jovanovic 
184*8a106958SDamjan Jovanovic     // DATA
185*8a106958SDamjan Jovanovic     std::vector< DYN XX* >
186*8a106958SDamjan Jovanovic                         aData;
187*8a106958SDamjan Jovanovic };
188*8a106958SDamjan Jovanovic 
189*8a106958SDamjan Jovanovic 
190*8a106958SDamjan Jovanovic 
191*8a106958SDamjan Jovanovic 
192*8a106958SDamjan Jovanovic /** Should be usable for all STL algorithms.
193*8a106958SDamjan Jovanovic     Implements the Random Access Iterator concept.
194*8a106958SDamjan Jovanovic */
195*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
196*8a106958SDamjan Jovanovic class VirtualVector<XX,PTRDEL>::
197*8a106958SDamjan Jovanovic       const_iterator
198*8a106958SDamjan Jovanovic 
199*8a106958SDamjan Jovanovic             // This derivation provides type information for the STL
200*8a106958SDamjan Jovanovic             // It introduces the types "value_type" and "difference_type".
201*8a106958SDamjan Jovanovic             : public std::iterator<std::random_access_iterator_tag,
202*8a106958SDamjan Jovanovic                         const XX>
203*8a106958SDamjan Jovanovic {
204*8a106958SDamjan Jovanovic   public:
205*8a106958SDamjan Jovanovic     typedef VirtualVector<XX,PTRDEL>                            my_container;
206*8a106958SDamjan Jovanovic     typedef typename my_container::impl_type::const_iterator    impl_iterator;
207*8a106958SDamjan Jovanovic 
208*8a106958SDamjan Jovanovic     // LIFECYCLE
const_iterator(impl_iterator i_implIter)209*8a106958SDamjan Jovanovic                         const_iterator(
210*8a106958SDamjan Jovanovic                             impl_iterator       i_implIter )
211*8a106958SDamjan Jovanovic                             : itImpl(i_implIter) {}
212*8a106958SDamjan Jovanovic 
213*8a106958SDamjan Jovanovic 
214*8a106958SDamjan Jovanovic     ///////////      STL ITERATOR CONCEPT IMPLEMENTATION        //////////////
215*8a106958SDamjan Jovanovic 
216*8a106958SDamjan Jovanovic     // Default Constructible functions:
const_iterator()217*8a106958SDamjan Jovanovic                         const_iterator()
218*8a106958SDamjan Jovanovic                             : itImpl() {}
219*8a106958SDamjan Jovanovic 
220*8a106958SDamjan Jovanovic     // Assignable functions:
221*8a106958SDamjan Jovanovic         // Assignment and copy constructor use the compiler generated versions.
222*8a106958SDamjan Jovanovic 
223*8a106958SDamjan Jovanovic     // Equality Comparable functions:
operator ==(const_iterator i_other) const224*8a106958SDamjan Jovanovic     bool                operator==(
225*8a106958SDamjan Jovanovic                             const_iterator      i_other ) const
226*8a106958SDamjan Jovanovic                             { return itImpl == i_other.itImpl; }
operator !=(const_iterator i_other) const227*8a106958SDamjan Jovanovic     bool                operator!=(
228*8a106958SDamjan Jovanovic                             const_iterator      i_other ) const
229*8a106958SDamjan Jovanovic                             { return itImpl != i_other.itImpl; }
230*8a106958SDamjan Jovanovic 
231*8a106958SDamjan Jovanovic     // Trivial Iterator functions:
operator *() const232*8a106958SDamjan Jovanovic     const XX &          operator*() const
233*8a106958SDamjan Jovanovic                             { return *(*itImpl); }
234*8a106958SDamjan Jovanovic 
235*8a106958SDamjan Jovanovic     // Input Iterator functions:
operator ++()236*8a106958SDamjan Jovanovic     const_iterator &    operator++()
237*8a106958SDamjan Jovanovic                             { ++itImpl; return *this; }
operator ++(int)238*8a106958SDamjan Jovanovic     const_iterator      operator++(int)
239*8a106958SDamjan Jovanovic                             { return const_iterator(itImpl++); }
240*8a106958SDamjan Jovanovic 
241*8a106958SDamjan Jovanovic     // Bidirectional Iterator functions:
operator --()242*8a106958SDamjan Jovanovic     const_iterator &    operator--()
243*8a106958SDamjan Jovanovic                             { --itImpl; return *this; }
operator --(int)244*8a106958SDamjan Jovanovic     const_iterator      operator--(int)
245*8a106958SDamjan Jovanovic                             { return const_iterator(itImpl--); }
246*8a106958SDamjan Jovanovic 
247*8a106958SDamjan Jovanovic     // Less Than Comparable functions:
operator <(const_iterator i_other) const248*8a106958SDamjan Jovanovic     bool                operator<(
249*8a106958SDamjan Jovanovic                             const_iterator      i_other ) const
250*8a106958SDamjan Jovanovic                             { return itImpl < i_other.itImpl; }
251*8a106958SDamjan Jovanovic 
252*8a106958SDamjan Jovanovic     // Random Access Iterator functions:
operator +=(difference_type i_diff)253*8a106958SDamjan Jovanovic     const_iterator &    operator+=(
254*8a106958SDamjan Jovanovic                             difference_type     i_diff )
255*8a106958SDamjan Jovanovic                             { itImpl += i_diff; return *this; }
operator +(difference_type i_diff) const256*8a106958SDamjan Jovanovic     const_iterator      operator+(
257*8a106958SDamjan Jovanovic                             difference_type     i_diff ) const
258*8a106958SDamjan Jovanovic                             { const_iterator ret(itImpl);
259*8a106958SDamjan Jovanovic                               return ret += i_diff; }
operator -=(difference_type i_diff)260*8a106958SDamjan Jovanovic     const_iterator &    operator-=(
261*8a106958SDamjan Jovanovic                             difference_type     i_diff )
262*8a106958SDamjan Jovanovic                             { itImpl -= i_diff;  return *this; }
operator -(difference_type i_diff) const263*8a106958SDamjan Jovanovic     const_iterator      operator-(
264*8a106958SDamjan Jovanovic                             difference_type     i_diff ) const
265*8a106958SDamjan Jovanovic                             { const_iterator ret(itImpl);
266*8a106958SDamjan Jovanovic                               return ret -= i_diff; }
operator -(const_iterator i_it) const267*8a106958SDamjan Jovanovic     difference_type     operator-(
268*8a106958SDamjan Jovanovic                             const_iterator      i_it ) const
269*8a106958SDamjan Jovanovic                             { return itImpl - i_it.itImpl; }
operator [](difference_type i_index)270*8a106958SDamjan Jovanovic     const XX &          operator[](
271*8a106958SDamjan Jovanovic                             difference_type     i_index )
272*8a106958SDamjan Jovanovic                             { return *(*itImpl[i_index]); }
273*8a106958SDamjan Jovanovic 
274*8a106958SDamjan Jovanovic     //////////////////////////////////////////////////////////////////////////
275*8a106958SDamjan Jovanovic 
276*8a106958SDamjan Jovanovic   private:
277*8a106958SDamjan Jovanovic     friend class VirtualVector<XX,PTRDEL>;
ImplValue() const278*8a106958SDamjan Jovanovic     impl_iterator       ImplValue() const       { return itImpl; }
279*8a106958SDamjan Jovanovic 
280*8a106958SDamjan Jovanovic     // DATA
281*8a106958SDamjan Jovanovic     impl_iterator       itImpl;
282*8a106958SDamjan Jovanovic };
283*8a106958SDamjan Jovanovic 
284*8a106958SDamjan Jovanovic 
285*8a106958SDamjan Jovanovic 
286*8a106958SDamjan Jovanovic 
287*8a106958SDamjan Jovanovic /** Should be usable for all STL algorithms.
288*8a106958SDamjan Jovanovic     Implements the Random Access Iterator concept.
289*8a106958SDamjan Jovanovic */
290*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
291*8a106958SDamjan Jovanovic class VirtualVector<XX,PTRDEL>::
292*8a106958SDamjan Jovanovic       iterator
293*8a106958SDamjan Jovanovic 
294*8a106958SDamjan Jovanovic             // This derivation provides type information for the STL
295*8a106958SDamjan Jovanovic             // It introduces the types "value_type" and "difference_type".
296*8a106958SDamjan Jovanovic             : public std::iterator<std::random_access_iterator_tag,
297*8a106958SDamjan Jovanovic                         XX>
298*8a106958SDamjan Jovanovic {
299*8a106958SDamjan Jovanovic   public:
300*8a106958SDamjan Jovanovic     typedef VirtualVector<XX,PTRDEL>                            my_container;
301*8a106958SDamjan Jovanovic     typedef typename my_container::impl_type::iterator          impl_iterator;
302*8a106958SDamjan Jovanovic 
303*8a106958SDamjan Jovanovic     // LIFECYCLE
iterator(impl_iterator i_implIter)304*8a106958SDamjan Jovanovic                         iterator(
305*8a106958SDamjan Jovanovic                             impl_iterator       i_implIter )
306*8a106958SDamjan Jovanovic                             : itImpl(i_implIter) {}
307*8a106958SDamjan Jovanovic 
308*8a106958SDamjan Jovanovic 
309*8a106958SDamjan Jovanovic     ///////////      STL ITERATOR CONCEPT IMPLEMENTATION        //////////////
310*8a106958SDamjan Jovanovic 
311*8a106958SDamjan Jovanovic     // Default Constructible functions:
iterator()312*8a106958SDamjan Jovanovic                         iterator()
313*8a106958SDamjan Jovanovic                             : itImpl() {}
314*8a106958SDamjan Jovanovic 
315*8a106958SDamjan Jovanovic     // Assignable functions:
316*8a106958SDamjan Jovanovic         // Assignment and copy constructor use the compiler generated versions.
317*8a106958SDamjan Jovanovic 
318*8a106958SDamjan Jovanovic     // Equality Comparable functions:
operator ==(iterator i_other) const319*8a106958SDamjan Jovanovic     bool                operator==(
320*8a106958SDamjan Jovanovic                             iterator            i_other ) const
321*8a106958SDamjan Jovanovic                             { return itImpl == i_other.itImpl; }
operator !=(iterator i_other) const322*8a106958SDamjan Jovanovic     bool                operator!=(
323*8a106958SDamjan Jovanovic                             iterator            i_other ) const
324*8a106958SDamjan Jovanovic                             { return itImpl != i_other.itImpl; }
325*8a106958SDamjan Jovanovic 
326*8a106958SDamjan Jovanovic     // Trivial Iterator functions:
operator *() const327*8a106958SDamjan Jovanovic     XX &                operator*() const
328*8a106958SDamjan Jovanovic                             { return *(*itImpl); }
329*8a106958SDamjan Jovanovic 
330*8a106958SDamjan Jovanovic     // Input Iterator functions:
operator ++()331*8a106958SDamjan Jovanovic     iterator &          operator++()
332*8a106958SDamjan Jovanovic                             { ++itImpl; return *this; }
operator ++(int)333*8a106958SDamjan Jovanovic     iterator            operator++(int)
334*8a106958SDamjan Jovanovic                             { return iterator(itImpl++); }
335*8a106958SDamjan Jovanovic 
336*8a106958SDamjan Jovanovic     // Bidirectional Iterator functions:
operator --()337*8a106958SDamjan Jovanovic     iterator &          operator--()
338*8a106958SDamjan Jovanovic                             { --itImpl; return *this; }
operator --(int)339*8a106958SDamjan Jovanovic     iterator            operator--(int)
340*8a106958SDamjan Jovanovic                             { return iterator(itImpl--); }
341*8a106958SDamjan Jovanovic 
342*8a106958SDamjan Jovanovic     // Less Than Comparable functions:
operator <(iterator i_other) const343*8a106958SDamjan Jovanovic     bool                operator<(
344*8a106958SDamjan Jovanovic                             iterator            i_other ) const
345*8a106958SDamjan Jovanovic                             { return itImpl < i_other.itImpl; }
346*8a106958SDamjan Jovanovic 
347*8a106958SDamjan Jovanovic     // Random Access Iterator functions:
operator +=(difference_type i_diff)348*8a106958SDamjan Jovanovic     iterator &          operator+=(
349*8a106958SDamjan Jovanovic                             difference_type     i_diff )
350*8a106958SDamjan Jovanovic                             { itImpl += i_diff; return *this;  }
operator +(difference_type i_diff) const351*8a106958SDamjan Jovanovic     iterator            operator+(
352*8a106958SDamjan Jovanovic                             difference_type     i_diff ) const
353*8a106958SDamjan Jovanovic                             { iterator ret(itImpl);
354*8a106958SDamjan Jovanovic                               return ret += i_diff; }
operator -=(difference_type i_diff)355*8a106958SDamjan Jovanovic     iterator &          operator-=(
356*8a106958SDamjan Jovanovic                             difference_type     i_diff )
357*8a106958SDamjan Jovanovic                             { itImpl -= i_diff; return *this;  }
operator -(difference_type i_diff) const358*8a106958SDamjan Jovanovic     iterator            operator-(
359*8a106958SDamjan Jovanovic                             difference_type     i_diff ) const
360*8a106958SDamjan Jovanovic                             { iterator ret(itImpl);
361*8a106958SDamjan Jovanovic                               return ret -= i_diff; }
operator -(iterator i_it) const362*8a106958SDamjan Jovanovic     difference_type     operator-(
363*8a106958SDamjan Jovanovic                             iterator            i_it ) const
364*8a106958SDamjan Jovanovic                             { return itImpl - i_it.itImpl; }
operator [](difference_type i_index)365*8a106958SDamjan Jovanovic     XX &                operator[](
366*8a106958SDamjan Jovanovic                             difference_type     i_index )
367*8a106958SDamjan Jovanovic                             { return *(*itImpl[i_index]); }
368*8a106958SDamjan Jovanovic 
369*8a106958SDamjan Jovanovic     //////////////////////////////////////////////////////////////////////////
370*8a106958SDamjan Jovanovic 
371*8a106958SDamjan Jovanovic   private:
372*8a106958SDamjan Jovanovic     friend class VirtualVector<XX,PTRDEL>;
ImplValue() const373*8a106958SDamjan Jovanovic     impl_iterator       ImplValue() const       { return itImpl; }
374*8a106958SDamjan Jovanovic 
375*8a106958SDamjan Jovanovic     // DATA
376*8a106958SDamjan Jovanovic     impl_iterator       itImpl;
377*8a106958SDamjan Jovanovic };
378*8a106958SDamjan Jovanovic 
379*8a106958SDamjan Jovanovic 
380*8a106958SDamjan Jovanovic 
381*8a106958SDamjan Jovanovic 
382*8a106958SDamjan Jovanovic // IMPLEMENTATION
383*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
384*8a106958SDamjan Jovanovic inline
VirtualVector()385*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::VirtualVector()
386*8a106958SDamjan Jovanovic     :   aData()
387*8a106958SDamjan Jovanovic {
388*8a106958SDamjan Jovanovic }
389*8a106958SDamjan Jovanovic 
390*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
391*8a106958SDamjan Jovanovic inline
VirtualVector(int i_size)392*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::VirtualVector(int i_size)
393*8a106958SDamjan Jovanovic     :   aData(i_size, 0)
394*8a106958SDamjan Jovanovic {
395*8a106958SDamjan Jovanovic }
396*8a106958SDamjan Jovanovic 
397*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
398*8a106958SDamjan Jovanovic inline
~VirtualVector()399*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::~VirtualVector()
400*8a106958SDamjan Jovanovic {
401*8a106958SDamjan Jovanovic     PTRDEL::Destruct(aData);
402*8a106958SDamjan Jovanovic }
403*8a106958SDamjan Jovanovic 
404*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
405*8a106958SDamjan Jovanovic inline const XX &
operator [](size_type i_pos) const406*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::operator[]( size_type i_pos ) const
407*8a106958SDamjan Jovanovic {
408*8a106958SDamjan Jovanovic     return *aData[i_pos];
409*8a106958SDamjan Jovanovic }
410*8a106958SDamjan Jovanovic 
411*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
412*8a106958SDamjan Jovanovic inline XX &
operator [](size_type i_pos)413*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::operator[]( size_type i_pos )
414*8a106958SDamjan Jovanovic {
415*8a106958SDamjan Jovanovic     return *aData[i_pos];
416*8a106958SDamjan Jovanovic }
417*8a106958SDamjan Jovanovic 
418*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
419*8a106958SDamjan Jovanovic inline void
push_back(DYN XX & i_drElement)420*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::push_back( DYN XX & i_drElement )
421*8a106958SDamjan Jovanovic {
422*8a106958SDamjan Jovanovic     aData.push_back(&i_drElement);
423*8a106958SDamjan Jovanovic }
424*8a106958SDamjan Jovanovic 
425*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
426*8a106958SDamjan Jovanovic inline void
pop_back()427*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::pop_back()
428*8a106958SDamjan Jovanovic {
429*8a106958SDamjan Jovanovic     if (NOT aData.empty())
430*8a106958SDamjan Jovanovic         PTRDEL::PopBack(aData);
431*8a106958SDamjan Jovanovic }
432*8a106958SDamjan Jovanovic 
433*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
434*8a106958SDamjan Jovanovic inline typename VirtualVector<XX,PTRDEL>::iterator
insert(iterator i_pos,DYN XX & i_drElement)435*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::insert( iterator            i_pos,
436*8a106958SDamjan Jovanovic                                   DYN XX &            i_drElement )
437*8a106958SDamjan Jovanovic {
438*8a106958SDamjan Jovanovic     return iterator(aData.insert(i_pos.ImplValue(), &i_drElement));
439*8a106958SDamjan Jovanovic }
440*8a106958SDamjan Jovanovic 
441*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
442*8a106958SDamjan Jovanovic inline void
erase(iterator i_pos)443*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::erase( iterator i_pos )
444*8a106958SDamjan Jovanovic {
445*8a106958SDamjan Jovanovic     PTRDEL::Erase(aData, i_pos.ImplValue());
446*8a106958SDamjan Jovanovic }
447*8a106958SDamjan Jovanovic 
448*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
449*8a106958SDamjan Jovanovic inline void
replace(iterator i_pos,DYN XX & i_drElement)450*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::replace( iterator     i_pos,
451*8a106958SDamjan Jovanovic                                    DYN XX &     i_drElement )
452*8a106958SDamjan Jovanovic {
453*8a106958SDamjan Jovanovic     PTRDEL::ReplacePtr(*i_pos, &i_drElement);
454*8a106958SDamjan Jovanovic }
455*8a106958SDamjan Jovanovic 
456*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
457*8a106958SDamjan Jovanovic inline void
reserve(size_type i_size)458*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::reserve( size_type i_size )
459*8a106958SDamjan Jovanovic {
460*8a106958SDamjan Jovanovic     aData.reserve(i_size);
461*8a106958SDamjan Jovanovic }
462*8a106958SDamjan Jovanovic 
463*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
464*8a106958SDamjan Jovanovic inline bool
empty() const465*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::empty() const
466*8a106958SDamjan Jovanovic {
467*8a106958SDamjan Jovanovic     return aData.empty();
468*8a106958SDamjan Jovanovic }
469*8a106958SDamjan Jovanovic 
470*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
471*8a106958SDamjan Jovanovic inline size_t
size() const472*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::size() const
473*8a106958SDamjan Jovanovic {
474*8a106958SDamjan Jovanovic     return aData.size();
475*8a106958SDamjan Jovanovic }
476*8a106958SDamjan Jovanovic 
477*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
478*8a106958SDamjan Jovanovic inline typename VirtualVector<XX,PTRDEL>::const_iterator
begin() const479*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::begin() const
480*8a106958SDamjan Jovanovic {
481*8a106958SDamjan Jovanovic     return const_iterator(aData.begin());
482*8a106958SDamjan Jovanovic }
483*8a106958SDamjan Jovanovic 
484*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
485*8a106958SDamjan Jovanovic inline typename VirtualVector<XX,PTRDEL>::const_iterator
end() const486*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::end() const
487*8a106958SDamjan Jovanovic {
488*8a106958SDamjan Jovanovic     return const_iterator(aData.end());
489*8a106958SDamjan Jovanovic }
490*8a106958SDamjan Jovanovic 
491*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
492*8a106958SDamjan Jovanovic inline const XX &
front() const493*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::front() const
494*8a106958SDamjan Jovanovic {
495*8a106958SDamjan Jovanovic     return *aData.front();
496*8a106958SDamjan Jovanovic }
497*8a106958SDamjan Jovanovic 
498*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
499*8a106958SDamjan Jovanovic inline const XX &
back() const500*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::back() const
501*8a106958SDamjan Jovanovic {
502*8a106958SDamjan Jovanovic     return *aData.back();
503*8a106958SDamjan Jovanovic }
504*8a106958SDamjan Jovanovic 
505*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
506*8a106958SDamjan Jovanovic inline typename VirtualVector<XX,PTRDEL>::iterator
begin()507*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::begin()
508*8a106958SDamjan Jovanovic {
509*8a106958SDamjan Jovanovic     return iterator(aData.begin());
510*8a106958SDamjan Jovanovic }
511*8a106958SDamjan Jovanovic 
512*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
513*8a106958SDamjan Jovanovic inline typename VirtualVector<XX,PTRDEL>::iterator
end()514*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::end()
515*8a106958SDamjan Jovanovic {
516*8a106958SDamjan Jovanovic     return iterator(aData.end());
517*8a106958SDamjan Jovanovic }
518*8a106958SDamjan Jovanovic 
519*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
520*8a106958SDamjan Jovanovic inline XX &
front()521*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::front()
522*8a106958SDamjan Jovanovic {
523*8a106958SDamjan Jovanovic     return *aData.front();
524*8a106958SDamjan Jovanovic }
525*8a106958SDamjan Jovanovic 
526*8a106958SDamjan Jovanovic template <class XX, class PTRDEL>
527*8a106958SDamjan Jovanovic inline XX &
back()528*8a106958SDamjan Jovanovic VirtualVector<XX,PTRDEL>::back()
529*8a106958SDamjan Jovanovic {
530*8a106958SDamjan Jovanovic     return *aData.back();
531*8a106958SDamjan Jovanovic }
532*8a106958SDamjan Jovanovic 
533*8a106958SDamjan Jovanovic 
534*8a106958SDamjan Jovanovic 
535*8a106958SDamjan Jovanovic 
536*8a106958SDamjan Jovanovic }   // namespace csv
537*8a106958SDamjan Jovanovic #endif
538