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 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGPARENTPOINTERMFIELD_H_
40 #define _OSGPARENTPOINTERMFIELD_H_
46 #include "OSGConfig.h"
47 #include "OSGPointerMFieldCommon.h"
48 #include "OSGPointerAccessHandler.h"
52 // forward declarations
53 template <class PtrTypeT
, typename RefCountPolicy
, Int32 NamespaceI
>
54 class ParentPointerMField
;
56 template <class StorageTypeT
>
57 class ParentMFieldIterator
;
59 /*---------------------------------------------------------------------------*/
60 /* ParentMFieldConstIterator<PtrTypeT> */
61 /*---------------------------------------------------------------------------*/
63 /*! \ingroup GrpBaseFieldContainerFields
64 \ingroup GrpLibOSGBase
68 template <class StorageTypeT
>
69 class ParentMFieldConstIterator
: protected StorageTypeT::PtrStoreConstItType
71 /*========================== PUBLIC =================================*/
74 friend class ParentMFieldIterator
;
78 /*---------------------------------------------------------------------*/
79 /*! \name Public Types */
82 typedef typename
StorageTypeT::PtrStoreConstItType Inherited
;
84 typedef ParentMFieldConstIterator Self
;
86 typedef typename
StorageTypeT::AccessHandler AccessHandler
;
88 typedef std::vector
<UInt16
> PosStorage
;
89 typedef std::vector
<UInt16
>::const_iterator PosStorageIt
;
92 typedef typename
Inherited::iterator_category iterator_category
;
93 typedef typename
Inherited::difference_type difference_type
;
96 typedef typename
StorageTypeT::const_value const_value
;
97 typedef typename
StorageTypeT::value_type value_type
;
98 typedef typename
StorageTypeT::iterator iterator
;
101 /*---------------------------------------------------------------------*/
102 /*! \name Constructors */
105 ParentMFieldConstIterator( void );
106 ParentMFieldConstIterator(const Self
&source
);
107 ParentMFieldConstIterator(const iterator
&fieldIter
);
108 ParentMFieldConstIterator(const Inherited
&storeIt
,
109 const PosStorageIt
&posIt
);
112 /*---------------------------------------------------------------------*/
113 /*! \name Destructor */
116 ~ParentMFieldConstIterator(void);
119 /*---------------------------------------------------------------------*/
120 /*! \name Operators */
123 value_type
operator *( void ) const;
124 value_type
operator [](const difference_type offset
) const;
127 /*---------------------------------------------------------------------*/
128 /*! \name Operators */
131 Self
&operator ++( void );
132 Self
operator ++( int );
134 Self
&operator --( void );
135 Self
operator --( int );
138 Self
&operator +=(const difference_type offset
);
139 Self
operator + (const difference_type offset
) const;
141 Self
&operator -=(const difference_type offset
);
142 Self
operator - (const difference_type offset
) const;
144 bool operator == (const Self
&rhs
) const;
145 bool operator != (const Self
&rhs
) const;
147 bool operator == (const iterator
&rhs
) const;
148 bool operator != (const iterator
&rhs
) const;
151 /*---------------------------------------------------------------------*/
152 /*! \name Operators */
155 value_type
getPtr (void) const;
156 UInt16
getParentFieldPos(void) const;
159 /*======================== PROTECTED ================================*/
164 /*---------------------------------------------------------------------*/
168 const Inherited
&ptrBase(void) const;
169 const PosStorageIt
&idBase (void) const;
172 /*========================== PRIVATE ================================*/
181 template <class PtrTypeT
>
182 typename ParentMFieldConstIterator
<PtrTypeT
>::difference_type
183 operator-(ParentMFieldConstIterator
<PtrTypeT
> const &lhs
,
184 ParentMFieldConstIterator
<PtrTypeT
> const &rhs
);
186 template <class PtrTypeT
>
187 ParentMFieldConstIterator
<PtrTypeT
>
188 operator+(typename ParentMFieldConstIterator
<PtrTypeT
>::differece_type
const offset
,
189 ParentMFieldConstIterator
<PtrTypeT
> const &rhs
);
192 /*---------------------------------------------------------------------------*/
193 /* ParentMFieldIterator<PtrTypeT> */
194 /*---------------------------------------------------------------------------*/
196 /*! \ingroup GrpBaseFieldContainerFields
197 \ingroup GrpLibOSGBase
201 template <class StorageTypeT
>
202 class ParentMFieldIterator
: protected StorageTypeT::PtrStoreItType
205 friend class ParentMFieldConstIterator
;
207 template <class PT
, typename RC
, Int32 NI
>
208 friend class ParentPointerMField
;
210 /*========================== PUBLIC =================================*/
214 /*---------------------------------------------------------------------*/
215 /*! \name Public Types */
219 typedef typename
StorageTypeT::PtrStoreItType Inherited
;
221 typedef ParentMFieldIterator Self
;
223 typedef typename
StorageTypeT::AccessHandler AccessHandler
;
225 typedef std::vector
<UInt16
> PosStorage
;
226 typedef std::vector
<UInt16
>::iterator PosStorageIt
;
229 typedef typename
Inherited::iterator_category iterator_category
;
230 typedef typename
Inherited::difference_type difference_type
;
233 typedef typename
StorageTypeT::const_value const_value
;
234 typedef typename
StorageTypeT::value_type value_type
;
235 typedef typename
StorageTypeT::const_iterator const_iterator
;
239 /*---------------------------------------------------------------------*/
240 /*! \name Constructors */
243 ParentMFieldIterator( void );
244 ParentMFieldIterator(const Self
&source
);
245 ParentMFieldIterator(const Inherited
&storeIt
,
246 const PosStorageIt
&posIt
);
249 /*---------------------------------------------------------------------*/
250 /*! \name Destructor */
253 ~ParentMFieldIterator(void);
256 /*---------------------------------------------------------------------*/
257 /*! \name Operators */
260 value_type
operator *( void ) const;
261 value_type
operator [](const difference_type offset
) const;
264 /*---------------------------------------------------------------------*/
265 /*! \name Operators */
268 Self
&operator ++( void );
269 Self
operator ++( int );
271 Self
&operator --( void );
272 Self
operator --( int );
275 Self
&operator +=(const difference_type offset
);
276 Self
operator + (const difference_type offset
) const;
278 Self
&operator -=(const difference_type offset
);
279 Self
operator - (const difference_type offset
) const;
281 bool operator == (const Self
&rhs
) const;
282 bool operator != (const Self
&rhs
) const;
284 bool operator == (const const_iterator
&rhs
) const;
285 bool operator != (const const_iterator
&rhs
) const;
288 /*---------------------------------------------------------------------*/
289 /*! \name Operators */
292 value_type
getPtr (void) const;
293 UInt16
getParentFieldPos(void) const;
296 /*---------------------------------------------------------------------*/
301 /*======================== PROTECTED ================================*/
306 /*---------------------------------------------------------------------*/
310 const Inherited
&ptrBase(void) const;
311 const PosStorageIt
&idBase (void) const;
314 /*========================== PRIVATE ================================*/
322 /*---------------------------------------------------------------------------*/
323 /* ParentPointerMField<PtrTypeT, */
325 /*---------------------------------------------------------------------------*/
327 /*! \ingroup GrpBaseFieldContainerFields
328 \ingroup GrpLibOSGBase
331 template <class PtrTypeT
,
332 typename RefCountPolicy
,
333 Int32 NamespaceI
= 0>
334 class ParentPointerMField
:
335 public PointerMFieldCommon
<PointerAccessHandler
<RefCountPolicy
>,
338 /*========================== PUBLIC =================================*/
342 /*---------------------------------------------------------------------*/
343 /*! \name Public Types */
346 typedef PointerMFieldCommon
<
347 PointerAccessHandler
<
349 NamespaceI
> Inherited
;
351 typedef ParentPointerMField Self
;
353 typedef PtrTypeT
const const_value
;
354 typedef PtrTypeT value_type
;
356 typedef typename
Inherited::size_type size_type
;
357 typedef typename
Inherited::difference_type difference_type
;
359 typedef typename
Inherited::PtrStoreItType PtrStoreItType
;
360 typedef typename
Inherited::PtrStoreConstItType PtrStoreConstItType
;
362 typedef ParentMFieldConstIterator
<Self
> const_iterator
;
363 typedef std::reverse_iterator
<
364 const_iterator
> const_reverse_iterator
;
366 typedef ParentMFieldIterator
<Self
> iterator
;
368 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
370 typedef UInt16 IdStoredType
;
371 #ifndef DOXYGEN_SHOULD_SKIP_THIS
372 typedef MFieldVector
<IdStoredType
> IdStoreType
;
374 typedef vector
<IdStoredType
> IdStoreType
;
376 typedef typename
IdStoreType::iterator IdStoreItType
;
377 typedef typename
IdStoreType::const_iterator IdStoreConstItType
;
379 typedef FieldTraits
<IdStoredType
> PosMFieldTraits
;
382 typedef FieldTraits
<value_type
,
383 NamespaceI
> PtrMFieldTraits
;
385 typedef FieldDescription
<PtrMFieldTraits
,
386 FieldType::MultiField
,
388 FieldType::ParentPtrField
> Description
;
390 typedef PointerAccessHandler
<
391 RefCountPolicy
> AccessHandler
;
394 typedef void EditHandle
;
395 typedef boost::shared_ptr
<EditHandle
> EditHandlePtr
;
397 typedef GetFCPtrMFieldHandle
<Self
> GetHandle
;
398 typedef boost::shared_ptr
<GetHandle
> GetHandlePtr
;
401 // handles for dynamic fields -- XXX TODO
402 // typedef EditParentPointerMFieldHandle<Self> DynEditHandle;
404 // typename EditParentPointerMFieldHandle<Self>::Ptr DynEditHandlePtr;
406 // typedef GetParentPointerMFieldHandle <Self> DynGetHandle;
407 // typedef typename GetParentPointerMFieldHandle <Self>::Ptr DynGetHandlePtr;
410 /*---------------------------------------------------------------------*/
411 /*! \name Constants */
414 static FieldType::Cardinality
const fieldCard
= FieldType::MultiField
;
415 static FieldType::Class
const Class
= FieldType::ParentPtrField
;
418 /*---------------------------------------------------------------------*/
419 /*! \name Class Type */
422 static FieldType
const &getClassType(void);
425 /*---------------------------------------------------------------------*/
426 /*! \name Constructors */
429 ParentPointerMField( void );
430 ParentPointerMField(const Self
&other
);
433 /*---------------------------------------------------------------------*/
434 /*! \name Destructor */
437 ~ParentPointerMField(void);
440 /*---------------------------------------------------------------------*/
441 /*! \name Binary IO */
444 SizeT
getBinSize (void ) const;
446 void copyToBin (BinaryDataHandler
&pMem
) const;
447 void copyFromBin(BinaryDataHandler
&pMem
);
450 /*---------------------------------------------------------------------*/
451 /*! \name Std Library Interface */
454 const_iterator
begin (void) const;
455 const_iterator
end (void) const;
457 const_reverse_iterator
rbegin(void) const;
458 const_reverse_iterator
rend (void) const;
460 value_type
front (void) const;
461 value_type
back (void) const;
464 /*---------------------------------------------------------------------*/
465 /*! \name IdStore Interface */
468 iterator
begin_nc (void );
469 iterator
end_nc (void );
471 #ifndef OSG_CLEAN_FCFIELDS
472 iterator
begin (void );
473 iterator
end (void );
475 reverse_iterator
rbegin (void );
476 reverse_iterator
rend (void );
479 iterator
insert (iterator pos
,
481 UInt16 parentFieldPos
);
483 #ifndef OSG_CLEAN_FCFIELDS
484 iterator
erase (iterator pos
);
485 iterator
erase (iterator first
,
489 void erase (size_type pos
);
491 #ifndef OSG_CLEAN_FCFIELDS
492 iterator
find (const_value value
);
494 iterator
find_nc (const_value value
);
496 const_iterator
find (const_value value
) const;
498 void push_back(const_value value
,
499 UInt16 parentFieldPos
);
501 void reserve (size_type newsize
);
504 /*---------------------------------------------------------------------*/
505 /*! \name Raw IdStore Access */
508 void replace(UInt32 uiIdx
,
510 UInt16 parentFieldPos
);
512 void replace(iterator pos
,
514 UInt16 parentFieldPos
);
517 /*---------------------------------------------------------------------*/
518 /*! \name Index Operator */
521 value_type
operator [](const size_type index
) const;
524 /*---------------------------------------------------------------------*/
525 /*! \name Index Operator */
528 value_type
ptrAt (const size_type index
) const;
529 UInt16
parentFieldPosAt(const size_type index
) const;
532 /*---------------------------------------------------------------------*/
536 #ifdef OSG_MT_CPTR_ASPECT
537 void syncWith (Self
&source
,
538 ConstFieldMaskArg syncMode
,
540 AspectOffsetStore
&oOffsets
);
544 /*---------------------------------------------------------------------*/
545 /*! \name Index Operator */
548 const Self
&operator =(const Self
&source
);
551 /*========================= PROTECTED ===============================*/
555 /*---------------------------------------------------------------------*/
559 static FieldType _fieldType
;
560 IdStoreType _vParentPos
;
563 /*---------------------------------------------------------------------*/
567 void resize(size_t newsize
,
568 const_value t
= NULL
);
573 /*========================== PRIVATE ================================*/
577 typedef PtrMFieldTraits MFieldTraits
;
582 #include "OSGParentPointerMField.inl"
584 #endif // _OSGPARENTPOINTERMFIELD_H_