fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Fields / PointerFields / OSGParentPointerMField.h
blob9160f55944547eae8f41576185abd50a67536b04
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 #ifndef _OSGPARENTPOINTERMFIELD_H_
40 #define _OSGPARENTPOINTERMFIELD_H_
42 #ifdef __sgi
43 #pragma once
44 #endif
46 #include "OSGConfig.h"
47 #include "OSGPointerMFieldCommon.h"
48 #include "OSGPointerAccessHandler.h"
50 OSG_BEGIN_NAMESPACE
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
65 \nohierarchy
68 template <class StorageTypeT>
69 class ParentMFieldConstIterator : protected StorageTypeT::PtrStoreConstItType
71 /*========================== PUBLIC =================================*/
73 template <class ST>
74 friend class ParentMFieldIterator;
76 public:
78 /*---------------------------------------------------------------------*/
79 /*! \name Public Types */
80 /*! \{ */
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;
91 // std library types
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;
100 /*! \} */
101 /*---------------------------------------------------------------------*/
102 /*! \name Constructors */
103 /*! \{ */
105 ParentMFieldConstIterator( void );
106 ParentMFieldConstIterator(const Self &source );
107 ParentMFieldConstIterator(const iterator &fieldIter);
108 ParentMFieldConstIterator(const Inherited &storeIt,
109 const PosStorageIt &posIt );
111 /*! \} */
112 /*---------------------------------------------------------------------*/
113 /*! \name Destructor */
114 /*! \{ */
116 ~ParentMFieldConstIterator(void);
118 /*! \} */
119 /*---------------------------------------------------------------------*/
120 /*! \name Operators */
121 /*! \{ */
123 value_type operator *( void ) const;
124 value_type operator [](const difference_type offset) const;
126 /*! \} */
127 /*---------------------------------------------------------------------*/
128 /*! \name Operators */
129 /*! \{ */
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;
150 /*! \} */
151 /*---------------------------------------------------------------------*/
152 /*! \name Operators */
153 /*! \{ */
155 value_type getPtr (void) const;
156 UInt16 getParentFieldPos(void) const;
158 /*! \} */
159 /*======================== PROTECTED ================================*/
161 protected:
163 /*! \} */
164 /*---------------------------------------------------------------------*/
165 /*! \name Base */
166 /*! \{ */
168 const Inherited &ptrBase(void) const;
169 const PosStorageIt &idBase (void) const;
171 /*! \} */
172 /*========================== PRIVATE ================================*/
174 private:
176 PosStorageIt _posIt;
180 #if 0
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 );
190 #endif
192 /*---------------------------------------------------------------------------*/
193 /* ParentMFieldIterator<PtrTypeT> */
194 /*---------------------------------------------------------------------------*/
196 /*! \ingroup GrpBaseFieldContainerFields
197 \ingroup GrpLibOSGBase
198 \nohierarchy
201 template <class StorageTypeT>
202 class ParentMFieldIterator : protected StorageTypeT::PtrStoreItType
204 template <class ST>
205 friend class ParentMFieldConstIterator;
207 template <class PT, typename RC, Int32 NI>
208 friend class ParentPointerMField;
210 /*========================== PUBLIC =================================*/
212 public:
214 /*---------------------------------------------------------------------*/
215 /*! \name Public Types */
216 /*! \{ */
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;
228 // std library types
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;
238 /*! \} */
239 /*---------------------------------------------------------------------*/
240 /*! \name Constructors */
241 /*! \{ */
243 ParentMFieldIterator( void );
244 ParentMFieldIterator(const Self &source );
245 ParentMFieldIterator(const Inherited &storeIt,
246 const PosStorageIt &posIt );
248 /*! \} */
249 /*---------------------------------------------------------------------*/
250 /*! \name Destructor */
251 /*! \{ */
253 ~ParentMFieldIterator(void);
255 /*! \} */
256 /*---------------------------------------------------------------------*/
257 /*! \name Operators */
258 /*! \{ */
260 value_type operator *( void ) const;
261 value_type operator [](const difference_type offset) const;
263 /*! \} */
264 /*---------------------------------------------------------------------*/
265 /*! \name Operators */
266 /*! \{ */
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;
287 /*! \} */
288 /*---------------------------------------------------------------------*/
289 /*! \name Operators */
290 /*! \{ */
292 value_type getPtr (void) const;
293 UInt16 getParentFieldPos(void) const;
295 /*! \} */
296 /*---------------------------------------------------------------------*/
297 /*! \name Base */
298 /*! \{ */
300 /*! \} */
301 /*======================== PROTECTED ================================*/
303 protected:
305 /*! \} */
306 /*---------------------------------------------------------------------*/
307 /*! \name Base */
308 /*! \{ */
310 const Inherited &ptrBase(void) const;
311 const PosStorageIt &idBase (void) const;
313 /*! \} */
314 /*========================== PRIVATE ================================*/
316 private:
318 PosStorageIt _posIt;
322 /*---------------------------------------------------------------------------*/
323 /* ParentPointerMField<PtrTypeT, */
324 /* NamespaceI > */
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>,
336 NamespaceI >
338 /*========================== PUBLIC =================================*/
340 public:
342 /*---------------------------------------------------------------------*/
343 /*! \name Public Types */
344 /*! \{ */
346 typedef PointerMFieldCommon<
347 PointerAccessHandler<
348 RefCountPolicy>,
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;
373 #else
374 typedef vector <IdStoredType > IdStoreType;
375 #endif
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,
387 RefCountPolicy,
388 FieldType::ParentPtrField> Description;
390 typedef PointerAccessHandler<
391 RefCountPolicy > AccessHandler;
393 // handles
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;
403 // typedef
404 // typename EditParentPointerMFieldHandle<Self>::Ptr DynEditHandlePtr;
406 // typedef GetParentPointerMFieldHandle <Self> DynGetHandle;
407 // typedef typename GetParentPointerMFieldHandle <Self>::Ptr DynGetHandlePtr;
409 /*! \} */
410 /*---------------------------------------------------------------------*/
411 /*! \name Constants */
412 /*! \{ */
414 static FieldType::Cardinality const fieldCard = FieldType::MultiField;
415 static FieldType::Class const Class = FieldType::ParentPtrField;
417 /*! \} */
418 /*---------------------------------------------------------------------*/
419 /*! \name Class Type */
420 /*! \{ */
422 static FieldType const &getClassType(void);
424 /*! \} */
425 /*---------------------------------------------------------------------*/
426 /*! \name Constructors */
427 /*! \{ */
429 ParentPointerMField( void );
430 ParentPointerMField(const Self &other);
432 /*! \} */
433 /*---------------------------------------------------------------------*/
434 /*! \name Destructor */
435 /*! \{ */
437 ~ParentPointerMField(void);
439 /*! \} */
440 /*---------------------------------------------------------------------*/
441 /*! \name Binary IO */
442 /*! \{ */
444 SizeT getBinSize (void ) const;
446 void copyToBin (BinaryDataHandler &pMem) const;
447 void copyFromBin(BinaryDataHandler &pMem);
449 /*! \} */
450 /*---------------------------------------------------------------------*/
451 /*! \name Std Library Interface */
452 /*! \{ */
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;
463 /*! \} */
464 /*---------------------------------------------------------------------*/
465 /*! \name IdStore Interface */
466 /*! \{ */
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 );
477 #endif
479 iterator insert (iterator pos,
480 const_value value,
481 UInt16 parentFieldPos);
483 #ifndef OSG_CLEAN_FCFIELDS
484 iterator erase (iterator pos );
485 iterator erase (iterator first,
486 iterator last );
487 #endif
489 void erase (size_type pos );
491 #ifndef OSG_CLEAN_FCFIELDS
492 iterator find (const_value value );
493 #endif
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 );
503 /*! \} */
504 /*---------------------------------------------------------------------*/
505 /*! \name Raw IdStore Access */
506 /*! \{ */
508 void replace(UInt32 uiIdx,
509 const_value value,
510 UInt16 parentFieldPos);
512 void replace(iterator pos,
513 const_value value,
514 UInt16 parentFieldPos);
516 /*! \} */
517 /*---------------------------------------------------------------------*/
518 /*! \name Index Operator */
519 /*! \{ */
521 value_type operator [](const size_type index) const;
523 /*! \} */
524 /*---------------------------------------------------------------------*/
525 /*! \name Index Operator */
526 /*! \{ */
528 value_type ptrAt (const size_type index) const;
529 UInt16 parentFieldPosAt(const size_type index) const;
531 /*! \} */
532 /*---------------------------------------------------------------------*/
533 /*! \name MT Sync */
534 /*! \{ */
536 #ifdef OSG_MT_CPTR_ASPECT
537 void syncWith (Self &source,
538 ConstFieldMaskArg syncMode,
539 UInt32 uiSyncInfo,
540 AspectOffsetStore &oOffsets );
541 #endif
543 /*! \} */
544 /*---------------------------------------------------------------------*/
545 /*! \name Index Operator */
546 /*! \{ */
548 const Self &operator =(const Self &source);
550 /*! \} */
551 /*========================= PROTECTED ===============================*/
553 protected:
555 /*---------------------------------------------------------------------*/
556 /*! \name Members */
557 /*! \{ */
559 static FieldType _fieldType;
560 IdStoreType _vParentPos;
562 /*! \} */
563 /*---------------------------------------------------------------------*/
564 /*! \name Member */
565 /*! \{ */
567 void resize(size_t newsize,
568 const_value t = NULL);
570 void clear (void );
572 /*! \} */
573 /*========================== PRIVATE ================================*/
575 private:
577 typedef PtrMFieldTraits MFieldTraits;
580 OSG_END_NAMESPACE
582 #include "OSGParentPointerMField.inl"
584 #endif // _OSGPARENTPOINTERMFIELD_H_