1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2008 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
41 /*! \class PointerMFieldBase
43 \brief Base class of all fields that store FieldContainerPtr.
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
54 SizeT PointerMFieldBase::getBinSize(void) const
57 sizeof(UInt32) + // num elements
59 MFieldTraits::getBinSize(&(_ptrStore[0]), _ptrStore.size()) : 0);
64 void PointerMFieldBase::copyToBin(BinaryDataHandler &pMem) const
66 UInt32 n = UInt32(_ptrStore.size());
72 MFieldTraits::copyToBin( pMem,
78 /*-------------------------------------------------------------------------*/
79 /* Std Library Const Interface */
82 PointerMFieldBase::const_iterator PointerMFieldBase::begin(void) const
84 return const_iterator(_ptrStore.begin());
88 PointerMFieldBase::const_iterator PointerMFieldBase::end(void) const
90 return const_iterator(_ptrStore.end());
94 PointerMFieldBase::const_reverse_iterator PointerMFieldBase::rbegin(void) const
96 return const_reverse_iterator(end());
100 PointerMFieldBase::const_reverse_iterator PointerMFieldBase::rend(void) const
102 return const_reverse_iterator(begin());
106 PointerMFieldBase::value_type PointerMFieldBase::front(void) const
108 return WeakRefCountPolicy::validate(_ptrStore.front());
112 PointerMFieldBase::value_type PointerMFieldBase::back(void) const
114 return WeakRefCountPolicy::validate(_ptrStore.back());
118 bool PointerMFieldBase::empty(void) const
120 return _ptrStore.empty();
124 PointerMFieldBase::size_type PointerMFieldBase::size(void) const
126 return _ptrStore.size();
130 UInt32 PointerMFieldBase::size32(void) const
132 return UInt32(_ptrStore.size());
136 PointerMFieldBase::size_type PointerMFieldBase::max_size(void) const
138 return _ptrStore.max_size();
142 PointerMFieldBase::size_type PointerMFieldBase::capacity(void) const
144 return _ptrStore.capacity();
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())
155 return it - _ptrStore.begin();
164 void PointerMFieldBase::reserve(size_type newSize)
166 return _ptrStore.reserve(newSize);
170 PointerMFieldBase::value_type
171 PointerMFieldBase::operator[](size_type const index) const
173 return WeakRefCountPolicy::validate(_ptrStore[index]);
177 PointerMFieldBase::value_type
178 PointerMFieldBase::at(size_type const index) const
180 return WeakRefCountPolicy::validate(_ptrStore.at(index));
184 bool PointerMFieldBase::operator ==(const Self &source) const
186 return _ptrStore == source._ptrStore;
190 #ifdef OSG_MT_CPTR_ASPECT
192 void PointerMFieldBase::beginEdit(UInt32 ,
198 PointerMFieldBase::Self *
199 PointerMFieldBase::resolveShare(UInt32 ,
206 void PointerMFieldBase::terminateShare(UInt32 ,
213 bool PointerMFieldBase::isShared(void)
219 /*-------------------------------------------------------------------------*/
223 PointerMFieldBase::PointerMFieldBase(void) :
229 /*-------------------------------------------------------------------------*/
233 PointerMFieldBase::~PointerMFieldBase(void)
238 /*-------------------------------------------------------------------------*/
239 /* Raw Store Access */
242 PointerMFieldBase::StorageType &
243 PointerMFieldBase::editRawStore(void)
249 PointerMFieldBase::StorageType const &
250 PointerMFieldBase::getRawStore(void) const
255 /*-------------------------------------------------------------------------*/
256 /* Cast Store Access */
258 template <class TargetStoredTypeT> inline
259 typename PointerMFieldBase::rebindStore<TargetStoredTypeT>::type &
260 PointerMFieldBase::editStore(void)
263 reinterpret_cast<typename rebindStore<TargetStoredTypeT>::type &>(
267 template <class TargetStoredTypeT> inline
268 typename PointerMFieldBase::rebindStore<TargetStoredTypeT>::type const &
269 PointerMFieldBase::getStore(void) const
272 reinterpret_cast<typename rebindStore<TargetStoredTypeT>::type const &>(
276 /*---------------------------------------------------------------------------*/
277 /* PointerMFieldBaseConstIterator */
278 /*---------------------------------------------------------------------------*/
280 /*---------------------------------------------------------------------------*/
284 PointerMFieldBaseConstIterator::PointerMFieldBaseConstIterator(void) :
290 PointerMFieldBaseConstIterator::PointerMFieldBaseConstIterator(
291 const Self &source) :
299 PointerMFieldBaseConstIterator::PointerMFieldBaseConstIterator(
300 const StorageConstIt &storeIt) :
306 /*---------------------------------------------------------------------------*/
310 PointerMFieldBaseConstIterator::~PointerMFieldBaseConstIterator(void)
314 /*---------------------------------------------------------------------------*/
315 /* Access Operators */
318 PointerMFieldBaseConstIterator::value_type
319 PointerMFieldBaseConstIterator::operator *(void) const
321 return WeakRefCountPolicy::validate(this->Inherited::operator*());
325 PointerMFieldBaseConstIterator::value_type
326 PointerMFieldBaseConstIterator::operator [](
327 const difference_type offset) const
329 return *(*this + offset);
332 /*---------------------------------------------------------------------------*/
336 PointerMFieldBaseConstIterator::Self &
337 PointerMFieldBaseConstIterator::operator ++(void)
339 this->Inherited::operator++();
345 PointerMFieldBaseConstIterator::Self
346 PointerMFieldBaseConstIterator::operator ++(int)
350 this->Inherited::operator++();
356 PointerMFieldBaseConstIterator::Self &
357 PointerMFieldBaseConstIterator::operator --(void)
359 this->Inherited::operator--();
365 PointerMFieldBaseConstIterator::Self
366 PointerMFieldBaseConstIterator::operator --(int)
370 this->Inherited::operator--();
376 PointerMFieldBaseConstIterator::Self &
377 PointerMFieldBaseConstIterator::operator +=(const difference_type offset)
379 this->Inherited::operator+=(offset);
385 PointerMFieldBaseConstIterator::Self
386 PointerMFieldBaseConstIterator::operator +(
387 const difference_type offset) const
391 return retVal += offset;
395 PointerMFieldBaseConstIterator::Self &
396 PointerMFieldBaseConstIterator::operator -=(const difference_type offset)
398 this->Inherited::operator-=(offset);
404 PointerMFieldBaseConstIterator::Self
405 PointerMFieldBaseConstIterator::operator -(
406 const difference_type offset) const
410 return retVal -= offset;
414 bool PointerMFieldBaseConstIterator::operator ==(const Self& rhs) const
416 return *(static_cast<const Inherited *>(this)) == rhs;
420 bool PointerMFieldBaseConstIterator::operator !=(const Self& rhs) const
422 return ! (*this == rhs);