fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Fields / PointerFields / OSGPointerMFieldBase.inl
blob4edd88dcb8518a63811d9b3a63170b0e9874568c
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *           Copyright (C) 2008 by the OpenSG Forum                          *
6  *                                                                           *
7  *                            www.opensg.org                                 *
8  *                                                                           *
9  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
10  *                                                                           *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13  *                                License                                    *
14  *                                                                           *
15  * This library is free software; you can redistribute it and/or modify it   *
16  * under the terms of the GNU Library General Public License as published    *
17  * by the Free Software Foundation, version 2.                               *
18  *                                                                           *
19  * This library is distributed in the hope that it will be useful, but       *
20  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
22  * Library General Public License for more details.                          *
23  *                                                                           *
24  * You should have received a copy of the GNU Library General Public         *
25  * License along with this library; if not, write to the Free Software       *
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
27  *                                                                           *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30  *                                Changes                                    *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35  *                                                                           *
36  *                                                                           *
37 \*---------------------------------------------------------------------------*/
39 OSG_BEGIN_NAMESPACE
41 /*! \class PointerMFieldBase
43     \brief Base class of all fields that store FieldContainerPtr.
44     
45     It provides the const parts of the std::vector interface, but the pointers
46     returned/accepted by these functions are always pointers to the base
47     class FieldContainer, not the derived type.
48     To access those as well as for write access one of the derived classes
49     has to be used.
50  */
53 inline
54 SizeT PointerMFieldBase::getBinSize(void) const
56     return 
57         sizeof(UInt32) + // num elements
58         (_ptrStore.size() ? 
59          MFieldTraits::getBinSize(&(_ptrStore[0]), _ptrStore.size()) : 0);
63 inline
64 void PointerMFieldBase::copyToBin(BinaryDataHandler &pMem) const
66     UInt32 n = UInt32(_ptrStore.size());
68     pMem.putValue(n);
70     if(n != 0)
71     {
72         MFieldTraits::copyToBin(   pMem, 
73                                 &(_ptrStore[0]),
74                                   _ptrStore.size());
75     }
78 /*-------------------------------------------------------------------------*/
79 /* Std Library Const Interface                                             */
81 inline 
82 PointerMFieldBase::const_iterator PointerMFieldBase::begin(void) const
84     return const_iterator(_ptrStore.begin());
87 inline 
88 PointerMFieldBase::const_iterator PointerMFieldBase::end(void) const
90     return const_iterator(_ptrStore.end());
92     
93 inline 
94 PointerMFieldBase::const_reverse_iterator PointerMFieldBase::rbegin(void) const
96     return const_reverse_iterator(end());
99 inline 
100 PointerMFieldBase::const_reverse_iterator PointerMFieldBase::rend(void) const
102     return const_reverse_iterator(begin());
105 inline 
106 PointerMFieldBase::value_type PointerMFieldBase::front(void) const
108     return WeakRefCountPolicy::validate(_ptrStore.front());
111 inline 
112 PointerMFieldBase::value_type PointerMFieldBase::back(void) const
114     return WeakRefCountPolicy::validate(_ptrStore.back());
117 inline 
118 bool PointerMFieldBase::empty(void) const
120     return _ptrStore.empty();
123 inline 
124 PointerMFieldBase::size_type PointerMFieldBase::size(void) const
126     return _ptrStore.size();
129 inline 
130 UInt32 PointerMFieldBase::size32(void) const
132     return UInt32(_ptrStore.size());
135 inline 
136 PointerMFieldBase::size_type PointerMFieldBase::max_size(void) const
138     return _ptrStore.max_size();
141 inline 
142 PointerMFieldBase::size_type PointerMFieldBase::capacity(void) const
144     return _ptrStore.capacity();
146     
147 inline
148 PointerMFieldBase::difference_type 
149     PointerMFieldBase::findIndex(const_value value) const
151     StorageConstIt it = std::find(_ptrStore.begin(), _ptrStore.end(), value);
153     if(it != _ptrStore.end())
154     {
155         return it - _ptrStore.begin();
156     }
157     else
158     {
159         return -1;
160     }
163 inline 
164 void PointerMFieldBase::reserve(size_type newSize)
166     return _ptrStore.reserve(newSize);
169 inline 
170 PointerMFieldBase::value_type 
171     PointerMFieldBase::operator[](size_type const index) const
173     return WeakRefCountPolicy::validate(_ptrStore[index]);
176 inline 
177 PointerMFieldBase::value_type 
178     PointerMFieldBase::at(size_type const index) const
180     return WeakRefCountPolicy::validate(_ptrStore.at(index));
182     
183 inline
184 bool PointerMFieldBase::operator ==(const Self &source) const
186     return _ptrStore == source._ptrStore;
190 #ifdef OSG_MT_CPTR_ASPECT
191 inline
192 void PointerMFieldBase::beginEdit(UInt32              ,
193                                   AspectOffsetStore  &)
197 inline
198 PointerMFieldBase::Self *
199     PointerMFieldBase::resolveShare(UInt32              , 
200                                     AspectOffsetStore  &)
202     return NULL;
205 inline
206 void PointerMFieldBase::terminateShare(UInt32              , 
207                                        AspectOffsetStore  &)
209     
212 inline
213 bool PointerMFieldBase::isShared(void)
215     return false;
217 #endif
219 /*-------------------------------------------------------------------------*/
220 /* Constructors                                                            */
222 inline
223 PointerMFieldBase::PointerMFieldBase(void) :
224      Inherited(),
225     _ptrStore ()
229 /*-------------------------------------------------------------------------*/
230 /* Destructor                                                              */
232 inline
233 PointerMFieldBase::~PointerMFieldBase(void)
238 /*-------------------------------------------------------------------------*/
239 /* Raw Store Access                                                        */
241 inline 
242 PointerMFieldBase::StorageType &
243     PointerMFieldBase::editRawStore(void)
245     return _ptrStore;
248 inline 
249 PointerMFieldBase::StorageType const &
250     PointerMFieldBase::getRawStore(void) const
252     return _ptrStore;
255 /*-------------------------------------------------------------------------*/
256 /* Cast Store Access                                                       */
258 template <class TargetStoredTypeT> inline 
259 typename PointerMFieldBase::rebindStore<TargetStoredTypeT>::type &
260     PointerMFieldBase::editStore(void)
262     return
263         reinterpret_cast<typename rebindStore<TargetStoredTypeT>::type &>(
264             _ptrStore);
267 template <class TargetStoredTypeT> inline 
268 typename PointerMFieldBase::rebindStore<TargetStoredTypeT>::type const &
269     PointerMFieldBase::getStore(void) const
271     return
272         reinterpret_cast<typename rebindStore<TargetStoredTypeT>::type const &>(
273             _ptrStore);
276 /*---------------------------------------------------------------------------*/
277 /* PointerMFieldBaseConstIterator                                            */
278 /*---------------------------------------------------------------------------*/
280 /*---------------------------------------------------------------------------*/
281 /* Constructors                                                              */
283 inline
284 PointerMFieldBaseConstIterator::PointerMFieldBaseConstIterator(void) :
285     Inherited()
289 inline
290 PointerMFieldBaseConstIterator::PointerMFieldBaseConstIterator(
291     const Self &source) :
293     Inherited(source)
297 /* explicit */ 
298 inline
299 PointerMFieldBaseConstIterator::PointerMFieldBaseConstIterator(
300     const StorageConstIt &storeIt) :
302     Inherited(storeIt)
306 /*---------------------------------------------------------------------------*/
307 /* Destructor                                                                */
309 inline
310 PointerMFieldBaseConstIterator::~PointerMFieldBaseConstIterator(void)
314 /*---------------------------------------------------------------------------*/
315 /* Access Operators                                                          */
317 inline 
318 PointerMFieldBaseConstIterator::value_type
319     PointerMFieldBaseConstIterator::operator *(void) const
321     return WeakRefCountPolicy::validate(this->Inherited::operator*());
324 inline 
325 PointerMFieldBaseConstIterator::value_type
326     PointerMFieldBaseConstIterator::operator [](
327         const difference_type offset) const
329     return *(*this + offset);
332 /*---------------------------------------------------------------------------*/
333 /* Operators                                                                 */
335 inline 
336 PointerMFieldBaseConstIterator::Self &
337     PointerMFieldBaseConstIterator::operator ++(void)
339     this->Inherited::operator++();
341     return *this;
344 inline 
345 PointerMFieldBaseConstIterator::Self
346     PointerMFieldBaseConstIterator::operator ++(int)
348     Self retVal = *this;
350     this->Inherited::operator++();
352     return retVal;
355 inline 
356 PointerMFieldBaseConstIterator::Self &
357     PointerMFieldBaseConstIterator::operator --(void)
359     this->Inherited::operator--();
361     return *this;
364 inline 
365 PointerMFieldBaseConstIterator::Self
366     PointerMFieldBaseConstIterator::operator --(int)
368     Self retVal = *this;
370     this->Inherited::operator--();
372     return retVal;
375 inline 
376 PointerMFieldBaseConstIterator::Self &
377     PointerMFieldBaseConstIterator::operator +=(const difference_type offset)
379     this->Inherited::operator+=(offset);
381     return *this;
384 inline 
385 PointerMFieldBaseConstIterator::Self
386     PointerMFieldBaseConstIterator::operator +(
387         const difference_type offset) const
389     Self retVal = *this;
391     return retVal += offset;
394 inline 
395 PointerMFieldBaseConstIterator::Self &
396     PointerMFieldBaseConstIterator::operator -=(const difference_type offset)
398     this->Inherited::operator-=(offset);
400     return *this;
403 inline 
404 PointerMFieldBaseConstIterator::Self
405     PointerMFieldBaseConstIterator::operator -(
406         const difference_type offset) const
408     Self retVal = *this;
410     return retVal -= offset;
413 inline 
414 bool PointerMFieldBaseConstIterator::operator ==(const Self& rhs) const
416     return *(static_cast<const Inherited *>(this)) == rhs;
419 inline 
420 bool PointerMFieldBaseConstIterator::operator !=(const Self& rhs) const
422     return ! (*this == rhs);
425 OSG_END_NAMESPACE