fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Fields / PointerFields / OSGPointerMField.h
blob85682375a6521087d54237f4a27ede993b20ff03
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 _OSGPOINTERMFIELD_H_
40 #define _OSGPOINTERMFIELD_H_
42 #ifdef __sgi
43 #pragma once
44 #endif
46 #include "OSGPointerMFieldCommon.h"
47 #include "OSGPointerAccessHandler.h"
49 OSG_BEGIN_NAMESPACE
51 // forward declarations
52 template <class PtrTypeT,
53 typename RefCountPolicy,
54 Int32 NamespaceI>
55 class PointerMField;
57 #ifndef OSG_CLEAN_FCFIELDS
58 template <class PtrTypeT,
59 typename RefCountPolicy,
60 Int32 NamespaceI>
61 class PointerMFieldReferenceProxy;
62 #endif
64 template <class PtrTypeT,
65 typename RefCountPolicy,
66 Int32 NamespaceI>
67 class PointerMFieldConstIterator;
69 /*---------------------------------------------------------------------------*/
70 /* PointerMFieldIterator<PtrTypeT> */
71 /*---------------------------------------------------------------------------*/
73 /*! \ingroup GrpBaseFieldContainerFields
74 \ingroup GrpLibOSGBase
75 \nohierarchy
78 template <class PtrTypeT, typename RefCountPolicy, Int32 NamespaceI>
79 class PointerMFieldIterator :
80 protected PointerMField<PtrTypeT,
81 RefCountPolicy,
82 NamespaceI >::PtrStoreItType
84 /*========================== PUBLIC =================================*/
86 public:
88 /*---------------------------------------------------------------------*/
89 /*! \name Public Types */
90 /*! \{ */
92 typedef PointerMFieldIterator Self;
94 typedef PointerMField<PtrTypeT,
95 RefCountPolicy,
96 NamespaceI > MFieldType;
98 typedef typename MFieldType::PtrStoreItType Inherited;
100 typedef typename MFieldType::AccessHandler AccessHandler;
102 typedef PtrTypeT const const_value;
104 // store types
105 typedef typename MFieldType::StoredType StoredType;
106 typedef typename MFieldType::PtrStoreType PtrStoreType;
107 typedef typename MFieldType::PtrStoreItType PtrStoreItType;
109 typedef typename MFieldType::const_iterator const_iterator;
111 // std library typedefs
113 typedef typename Inherited::iterator_category iterator_category;
114 typedef typename Inherited::difference_type difference_type;
115 typedef PtrTypeT value_type;
116 typedef PtrTypeT * pointer;
118 #ifndef OSG_CLEAN_FCFIELDS
119 typedef PointerMFieldReferenceProxy<
120 PtrTypeT,
121 RefCountPolicy,
122 NamespaceI > reference;
123 #else
124 typedef typename Inherited::reference reference;
125 #endif
127 #if defined(WIN32) && _SECURE_SCL == 1 && _MSC_VER < 1600
128 typedef typename Inherited::_Checked_iterator_base_type
129 _Checked_iterator_base_type;
130 #endif
132 /*! \} */
133 /*---------------------------------------------------------------------*/
134 /*! \name Constructors */
135 /*! \{ */
137 PointerMFieldIterator( void );
138 PointerMFieldIterator(const Self &source );
140 PointerMFieldIterator(const PtrStoreItType &storeIter,
141 MFieldType *pField );
143 /*! \} */
144 /*---------------------------------------------------------------------*/
145 /*! \name Destructor */
146 /*! \{ */
148 ~PointerMFieldIterator(void);
150 /*! \} */
151 /*---------------------------------------------------------------------*/
152 /*! \name Operators */
153 /*! \{ */
155 #ifndef OSG_CLEAN_FCFIELDS
156 reference operator *( void ) const;
157 reference operator [](const difference_type offset) const;
158 #else
159 const_value operator *( void ) const;
160 const_value operator [](const difference_type offset) const;
161 #endif
163 /*! \} */
164 /*---------------------------------------------------------------------*/
165 /*! \name Operators */
166 /*! \{ */
168 Self &operator ++( void );
169 Self operator ++( int );
171 Self &operator --( void );
172 Self operator --( int );
174 Self &operator +=(const difference_type offset);
175 Self operator + (const difference_type offset) const;
177 Self &operator -=(const difference_type offset);
178 Self operator - (const difference_type offset) const;
181 bool operator == (const Self &rhs ) const;
182 bool operator != (const Self &rhs ) const;
184 bool operator == (const const_iterator &rhs ) const;
185 bool operator != (const const_iterator &rhs ) const;
187 /*! \} */
188 /*---------------------------------------------------------------------*/
189 /*! \name Operators */
190 /*! \{ */
192 const Self &operator =(const Self &other);
194 /*! \} */
195 /*---------------------------------------------------------------------*/
196 /*! \name Base */
197 /*! \{ */
199 const PtrStoreItType &base(void) const;
201 /*! \} */
202 /*========================= PROTECTED ===============================*/
204 protected:
206 /*========================== PRIVATE ================================*/
208 private:
210 MFieldType *_pField;
212 template <class AccessHandlerT, Int32 NI>
213 friend class PointerMFieldCommon;
215 template <class PT, typename RC, Int32 NI>
216 friend class PointerMFieldConstIterator;
218 template <class PT, typename RC, Int32 NI>
219 friend class PointerMField;
223 template <class PtrTypeT, class RefCountPolicyT, Int32 NamespaceI>
224 typename PointerMFieldIterator<PtrTypeT,
225 RefCountPolicyT,
226 NamespaceI >::difference_type
227 operator-(PointerMFieldIterator<PtrTypeT,
228 RefCountPolicyT,
229 NamespaceI > const &lhs,
231 PointerMFieldIterator<PtrTypeT,
232 RefCountPolicyT,
233 NamespaceI > const &rhs );
235 template <class PtrTypeT, class RefCountPolicyT, Int32 NamespaceI>
236 PointerMFieldIterator<PtrTypeT,
237 RefCountPolicyT,
238 NamespaceI >
240 operator+(
241 typename PointerMFieldIterator<
242 PtrTypeT,
243 RefCountPolicyT,
244 NamespaceI >::differece_type const offset,
246 PointerMFieldIterator<
247 PtrTypeT,
248 RefCountPolicyT,
249 NamespaceI > const &rhs );
252 /*---------------------------------------------------------------------------*/
253 /* PointerMFieldConstIterator<PtrTypeT> */
254 /*---------------------------------------------------------------------------*/
256 /*! \ingroup GrpBaseFieldContainerFields
257 \ingroup GrpLibOSGBase
258 \nohierarchy
261 template <class PtrTypeT, typename RefCountPolicy, Int32 NamespaceI>
262 class PointerMFieldConstIterator :
263 protected PointerMField<PtrTypeT,
264 RefCountPolicy,
265 NamespaceI >::PtrStoreConstItType
267 /*========================== PUBLIC =================================*/
269 public:
271 /*---------------------------------------------------------------------*/
272 /*! \name Public Types */
273 /*! \{ */
275 typedef PointerMFieldConstIterator Self;
277 typedef PointerMField<PtrTypeT,
278 RefCountPolicy,
279 NamespaceI > MFieldType;
281 typedef typename MFieldType::PtrStoreConstItType Inherited;
283 typedef typename MFieldType::AccessHandler AccessHandler;
285 typedef PtrTypeT const const_value;
287 // store types
288 typedef typename MFieldType::StoredType StoredType;
289 typedef typename MFieldType::PtrStoreType PtrStoreType;
290 typedef typename MFieldType::PtrStoreConstItType PtrStoreConstItType;
292 typedef typename MFieldType::iterator iterator;
294 // std library types
295 typedef typename Inherited::iterator_category iterator_category;
296 typedef typename Inherited::difference_type difference_type;
297 typedef typename Inherited::value_type value_type;
298 typedef typename Inherited::pointer pointer;
299 typedef typename Inherited::reference reference;
301 /*! \} */
302 /*---------------------------------------------------------------------*/
303 /*! \name Constructors */
304 /*! \{ */
306 PointerMFieldConstIterator( void );
307 PointerMFieldConstIterator(const Self &source );
308 PointerMFieldConstIterator(const iterator &fieldIter);
309 explicit PointerMFieldConstIterator(const PtrStoreConstItType &storeIter);
311 /*! \} */
312 /*---------------------------------------------------------------------*/
313 /*! \name Destructor */
314 /*! \{ */
316 ~PointerMFieldConstIterator(void);
318 /*! \} */
319 /*---------------------------------------------------------------------*/
320 /*! \name Operators */
321 /*! \{ */
323 const_value operator * ( void ) const;
324 const_value operator [](const difference_type offset) const;
326 /*! \} */
327 /*---------------------------------------------------------------------*/
328 /*! \name Operators */
329 /*! \{ */
331 Self &operator ++( void );
332 Self operator ++( int );
334 Self &operator --( void );
335 Self operator --( int );
337 Self &operator +=(const difference_type offset);
338 Self operator + (const difference_type offset) const;
340 Self &operator -=(const difference_type offset);
341 Self operator - (const difference_type offset) const;
344 bool operator == (const Self &rhs ) const;
345 bool operator != (const Self &rhs ) const;
347 bool operator == (const iterator &rhs ) const;
348 bool operator != (const iterator &rhs ) const;
350 /*! \} */
351 /*---------------------------------------------------------------------*/
352 /*! \name Base */
353 /*! \{ */
355 const PtrStoreConstItType &base(void) const;
357 /*! \} */
358 /*========================= PROTECTED ===============================*/
360 protected:
362 /*========================== PRIVATE ================================*/
364 private:
366 template <class AccessHandlerT, Int32 NI>
367 friend class PointerMFieldCommon;
369 template <class PT, typename RC, Int32 NI>
370 friend class PointerMFieldIterator;
372 template <class PT, typename RC, Int32 NI>
373 friend class PointerMField;
376 template <class PtrTypeT, class RefCountPolicyT, Int32 iNamespace>
377 typename PointerMFieldConstIterator<PtrTypeT,
378 RefCountPolicyT,
379 iNamespace >::difference_type
380 operator-(PointerMFieldConstIterator<PtrTypeT,
381 RefCountPolicyT,
382 iNamespace > const &lhs,
383 PointerMFieldConstIterator<PtrTypeT,
384 RefCountPolicyT,
385 iNamespace > const &rhs );
387 template <class PtrTypeT, class RefCountPolicyT, Int32 iNamespace>
388 typename PointerMFieldConstIterator<PtrTypeT,
389 RefCountPolicyT,
390 iNamespace >::difference_type
391 operator-(PointerMFieldIterator <PtrTypeT,
392 RefCountPolicyT,
393 iNamespace > const &lhs,
394 PointerMFieldConstIterator<PtrTypeT,
395 RefCountPolicyT,
396 iNamespace > const &rhs );
398 template <class PtrTypeT, class RefCountPolicyT, Int32 iNamespace>
399 typename PointerMFieldConstIterator<PtrTypeT,
400 RefCountPolicyT,
401 iNamespace >::difference_type
402 operator-(PointerMFieldConstIterator<PtrTypeT,
403 RefCountPolicyT,
404 iNamespace > const &lhs,
405 PointerMFieldIterator <PtrTypeT,
406 RefCountPolicyT,
407 iNamespace > const &rhs );
409 template <class PtrTypeT, class RefCountPolicyT, Int32 iNamespace>
410 PointerMFieldConstIterator<PtrTypeT, RefCountPolicyT, iNamespace>
411 operator+(
412 typename PointerMFieldConstIterator<
413 PtrTypeT,
414 RefCountPolicyT,
415 iNamespace >::difference_type const offset,
417 PointerMFieldConstIterator<
418 PtrTypeT,
419 RefCountPolicyT,
420 iNamespace > const &rhs );
423 #ifndef OSG_CLEAN_FCFIELDS
424 /*-------------------------------------------------------------------------*/
425 /* WeakMFieldReferenceProxy<PtrTypeT> */
426 /*-------------------------------------------------------------------------*/
428 /*! \ingroup GrpBaseFieldContainerFields
429 \ingroup GrpLibOSGBase
430 \nohierarchy
433 template <class PtrTypeT, typename RefCountPolicy, Int32 NamespaceI>
434 class PointerMFieldReferenceProxy
436 /*========================== PUBLIC =================================*/
438 public:
440 /*---------------------------------------------------------------------*/
441 /*! \name Public Types */
442 /*! \{ */
444 typedef PointerMFieldReferenceProxy Self;
446 typedef PointerMField<PtrTypeT,
447 RefCountPolicy,
448 NamespaceI > MFieldType;
450 typedef typename MFieldType::AccessHandler AccessHandler;
452 // store types
453 typedef typename MFieldType::StoredType StoredType;
454 typedef typename MFieldType::PtrStoreType PtrStoreType;
455 typedef typename MFieldType::PtrStoreItType PtrStoreItType;
456 typedef typename MFieldType::PtrStoreConstItType PtrStoreConstItType;
458 // std library types
459 typedef PtrTypeT value_type;
461 /*! \} */
462 /*---------------------------------------------------------------------*/
463 /*! \name Constructors */
464 /*! \{ */
466 PointerMFieldReferenceProxy(const PtrStoreItType &storeIter,
467 MFieldType *pField );
469 PointerMFieldReferenceProxy(const Self &source );
471 /*! \} */
472 /*---------------------------------------------------------------------*/
473 /*! \name Destructor */
474 /*! \{ */
476 ~PointerMFieldReferenceProxy(void);
478 /*! \} */
479 /*---------------------------------------------------------------------*/
480 /*! \name Operators */
481 /*! \{ */
483 operator value_type(void) const;
484 value_type operator-> (void) const;
486 void operator=(value_type newValue);
488 /*! \} */
489 /*========================== PRIVATE ================================*/
491 private:
493 PtrStoreItType _storeIter;
494 MFieldType *_pField;
496 #endif
498 /*---------------------------------------------------------------------------*/
499 /* WeakPointerMField<FieldConfigT> */
500 /*---------------------------------------------------------------------------*/
502 /*! \ingroup GrpBaseFieldContainerFields
503 \ingroup GrpLibOSGBase
506 template <class PtrTypeT,
507 typename RefCountPolicy,
508 Int32 NamespaceI = 0>
509 class PointerMField :
510 public PointerMFieldCommon<PointerAccessHandler<RefCountPolicy>,
511 NamespaceI >
513 /*========================== PUBLIC =================================*/
515 public:
517 /*---------------------------------------------------------------------*/
518 /*! \name Public Types */
519 /*! \{ */
521 typedef PointerMFieldCommon <
522 PointerAccessHandler<RefCountPolicy>,
523 NamespaceI > Inherited;
525 typedef PointerMField Self;
527 typedef PtrTypeT const const_value;
528 typedef PtrTypeT value_type;
529 typedef value_type StoredType;
531 typedef typename Inherited::size_type size_type;
532 typedef typename Inherited::difference_type difference_type;
534 typedef PointerMFieldIterator <PtrTypeT,
535 RefCountPolicy,
536 NamespaceI > iterator;
538 typedef PointerMFieldConstIterator <PtrTypeT,
539 RefCountPolicy,
540 NamespaceI > const_iterator;
542 typedef std::reverse_iterator <iterator > reverse_iterator;
543 typedef std::reverse_iterator <const_iterator> const_reverse_iterator;
546 typedef FieldTraits <value_type,
547 NamespaceI > MFieldTraits;
548 typedef FieldDescription <
549 MFieldTraits,
550 FieldType::MultiField,
551 RefCountPolicy,
552 FieldType::PtrField > Description;
554 #ifndef OSG_CLEAN_FCFIELDS
555 typedef PointerMFieldReferenceProxy<PtrTypeT,
556 RefCountPolicy,
557 NamespaceI > reference;
558 #endif
560 // handles
561 typedef EditFCPtrMFieldHandle <Self > EditHandle;
562 typedef boost::shared_ptr <EditHandle > EditHandlePtr;
564 typedef GetFCPtrMFieldHandle <Self > GetHandle;
565 typedef boost::shared_ptr <GetHandle > GetHandlePtr;
567 // handles for dynamic fields -- XXX TODO
568 // typedef EditPointerMFieldHandle<Self> DynamicEditHandle;
569 // typedef typename EditPointerMFieldHandle<Self>::Ptr DynamicEditHandlePtr;
571 // typedef GetPointerMFieldHandle <Self> DynamicGetHandle;
572 // typedef typename GetPointerMFieldHandle <Self>::Ptr DynamicGetHandlePtr;
574 /*! \} */
575 /*---------------------------------------------------------------------*/
576 /*! \name Constants */
577 /*! \{ */
579 static FieldType::Cardinality const fieldCard = FieldType::MultiField;
580 static FieldType::Class const Class = FieldType::PtrField;
582 /*! \} */
583 /*---------------------------------------------------------------------*/
584 /*! \name Class Type */
585 /*! \{ */
587 static FieldType const &getClassType(void);
589 /*! \} */
590 /*---------------------------------------------------------------------*/
591 /*! \name Constructors */
592 /*! \{ */
594 PointerMField( void );
595 PointerMField(const Self &other );
596 explicit PointerMField(const UInt32 initSize);
598 /*! \} */
599 /*---------------------------------------------------------------------*/
600 /*! \name Destructor */
601 /*! \{ */
603 ~PointerMField(void);
605 /*! \} */
606 /*---------------------------------------------------------------------*/
607 /*! \name String/Stream IO (Input) */
608 /*! \{ */
610 /*! \} */
611 /*---------------------------------------------------------------------*/
612 /*! \name Set */
613 /*! \{ */
615 #ifdef OSG_FIELD_TOCHECK
616 void setValues(const StorageType &value);
617 void setValues(const StorageTypeParent &value);
618 void setValues(const Self &obj );
619 #endif
621 /*! \} */
622 /*---------------------------------------------------------------------*/
623 /*! \name Binary Interface */
624 /*! \{ */
626 void copyFromBin(BinaryDataHandler &pMem);
628 /*! \} */
629 /*---------------------------------------------------------------------*/
630 /*! \name STL Interface */
631 /*! \{ */
633 iterator begin_nc(void );
634 iterator end_nc (void );
636 #ifndef OSG_CLEAN_FCFIELDS
637 reference front_nc(void );
638 reference back_nc (void );
639 #endif
641 iterator find_nc (const_value value);
643 /*! \} */
644 /*---------------------------------------------------------------------*/
645 /*! \name Std Library Interface */
646 /*! \{ */
648 #ifndef OSG_CLEAN_FCFIELDS
649 iterator begin (void );
650 iterator end (void );
652 reverse_iterator rbegin (void );
653 reverse_iterator rend (void );
654 #endif
656 const_iterator begin (void ) const;
657 const_iterator end (void ) const;
659 const_reverse_iterator rbegin (void ) const;
660 const_reverse_iterator rend (void ) const;
662 #ifndef OSG_CLEAN_FCFIELDS
663 reference front (void );
664 reference back (void );
665 #endif
667 const_value front (void ) const;
668 const_value back (void ) const;
670 iterator insert (iterator pos,
671 const_value value );
673 void insert (iterator pos,
674 size_type n,
675 const_value value );
677 template <class InputIteratorT>
678 void insert (iterator pos,
679 InputIteratorT first,
680 InputIteratorT last );
682 void erase (size_type index );
683 #ifndef OSG_CLEAN_FCFIELDS
684 iterator erase (iterator pos );
685 iterator erase (iterator first,
686 iterator last );
687 #endif
689 #ifndef OSG_CLEAN_FCFIELDS
690 iterator find (const_value value );
691 #endif
692 const_iterator find (const_value value ) const;
694 void push_back(const_value value );
696 void resize (size_t newSize,
697 const_value value = NULL );
699 void reserve (size_type newSize );
701 void clear (void );
703 #ifdef OSG_1_COMPAT
704 void addValue (const_value value );
705 #endif
707 void assign (size_type newSize,
708 const_value value = NULL );
710 template <class InputIteratorT>
711 void assign (InputIteratorT first,
712 InputIteratorT last );
714 void replace (UInt32 uiIdx,
715 const_value value );
717 void replace (iterator pos,
718 const_value value );
720 /*! \} */
721 /*---------------------------------------------------------------------*/
722 /*! \name Index Operator */
723 /*! \{ */
725 #ifndef OSG_CLEAN_FCFIELDS
726 reference operator [](size_type const index);
727 #endif
728 const_value operator [](size_type const index) const;
730 /*! \} */
731 /*---------------------------------------------------------------------*/
732 /*! \name Compare */
733 /*! \{ */
735 bool operator ==(const Self &source) const;
737 /*! \} */
738 /*---------------------------------------------------------------------*/
739 /*! \name Assignment */
740 /*! \{ */
742 Self &operator =(Self const &source);
744 /*! \} */
745 /*---------------------------------------------------------------------*/
746 /*! \name MT Sync */
747 /*! \{ */
749 #ifdef OSG_MT_CPTR_ASPECT
750 void syncWith(Self &source,
751 ConstFieldMaskArg syncMode,
752 UInt32 uiSyncInfo,
753 AspectOffsetStore &oOffsets );
754 #endif
756 /*! \} */
757 /*========================= PROTECTED ===============================*/
759 protected:
761 /*---------------------------------------------------------------------*/
762 /*! \name Members */
763 /*! \{ */
765 static FieldType _fieldType;
767 /*! \} */
768 /*---------------------------------------------------------------------*/
769 /*! \name FieldDesc creation */
770 /*! \{ */
772 static FieldDescriptionBase *
773 createFieldDescription (const Char8 *szFieldname,
774 UInt32 uiFieldFlags,
775 FieldEditMethod fEditMethod,
776 FieldGetMethod fGetMethod );
778 static FieldDescriptionBase *
779 createIdxFieldDescription(const Char8 *szFieldname,
780 UInt32 uiFieldFlags,
781 FieldIndexEditMethod fEditMethod,
782 FieldIndexGetMethod fGetMethod );
784 /*! \} */
785 /*========================== PRIVATE ================================*/
787 private:
790 OSG_END_NAMESPACE
792 #include "OSGPointerMField.inl"
794 #endif // _OSGPOINTERMFIELD_H_