fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Fields / Handle / OSGFieldContainerMFieldHandle.inl
blob9c72347c530dd402e052c120c1d6493f5dc131fe
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *           Copyright (C) 2003 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 /*---------------------------------------------------------------------------*/
42 /* GetMFieldHandle<FieldContainerPtrMFieldBase>                              */
43 /*---------------------------------------------------------------------------*/
45 /*---------------------------------------------------------------------------*/
46 /* Constructors                                                              */
48 inline
49 GetMFieldHandle<FieldContainerPtrMFieldBase>::GetMFieldHandle(
50     const GetMFieldHandle &source) :
52     Inherited(source)
56 inline
57 GetMFieldHandle<FieldContainerPtrMFieldBase>::GetMFieldHandle(
58     const FieldContainerPtrMFieldBase *pField, 
59     const FieldDescriptionBase        *pDescription,
60           FieldContainer              *pContainer  ) :
62     Inherited(pField, pDescription, pContainer)
66 inline
67 const FieldType &
68     GetMFieldHandle<FieldContainerPtrMFieldBase>::getType(void) const
70     return FieldContainerPtrMFieldBase::getClassType();
74 inline
75 bool GetMFieldHandle<FieldContainerPtrMFieldBase>::isPointerField(void) const
77     return true;
81 inline
82 void GetMFieldHandle<FieldContainerPtrMFieldBase>::pushValueToStream(
83     OutStream &str) const
85     FWARNING(("illegal pushValueToStream called for %s\n", 
86               this->getName().c_str()));
87     OSG_ASSERT(false);
91 inline
92 void GetMFieldHandle<FieldContainerPtrMFieldBase>::pushIndexedValueToStream(
93     OutStream &str, 
94     UInt32     index) const
96     FWARNING(("illegal pushIndexedValueToStream called for %s\n", 
97               this->getName().c_str()));
98     OSG_ASSERT(false);
101 inline
102 void GetMFieldHandle<FieldContainerPtrMFieldBase>::pushSizeToStream(
103     OutStream &str) const
105     FWARNING(("illegal pushSizeToStream called for %s\n", 
106               this->getName().c_str()));
107     OSG_ASSERT(false);
110 inline
111 bool GetMFieldHandle<FieldContainerPtrMFieldBase>::equal(
112     Inherited::Ptr rhs) const
114     Ptr pOther = boost::dynamic_pointer_cast<GetMFieldHandle>(rhs);
116     if(pOther == NULL)
117     {
118         return false;
119     }
120     
121     const FieldContainerPtrMFieldBase *pLhs = 
122         static_cast<const FieldContainerPtrMFieldBase *>(        _pField);
124     const FieldContainerPtrMFieldBase *pRhs = 
125         static_cast<const FieldContainerPtrMFieldBase *>(pOther->_pField);
127     return (*pLhs) == (*pRhs);
130 inline
131 const FieldContainerPtrMFieldBase *
132     GetMFieldHandle<FieldContainerPtrMFieldBase>::getField(void)
134     return static_cast<const FieldContainerPtrMFieldBase *>(_pField);
137 inline
138 const FieldContainerPtrMFieldBase *
139     GetMFieldHandle<FieldContainerPtrMFieldBase>::operator ->(void)
141     return static_cast<const FieldContainerPtrMFieldBase *>(_pField);
144 inline
145 const FieldContainerPtrMFieldBase &
146     GetMFieldHandle<FieldContainerPtrMFieldBase>::operator * (void)
148     return *(static_cast<const FieldContainerPtrMFieldBase *>(_pField));
151 /*---------------------------------------------------------------------------*/
152 /* EditMFieldHandle<FieldContainerPtrMFieldBase>                             */
153 /*---------------------------------------------------------------------------*/
155 /*---------------------------------------------------------------------------*/
156 /* Constructors                                                              */
158 inline
159 EditMFieldHandle<FieldContainerPtrMFieldBase>::EditMFieldHandle(
160     const EditMFieldHandle &source) :
161     
162      Inherited (source            ),
163     _bStoreless(source._bStoreless)
167 inline
168 EditMFieldHandle<FieldContainerPtrMFieldBase>::EditMFieldHandle(      
169           FieldContainerPtrMFieldBase *pField, 
170     const FieldDescriptionBase        *pDescription,
171           FieldContainer              *pContainer  ) :
173      Inherited (pField, 
174                 pDescription,
175                 pContainer  ),
176     _bStoreless(false       )
180 inline
181 bool EditMFieldHandle<FieldContainerPtrMFieldBase>::isValid(void) const
183     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
185     return 
186         ( (_pField     != NULL)                                      || 
187          ((_bStoreless == true) && (0x0000 != (accessFlags & 
188                                                Field::FCustomAccess))));
191 inline
192 void EditMFieldHandle<FieldContainerPtrMFieldBase>::setStoreless(void)
194     _bStoreless = true;
197 /*---------------------------------------------------------------------------*/
198 /* Field Type Query                                                          */
200 inline
201 const FieldType & 
202     EditMFieldHandle<FieldContainerPtrMFieldBase>::getType(void) const
204     return FieldContainerPtrMFieldBase::getClassType();
207 inline
208 bool EditMFieldHandle<FieldContainerPtrMFieldBase>::isPointerField(void) const
210     return true;
213 /*---------------------------------------------------------------------------*/
214 /* Stream/String IO                                                          */
216 inline
217 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushValueToStream(
218     OutStream &str) const
220     FWARNING(("illegal pushValueToStream called for %s\n", 
221               this->getName().c_str()));
222     OSG_ASSERT(false);
225 inline
226 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushSizeToStream(
227     OutStream &str) const
229     FWARNING(("illegal pushSizeToStream called for %s\n", 
230               this->getName().c_str()));
231     OSG_ASSERT(false);
234 inline
235 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushIndexedValueToStream(
236     OutStream &str, 
237     UInt32     index) const
239     FWARNING(("illegal pushIndexedValueToStream called for %s\n", 
240               this->getName().c_str()));
241     OSG_ASSERT(false);
244 inline
245 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushValueFromCString(
246     const Char8 *str)
248     FWARNING(("illegal pushValueFromCString called for %s\n", 
249               this->getName().c_str()));
250     OSG_ASSERT(false);
253 inline
254 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushIndexedValueFromCString(
255     const Char8  *str, 
256           UInt32  index)
258     FWARNING(("illegal pushIndexedValueFromCString called for %s\n", 
259               this->getName().c_str()));
260     OSG_ASSERT(false);
263 /*---------------------------------------------------------------------------*/
264 /* Comparison                                                                */
266 inline
267 bool EditMFieldHandle<FieldContainerPtrMFieldBase>::equal(
268     Inherited::Ptr rhs) const
270     Ptr pOther = boost::dynamic_pointer_cast<EditMFieldHandle>(rhs);
272     if(pOther == NULL)
273     {
274         return false;
275     }
277     FieldContainerPtrMFieldBase *pLhs = 
278         static_cast<FieldContainerPtrMFieldBase *>(        _pField);
280     FieldContainerPtrMFieldBase *pRhs = 
281         static_cast<FieldContainerPtrMFieldBase *>(pOther->_pField);
283     return (*pLhs) == (*pRhs);
286 /*---------------------------------------------------------------------------*/
287 /* Copy/Share/Clone                                                          */
289 inline
290 void EditMFieldHandle<FieldContainerPtrMFieldBase>::copyValues(
291     GetFieldHandlePtr source) const
293     FWARNING(("illegal copyValues called for %s\n", 
294               this->getName().c_str()));
295     OSG_ASSERT(false);
298 inline
299 void EditMFieldHandle<FieldContainerPtrMFieldBase>::shareValues(
300     GetFieldHandlePtr source) const
302     OSG_ASSERT(false);
306 inline
307 void EditMFieldHandle<FieldContainerPtrMFieldBase>::cloneValues(
308           GetFieldHandlePtr  pSrc,
309     const TypePtrVector     &shareTypes,
310     const TypePtrVector     &ignoreTypes,
311     const TypeIdVector      &shareGroupIds,
312     const TypeIdVector      &ignoreGroupIds) const
314     OSG_ASSERT(false);
317 /*---------------------------------------------------------------------------*/
318 /* GetFCPtrMFieldHandle<FieldT>                                              */
319 /*---------------------------------------------------------------------------*/
321 /*---------------------------------------------------------------------------*/
322 /* Constructors                                                              */
324 template <class FieldT> inline
325 GetFCPtrMFieldHandle<FieldT>::GetFCPtrMFieldHandle(
326     const GetFCPtrMFieldHandle &source) :
328     Inherited(source)
332 template <class FieldT> inline
333 GetFCPtrMFieldHandle<FieldT>::GetFCPtrMFieldHandle(
334     const FieldT               *pField, 
335     const FieldDescriptionBase *pDescription,
336           FieldContainer       *pContainer  ) :
338     Inherited(pField, pDescription, pContainer)
342 /*---------------------------------------------------------------------------*/
343 /* Field Type Query                                                          */
345 template <class FieldT> inline
346 const FieldType &GetFCPtrMFieldHandle<FieldT>::getType(void) const
348     return FieldT::getClassType();
351 /*---------------------------------------------------------------------------*/
352 /* Stream/String IO                                                          */
354 template <class FieldT> inline
355 void GetFCPtrMFieldHandle<FieldT>::pushValueToStream(OutStream &str) const
357     FWARNING(("illegal pushValueToStream called for %s\n", 
358               this->getName().c_str()));
359 //    OSG_ASSERT(false);
361     for(OSG::SizeT i = 0; i < this->size(); ++i)
362     {
363         str << this->get(i) << " ";
364     }
367 template <class FieldT> inline
368 void GetFCPtrMFieldHandle<FieldT>::pushSizeToStream(OutStream &str) const
370     FWARNING(("illegal pushSizeToStream called for %s\n", 
371               this->getName().c_str()));
372     OSG_ASSERT(false);
375 /*---------------------------------------------------------------------------*/
376 /* Access                                                                    */
378 template <class FieldT> inline
379 FieldContainer *GetFCPtrMFieldHandle<FieldT>::get(SizeT index) const
381     return (*dcast_const())[index];
384 template <class FieldT> inline
385 SizeT GetFCPtrMFieldHandle<FieldT>::size(void) const
387     return dcast_const()->size();
390 template <class FieldT>
391 Int32 GetFCPtrMFieldHandle<FieldT>::find(FieldContainer *existingFC) const
393     Int32                        retVal          = -1;
394     typename FieldT::const_value typedExistingFC =
395         dynamic_cast<typename FieldT::const_value>(existingFC);
396     BitVector                    accessFlags     =
397         _pDescription->getFlags() & Field::FAccessMask;
399     if(0x0000 != (accessFlags & Field::FCustomAccess) ||
400        0x0000 != (accessFlags & Field::FStdAccess   )   )
401     {
402         if(typedExistingFC != NULL || existingFC == NULL)
403         {
404             retVal = dcast_const()->findIndex(typedExistingFC);
405         }
406     }
407     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
408     {
409         retVal = dcast_const()->findIndex(typedExistingFC);
410     }
411     else
412     {
413         // this should never happen
414         FFATAL(("GetFCPtrMFieldHandle<FieldT>::find: Field has unknown access.\n"));
415     }
416         
417     return retVal;
420 template <class FieldT> inline
421 const FieldT *GetFCPtrMFieldHandle<FieldT>::getField(void)
423     return dcast_const();
426 template <class FieldT> inline
427 const FieldT *GetFCPtrMFieldHandle<FieldT>::operator ->(void)
429     return dcast_const();
432 template <class FieldT> inline
433 const FieldT &GetFCPtrMFieldHandle<FieldT>::operator * (void)
435     return *dcast_const();
438 /*---------------------------------------------------------------------------*/
439 /* Private Helper                                                            */
441 template <class FieldT> inline
442 const typename GetFCPtrMFieldHandle<FieldT>::HandledField *
443     GetFCPtrMFieldHandle<FieldT>::dcast_const(void) const
445     return static_cast<const HandledField *>(_pField);
448 /*---------------------------------------------------------------------------*/
449 /* EditFCPtrMFieldHandle<FieldT>                                             */
450 /*---------------------------------------------------------------------------*/
452 /*---------------------------------------------------------------------------*/
453 /* Constructors                                                              */
455 template <class FieldT> inline
456 EditFCPtrMFieldHandle<FieldT>::EditFCPtrMFieldHandle(
457     const EditFCPtrMFieldHandle &source) :
458     
459      Inherited         (source                   ),
460      _fAddMethod       (source._fAddMethod       ),
461      _fRemoveMethod    (source._fRemoveMethod    ),
462      _fRemoveObjMethod (source._fRemoveObjMethod ),
463      _fInsertMethod    (source._fInsertMethod    ),
464      _fReplaceMethod   (source._fReplaceMethod   ),
465      _fReplaceObjMethod(source._fReplaceObjMethod),
466      _fClearMethod     (source._fClearMethod     )
470 template <class FieldT> inline
471 EditFCPtrMFieldHandle<FieldT>::EditFCPtrMFieldHandle( 
472           FieldT               *pField, 
473     const FieldDescriptionBase *pDescription,
474           FieldContainer       *pContainer  ) :
476      Inherited         (pField, 
477                         pDescription,
478                         pContainer  ),
479      _fAddMethod       (            ),
480      _fRemoveMethod    (            ),
481      _fRemoveObjMethod (            ),
482      _fInsertMethod    (            ),
483      _fReplaceMethod   (            ),
484      _fReplaceObjMethod(            ),
485      _fClearMethod     (            )
489 /*---------------------------------------------------------------------------*/
490 /* Field Type Query                                                          */
492 template <class FieldT> inline
493 const FieldType &EditFCPtrMFieldHandle<FieldT>::getType(void) const
495     return FieldT::getClassType();
498 /*! Returns whether the edited field supports addition of values.
499  */
500 template <class FieldT> inline
501 bool EditFCPtrMFieldHandle<FieldT>::supportsAdd(void) const
503     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
505     return
506         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
507           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
508          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
509           !_fAddMethod.empty()                                 )   );
512 /*! Returns whether the edited field supports removal of values by index.
513  */
514 template <class FieldT> inline
515 bool EditFCPtrMFieldHandle<FieldT>::supportsRemove(void) const
517     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
519     return
520         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
521           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
522          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
523           !_fRemoveMethod.empty()                                 )   );
526 /*! Returns whether the edited field supports removal of values by object.
527  */
528 template <class FieldT> inline
529 bool EditFCPtrMFieldHandle<FieldT>::supportsRemoveObject(void) const
531     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
533     return
534         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
535           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
536          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
537           !_fRemoveObjMethod.empty()                              )   );
540 /*! Returns whether the edited field supports insertion of values.
541  */
542 template <class FieldT> inline
543 bool EditFCPtrMFieldHandle<FieldT>::supportsInsert(void) const
545     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
547     return 
548         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
549           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
550          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
551           !_fInsertMethod.empty()                                 )   );
554 /*! Returns whether the edited field supports replacement of values by index.
555  */
556 template <class FieldT> inline
557 bool EditFCPtrMFieldHandle<FieldT>::supportsReplace(void) const
559     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
561     return
562         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
563           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
564          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
565           !_fReplaceMethod.empty()                                )   );
568 /*! Returns whether the edited field supports replacement of values by object.
569  */
570 template <class FieldT> inline
571 bool EditFCPtrMFieldHandle<FieldT>::supportsReplaceObject(void) const
573     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
575     return
576         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
577           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
578          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
579           !_fReplaceObjMethod.empty()                                )   );
582 /*! Returns whether the edited field supports clearing of values.
583  */
584 template <class FieldT> inline
585 bool EditFCPtrMFieldHandle<FieldT>::supportsClear(void) const
587     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
589     return
590         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
591           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
592          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
593           !_fClearMethod.empty()                                  )   );
596 /*---------------------------------------------------------------------------*/
597 /* Access                                                                    */
599 /*! Returns the value stored at \a index in the edited field; no range checking
600     is performed on \a index.
601  */
602 template <class FieldT> inline
603 FieldContainer *EditFCPtrMFieldHandle<FieldT>::get(SizeT index) const
605     return (*dcast_const())[index];
608 /*! Returns the number of elements stored in the edited field.
609  */
610 template <class FieldT> inline
611 SizeT EditFCPtrMFieldHandle<FieldT>::size(void) const
613     return dcast_const()->size();
616 /*! Returns the (first) index of \a existingFC in the edited field or -1 if it
617     can not be found.
618  */
619 template <class FieldT>
620 Int32 EditFCPtrMFieldHandle<FieldT>::find(FieldContainer *existingFC) const
622     Int32                        retVal          = -1;
623     typename FieldT::const_value typedExistingFC =
624         dynamic_cast<typename FieldT::const_value>(existingFC);
625     BitVector                    accessFlags     =
626         _pDescription->getFlags() & Field::FAccessMask;
628     if(0x0000 != (accessFlags & Field::FCustomAccess) ||
629        0x0000 != (accessFlags & Field::FStdAccess   )   )
630     {
631         if(typedExistingFC != NULL || existingFC == NULL)
632         {
633             retVal = dcast_const()->findIndex(typedExistingFC);
634         }
635     }
636     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
637     {
638         retVal = dcast_const()->findIndex(typedExistingFC);
639     }
640     else
641     {
642         // this should never happen
643         FFATAL(("EditFCPtrMFieldHandle<%s>::find: Field has unknown "
644                 "access.\n", typeid(FieldT).name()                   ));
645     }
646         
647     return retVal;
650 /*! Adds \a newFC to the edited field and returns \c true iff successful.
652     \note This operation is only available if \c supportsAdd returns \c true.
653  */
654 template <class FieldT>
655 bool EditFCPtrMFieldHandle<FieldT>::add(FieldContainer *newFC) const
657     bool                         retVal      = false;
658     typename FieldT::const_value typedNewFC  =
659         dynamic_cast<typename FieldT::const_value>(newFC);
660     BitVector                    accessFlags =
661         _pDescription->getFlags() & Field::FAccessMask;
663     if(0x0000 != (accessFlags & Field::FCustomAccess))
664     {
665         if(typedNewFC != NULL || newFC == NULL)
666         {
667             if(!_fAddMethod.empty())
668             {
669                 _fAddMethod(typedNewFC);
670                 retVal = true;
671             }
672             else
673             {
674                 FFATAL(("EditFCPtrMFieldHandle<%s>::add called, but "
675                         "_fAddMethod is not set.\n", typeid(FieldT).name()));
676             }
677         }
678     }
679     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
680     {
681         if(typedNewFC != NULL)
682         {
683             dcast()->push_back(typedNewFC);
684             retVal = true;
685         }
686     }
687     else if(0x0000 != (accessFlags & Field::FStdAccess))
688     {
689         if(typedNewFC != NULL || newFC == NULL)
690         {
691             dcast()->push_back(typedNewFC);
692             retVal = true;
693         }
694     }
695     else
696     {
697         // this should never happen
698         FFATAL(("EditFCPtrMFieldHandle<%s>::add: Field has unknown "
699                 "access.\n", typeid(FieldT).name()                  ));
700     }
702     return retVal;
705 /*! Removes the value at \a index from the edited field and returns \c true
706     iff successful; no range checking is performed on \a index.
707     
708     \note This operation is only available if \c supportsRemove returns \c true.
709  */
710 template <class FieldT>
711 bool EditFCPtrMFieldHandle<FieldT>::remove(UInt32 index) const
713     bool      retVal      = false;
714     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
715     
716     if(0x0000 != (accessFlags & Field::FCustomAccess))
717     {
718         if(!_fRemoveMethod.empty())
719         {
720             _fRemoveMethod(index);
721             retVal = true;
722         }
723         else
724         {
725             FFATAL(("EditFCPtrMFieldHandle<%s>::remove called, but "
726                     "_fRemoveMethod is not set.\n", typeid(FieldT).name()));
727         }
728     }
729     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
730     {
731         dcast()->erase(index);
732         retVal = true;
733     }
734     else if(0x0000 != (accessFlags & Field::FStdAccess))
735     {
736         dcast()->erase(index);
737         retVal = true;
738     }
739     else
740     {
741         // this should never happen
742         FFATAL(("EditFCPtrMFieldHandle<%s>::remove: Field has unknown "
743                 "access.\n", typeid(FieldT).name()                     ));
744     }
746     return retVal;
749 /*! Removes the given \a existingFC from the edited field and returns \c true
750     iff successful.
751     
752     \note This operation is only available if \c supportsRemoveObject
753           returns \c true.
754  */
755 template <class FieldT>
756 bool EditFCPtrMFieldHandle<FieldT>::removeObject(
757     FieldContainer *existingFC) const
759     bool                         retVal          = false;
760     typename FieldT::const_value typedExistingFC =
761         dynamic_cast<typename FieldT::const_value>(existingFC);
762     BitVector                    accessFlags     =
763         _pDescription->getFlags() & Field::FAccessMask;
765     if(0x0000 != (accessFlags & Field::FCustomAccess))
766     {
767         if(typedExistingFC != NULL || existingFC == NULL)
768         {
769             if(!_fRemoveObjMethod.empty())
770             {
771                 _fRemoveObjMethod(typedExistingFC);
772                 retVal = true;
773             }
774             else
775             {
776                 FFATAL(("EditFCPtrMFieldHandle<%s>::removeObject called, "
777                         "but _fRemoveObjMethod is not set.\n", 
778                         typeid(FieldT).name()                             ));
779             }
780         }
781     }
782     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
783     {
784         if(typedExistingFC != NULL)
785         {
786             Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
787         
788             if(iElemIdx != -1)
789             {
790                 dcast()->erase(iElemIdx);
791                 retVal = true;
792             }
793         }
794     }
795     else if(0x0000 != (accessFlags & Field::FStdAccess))
796     {
797         if(typedExistingFC != NULL || existingFC == NULL)
798         {
799             Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
800         
801             if(iElemIdx != -1)
802             {
803                 dcast()->erase(iElemIdx);
804                 retVal = true;
805             }
806         }
807     }
808     else
809     {
810         // this should never happen
811         FFATAL(("EditFCPtrMFieldHandle<%s>::removeObject: Field has unknown "
812                 "access.\n", typeid(FieldT).name()));
813     }
815     return retVal;
818 /*! Inserts the value \a newFC at \a index into the edited field and returns
819     \c true iff successful; no range checking is performed on \a index.
820     
821     \note This operation is only available if \c supportsInsert returns \c true.
822  */
823 template <class FieldT>
824 bool EditFCPtrMFieldHandle<FieldT>::insert(
825     UInt32 index, FieldContainer *newFC) const
827     bool                         retVal      = false;
828     typename FieldT::const_value typedNewFC  =
829         dynamic_cast<typename FieldT::const_value>(newFC);
830     BitVector                    accessFlags =
831         _pDescription->getFlags() & Field::FAccessMask;
832         
833     if(0x0000 != (accessFlags & Field::FCustomAccess))
834     {
835         if(typedNewFC != NULL || newFC == NULL)
836         {
837             if(!_fInsertMethod.empty())
838             {
839                 _fInsertMethod(index, typedNewFC);
840                 retVal = true;
841             }
842             else
843             {
844                 FFATAL(("EditFCPtrMFieldHandle<%s>::insert called, but "
845                         "_fInsertMethod is not set.\n", typeid(FieldT).name()));
846             }
847         }
848     }
849     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
850     {
851         if(typedNewFC != NULL)
852         {
853             dcast()->insert(dcast()->begin_nc() + index, typedNewFC);
854             retVal = true;
855         }
856     }
857     else if(0x0000 != (accessFlags & Field::FStdAccess))
858     {
859         if(typedNewFC != NULL || newFC == NULL)
860         {
861             dcast()->insert(dcast()->begin_nc() + index, typedNewFC);
862             retVal = true;
863         }
864     }
865     else
866     {
867         // this should never happen
868         FFATAL(("EditFCPtrMFieldHandle<%s>::insert: Field has unknown "
869                 " access.\n", typeid(FieldT).name()                    ));
870     }
872     return retVal;
875 /*! Replaces the value at \a index with \a newFC in the edited field and returns
876     \c true iff successful; no range checking is performed on \a index.
877     
878     \note This operation is only available if \c supportsReplace returns \c true.
879  */
880 template <class FieldT>
881 bool EditFCPtrMFieldHandle<FieldT>::replace(
882     UInt32 index, FieldContainer *newFC) const
884     bool                         retVal      = false;
885     typename FieldT::const_value typedNewFC  =
886         dynamic_cast<typename FieldT::const_value>(newFC);
887     BitVector                    accessFlags =
888         _pDescription->getFlags() & Field::FAccessMask;
889         
890     if(0x0000 != (accessFlags & Field::FCustomAccess))
891     {
892         if(typedNewFC != NULL || newFC == NULL)
893         {
894             if(!_fReplaceMethod.empty())
895             {
896                 _fReplaceMethod(index, typedNewFC);
897                 retVal = true;
898             }
899             else
900             {
901                 FFATAL(("EditFCPtrMFieldHandle<%s>::replace called, but "
902                         "_fReplaceMethod is not set.\n", 
903                         typeid(FieldT).name()));
904             }
905         }
906     }
907     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
908     {
909         if(typedNewFC != NULL)
910         {
911             dcast()->replace(index, typedNewFC);
912             retVal = true;
913         }
914     }
915     else if(0x0000 != (accessFlags & Field::FStdAccess))
916     {
917         if(typedNewFC != NULL || newFC == NULL)
918         {
919             dcast()->replace(index, typedNewFC);
920             retVal = true;
921         }
922     }
923     else
924     {
925         // this should never happen
926         FFATAL(("EditFCPtrMFieldHandle<%s>::replace: Field has unknown "
927                 "access.\n", typeid(FieldT).name()                      ));
928     }
930     return retVal;
933 /*! Replaces the value \a existingFC with \a newFC in the edited field and
934     returns \c true iff successful.
935     
936     \note This operation is only available if \c supportsReplaceObject
937           returns \c true.
938  */
939 template <class FieldT>
940 bool EditFCPtrMFieldHandle<FieldT>::replaceObject(
941     FieldContainer *existingFC, FieldContainer *newFC) const
943     bool                         retVal          = false;
944     typename FieldT::const_value typedExistingFC =
945         dynamic_cast<typename FieldT::const_value>(existingFC);
946     typename FieldT::const_value typedNewFC      =
947         dynamic_cast<typename FieldT::const_value>(newFC);
948     BitVector                    accessFlags     =
949         _pDescription->getFlags() & Field::FAccessMask;
950         
951     if(0x0000 != (accessFlags & Field::FCustomAccess))
952     {
953         if((typedExistingFC != NULL || existingFC == NULL) &&
954            (typedNewFC      != NULL || newFC      == NULL)   )
955         {
956             if(!_fReplaceObjMethod.empty())
957             {
958                 _fReplaceObjMethod(typedExistingFC, typedNewFC);
959                 retVal = true;
960             }
961             else
962             {
963                 FFATAL(("EditFCPtrMFieldHandle<%s>::replaceObject called, "
964                         "but _fReplaceMethod is not set.\n", 
965                         typeid(FieldT).name()));
966             }
967         }
968     }
969     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
970     {
971         if((typedExistingFC != NULL) && (typedNewFC != NULL))
972         {
973             Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
974         
975             if(iElemIdx != -1)
976             {
977                 dcast()->replace(iElemIdx, typedNewFC);
978                 retVal = true;
979             }
980         }
981     }
982     else if(0x0000 != (accessFlags & Field::FStdAccess))
983     {
984         if((typedExistingFC != NULL || existingFC == NULL) &&
985            (typedNewFC      != NULL || newFC      == NULL)   )
986         {
987             Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
988         
989             if(iElemIdx != -1)
990             {
991                 dcast()->replace(iElemIdx, typedNewFC);
992                 retVal = true;
993             }
994         }
995     }
996     else
997     {
998         // this should never happen
999         FFATAL(("EditFCPtrMFieldHandle<%s>::replaceObject: Field has unknown "
1000                 "access.\n", typeid(FieldT).name()));
1001     }
1003     return retVal;
1006 /*! Clears the edited field and returns \c true iff successful.
1008     \note This operation is only available if \c supportsClear returns \c true.
1009  */
1010 template <class FieldT>
1011 bool EditFCPtrMFieldHandle<FieldT>::clear(void) const
1013     bool      retVal      = false;
1014     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
1015     
1016     if(0x0000 != (accessFlags & Field::FCustomAccess))
1017     {
1018         if(!_fClearMethod.empty())
1019         {
1020             _fClearMethod();
1021             retVal = true;
1022         }
1023         else
1024         {
1025             FFATAL(("EditFCPtrMFieldHandle<%s>::clear called, but "
1026                     "_fClearMethod is not set.\n", typeid(FieldT).name()));
1027         }
1028     }
1029     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
1030     {
1031         dcast()->clear();
1032         retVal = true;
1033     }
1034     else if(0x0000 != (accessFlags & Field::FStdAccess))
1035     {
1036         dcast()->clear();
1037         retVal = true;
1038     }
1039     else
1040     {
1041         // this should never happen
1042         FFATAL(("EditFCPtrMFieldHandle<%s>::clear: Field has unknown "
1043                 "access.\n", typeid(FieldT).name()                    ));
1044     }
1046     return retVal;
1049 /*---------------------------------------------------------------------------*/
1050 /* Stream/String IO                                                          */
1052 template <class FieldT> inline
1053 void EditFCPtrMFieldHandle<FieldT>::pushValueToStream(OutStream &str) const
1055     FWARNING(("illegal pushValueToStream called for %s\n", 
1056               this->getName().c_str()));
1057     OSG_ASSERT(false);
1060 template <class FieldT> inline
1061 void EditFCPtrMFieldHandle<FieldT>::pushSizeToStream(OutStream &str) const
1063     FWARNING(("illegal pushSizeToStream called for %s\n", 
1064               this->getName().c_str()));
1065     OSG_ASSERT(false);
1068 template <class FieldT> inline
1069 void EditFCPtrMFieldHandle<FieldT>::pushValueFromCString(const Char8 *str)
1071     FWARNING(("illegal pushValueFromCString called for %s\n", 
1072               this->getName().c_str()));
1073     OSG_ASSERT(false);
1076 /*---------------------------------------------------------------------------*/
1077 /* Callback Setup                                                            */
1079 template <class FieldT> inline
1080 void EditFCPtrMFieldHandle<FieldT>::setAddMethod(AddMethod fMethod)
1082     _fAddMethod = fMethod;
1085 template <class FieldT> inline
1086 void EditFCPtrMFieldHandle<FieldT>::setRemoveMethod(RemoveMethod fMethod)
1088     _fRemoveMethod = fMethod;
1091 template <class FieldT> inline
1092 void EditFCPtrMFieldHandle<FieldT>::setRemoveObjMethod(RemoveObjMethod fMethod)
1094     _fRemoveObjMethod = fMethod;
1097 template <class FieldT> inline
1098 void EditFCPtrMFieldHandle<FieldT>::setInsertMethod(InsertMethod fMethod)
1100     _fInsertMethod = fMethod;
1103 template <class FieldT> inline
1104 void EditFCPtrMFieldHandle<FieldT>::setReplaceMethod(ReplaceMethod fMethod)
1106     _fReplaceMethod = fMethod;
1109 template <class FieldT> inline
1110 void EditFCPtrMFieldHandle<FieldT>::setReplaceObjMethod(
1111     ReplaceObjMethod fMethod)
1113     _fReplaceObjMethod = fMethod;
1116 template <class FieldT> inline
1117 void EditFCPtrMFieldHandle<FieldT>::setClearMethod(ClearMethod fMethod)
1119     _fClearMethod = fMethod;
1122 /*---------------------------------------------------------------------------*/
1123 /* Copy/Share/Clone                                                          */
1125 template <class FieldT> inline
1126 void EditFCPtrMFieldHandle<FieldT>::copyValues(GetFieldHandlePtr source) const
1128     FWARNING(("illegal copyValues called for %s\n", 
1129               this->getName().c_str()));
1130     OSG_ASSERT(false);
1133 template <class FieldT> inline
1134 void EditFCPtrMFieldHandle<FieldT>::shareValues(GetFieldHandlePtr source) const
1136     typename Self::GetMFHandlePtr pSrcBase = 
1137         boost::dynamic_pointer_cast<GetMFHandle>(source);
1139     FieldContainerUnrecPtr pDst = NULL;
1141     if(pSrcBase != NULL && pSrcBase->isValid() == true)
1142     {
1143         const FieldContainerPtrMFieldBase *pSrcField = pSrcBase->getField();
1144             
1145         for(SizeT i = 0; i < pSrcField->size(); ++i)
1146         {
1147             this->add((*pSrcField)[i]);
1148         }
1149     }
1150     else
1151     {
1152         FWARNING(("shareValues illegal source for %s\n", 
1153                   this->getName().c_str()));
1154     }
1157 template <class FieldT> inline
1158 void EditFCPtrMFieldHandle<FieldT>::cloneValues(
1159               GetFieldHandlePtr  pSrc,
1160         const TypePtrVector     &shareTypes,
1161         const TypePtrVector     &ignoreTypes,
1162         const TypeIdVector      &shareGroupIds,
1163         const TypeIdVector      &ignoreGroupIds) const
1165     typename Self::GetMFHandlePtr pSrcBase = 
1166         boost::dynamic_pointer_cast<GetMFHandle>(pSrc);
1168     FieldContainerUnrecPtr pDst = NULL;
1170     if(pSrcBase != NULL && pSrcBase->isValid() == true)
1171     {
1172         const FieldContainerPtrMFieldBase *pSrcField = pSrcBase->getField();
1173             
1174         for(SizeT i = 0; i < pSrcField->size(); ++i)
1175         {
1176             StoredPtrType pSrcTyped = 
1177                 dynamic_cast<StoredPtrType>((*pSrcField)[i]);
1179             if(pSrcTyped != NULL)
1180             {
1181                 pDst = deepClone(pSrcTyped,
1182                                  shareTypes,
1183                                  ignoreTypes,
1184                                  shareGroupIds,
1185                                  ignoreGroupIds);
1186             }
1187             else
1188             {
1189                 pDst = NULL;
1190             }
1191             
1192             this->add(pDst);
1193         }
1194     }
1195     else
1196     {
1197         FWARNING(("cloneValues illegal source for %s\n", 
1198                   this->getName().c_str()));
1199     }
1202 /*---------------------------------------------------------------------------*/
1203 /* Private Helper                                                            */
1205 template <class FieldT> inline
1206 typename EditFCPtrMFieldHandle<FieldT>::HandledField *
1207     EditFCPtrMFieldHandle<FieldT>::dcast(void) const
1209     return static_cast<HandledField *>(_pField);
1212 template <class FieldT> inline
1213 const typename EditFCPtrMFieldHandle<FieldT>::HandledField *
1214     EditFCPtrMFieldHandle<FieldT>::dcast_const(void) const
1216     return static_cast<const HandledField *>(_pField);
1220 OSG_END_NAMESPACE