1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
41 /*---------------------------------------------------------------------------*/
42 /* GetMFieldHandle<FieldContainerPtrMFieldBase> */
43 /*---------------------------------------------------------------------------*/
45 /*---------------------------------------------------------------------------*/
49 GetMFieldHandle<FieldContainerPtrMFieldBase>::GetMFieldHandle(
50 const GetMFieldHandle &source) :
57 GetMFieldHandle<FieldContainerPtrMFieldBase>::GetMFieldHandle(
58 const FieldContainerPtrMFieldBase *pField,
59 const FieldDescriptionBase *pDescription,
60 FieldContainer *pContainer ) :
62 Inherited(pField, pDescription, pContainer)
68 GetMFieldHandle<FieldContainerPtrMFieldBase>::getType(void) const
70 return FieldContainerPtrMFieldBase::getClassType();
75 bool GetMFieldHandle<FieldContainerPtrMFieldBase>::isPointerField(void) const
82 void GetMFieldHandle<FieldContainerPtrMFieldBase>::pushValueToStream(
85 FWARNING(("illegal pushValueToStream called for %s\n",
86 this->getName().c_str()));
92 void GetMFieldHandle<FieldContainerPtrMFieldBase>::pushIndexedValueToStream(
96 FWARNING(("illegal pushIndexedValueToStream called for %s\n",
97 this->getName().c_str()));
102 void GetMFieldHandle<FieldContainerPtrMFieldBase>::pushSizeToStream(
103 OutStream &str) const
105 FWARNING(("illegal pushSizeToStream called for %s\n",
106 this->getName().c_str()));
111 bool GetMFieldHandle<FieldContainerPtrMFieldBase>::equal(
112 Inherited::Ptr rhs) const
114 Ptr pOther = boost::dynamic_pointer_cast<GetMFieldHandle>(rhs);
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);
131 const FieldContainerPtrMFieldBase *
132 GetMFieldHandle<FieldContainerPtrMFieldBase>::getField(void)
134 return static_cast<const FieldContainerPtrMFieldBase *>(_pField);
138 const FieldContainerPtrMFieldBase *
139 GetMFieldHandle<FieldContainerPtrMFieldBase>::operator ->(void)
141 return static_cast<const FieldContainerPtrMFieldBase *>(_pField);
145 const FieldContainerPtrMFieldBase &
146 GetMFieldHandle<FieldContainerPtrMFieldBase>::operator * (void)
148 return *(static_cast<const FieldContainerPtrMFieldBase *>(_pField));
151 /*---------------------------------------------------------------------------*/
152 /* EditMFieldHandle<FieldContainerPtrMFieldBase> */
153 /*---------------------------------------------------------------------------*/
155 /*---------------------------------------------------------------------------*/
159 EditMFieldHandle<FieldContainerPtrMFieldBase>::EditMFieldHandle(
160 const EditMFieldHandle &source) :
163 _bStoreless(source._bStoreless)
168 EditMFieldHandle<FieldContainerPtrMFieldBase>::EditMFieldHandle(
169 FieldContainerPtrMFieldBase *pField,
170 const FieldDescriptionBase *pDescription,
171 FieldContainer *pContainer ) :
181 bool EditMFieldHandle<FieldContainerPtrMFieldBase>::isValid(void) const
183 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
186 ( (_pField != NULL) ||
187 ((_bStoreless == true) && (0x0000 != (accessFlags &
188 Field::FCustomAccess))));
192 void EditMFieldHandle<FieldContainerPtrMFieldBase>::setStoreless(void)
197 /*---------------------------------------------------------------------------*/
198 /* Field Type Query */
202 EditMFieldHandle<FieldContainerPtrMFieldBase>::getType(void) const
204 return FieldContainerPtrMFieldBase::getClassType();
208 bool EditMFieldHandle<FieldContainerPtrMFieldBase>::isPointerField(void) const
213 /*---------------------------------------------------------------------------*/
214 /* Stream/String IO */
217 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushValueToStream(
218 OutStream &str) const
220 FWARNING(("illegal pushValueToStream called for %s\n",
221 this->getName().c_str()));
226 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushSizeToStream(
227 OutStream &str) const
229 FWARNING(("illegal pushSizeToStream called for %s\n",
230 this->getName().c_str()));
235 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushIndexedValueToStream(
239 FWARNING(("illegal pushIndexedValueToStream called for %s\n",
240 this->getName().c_str()));
245 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushValueFromCString(
248 FWARNING(("illegal pushValueFromCString called for %s\n",
249 this->getName().c_str()));
254 void EditMFieldHandle<FieldContainerPtrMFieldBase>::pushIndexedValueFromCString(
258 FWARNING(("illegal pushIndexedValueFromCString called for %s\n",
259 this->getName().c_str()));
263 /*---------------------------------------------------------------------------*/
267 bool EditMFieldHandle<FieldContainerPtrMFieldBase>::equal(
268 Inherited::Ptr rhs) const
270 Ptr pOther = boost::dynamic_pointer_cast<EditMFieldHandle>(rhs);
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 */
290 void EditMFieldHandle<FieldContainerPtrMFieldBase>::copyValues(
291 GetFieldHandlePtr source) const
293 FWARNING(("illegal copyValues called for %s\n",
294 this->getName().c_str()));
299 void EditMFieldHandle<FieldContainerPtrMFieldBase>::shareValues(
300 GetFieldHandlePtr source) const
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
317 /*---------------------------------------------------------------------------*/
318 /* GetFCPtrMFieldHandle<FieldT> */
319 /*---------------------------------------------------------------------------*/
321 /*---------------------------------------------------------------------------*/
324 template <class FieldT> inline
325 GetFCPtrMFieldHandle<FieldT>::GetFCPtrMFieldHandle(
326 const GetFCPtrMFieldHandle &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)
363 str << this->get(i) << " ";
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()));
375 /*---------------------------------------------------------------------------*/
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
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 ) )
402 if(typedExistingFC != NULL || existingFC == NULL)
404 retVal = dcast_const()->findIndex(typedExistingFC);
407 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
409 retVal = dcast_const()->findIndex(typedExistingFC);
413 // this should never happen
414 FFATAL(("GetFCPtrMFieldHandle<FieldT>::find: Field has unknown access.\n"));
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 /*---------------------------------------------------------------------------*/
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 /*---------------------------------------------------------------------------*/
455 template <class FieldT> inline
456 EditFCPtrMFieldHandle<FieldT>::EditFCPtrMFieldHandle(
457 const EditFCPtrMFieldHandle &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(
473 const FieldDescriptionBase *pDescription,
474 FieldContainer *pContainer ) :
481 _fRemoveObjMethod ( ),
484 _fReplaceObjMethod( ),
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.
500 template <class FieldT> inline
501 bool EditFCPtrMFieldHandle<FieldT>::supportsAdd(void) const
503 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
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.
514 template <class FieldT> inline
515 bool EditFCPtrMFieldHandle<FieldT>::supportsRemove(void) const
517 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
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.
528 template <class FieldT> inline
529 bool EditFCPtrMFieldHandle<FieldT>::supportsRemoveObject(void) const
531 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
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.
542 template <class FieldT> inline
543 bool EditFCPtrMFieldHandle<FieldT>::supportsInsert(void) const
545 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
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.
556 template <class FieldT> inline
557 bool EditFCPtrMFieldHandle<FieldT>::supportsReplace(void) const
559 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
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.
570 template <class FieldT> inline
571 bool EditFCPtrMFieldHandle<FieldT>::supportsReplaceObject(void) const
573 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
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.
584 template <class FieldT> inline
585 bool EditFCPtrMFieldHandle<FieldT>::supportsClear(void) const
587 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
590 ((0x0000 != (accessFlags & Field::FStdAccess ) ||
591 0x0000 != (accessFlags & Field::FNullCheckAccess) ) ||
592 (0x0000 != (accessFlags & Field::FCustomAccess ) &&
593 !_fClearMethod.empty() ) );
596 /*---------------------------------------------------------------------------*/
599 /*! Returns the value stored at \a index in the edited field; no range checking
600 is performed on \a index.
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.
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
619 template <class FieldT>
620 Int32 EditFCPtrMFieldHandle<FieldT>::find(FieldContainer *existingFC) const
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 ) )
631 if(typedExistingFC != NULL || existingFC == NULL)
633 retVal = dcast_const()->findIndex(typedExistingFC);
636 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
638 retVal = dcast_const()->findIndex(typedExistingFC);
642 // this should never happen
643 FFATAL(("EditFCPtrMFieldHandle<%s>::find: Field has unknown "
644 "access.\n", typeid(FieldT).name() ));
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.
654 template <class FieldT>
655 bool EditFCPtrMFieldHandle<FieldT>::add(FieldContainer *newFC) const
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))
665 if(typedNewFC != NULL || newFC == NULL)
667 if(!_fAddMethod.empty())
669 _fAddMethod(typedNewFC);
674 FFATAL(("EditFCPtrMFieldHandle<%s>::add called, but "
675 "_fAddMethod is not set.\n", typeid(FieldT).name()));
679 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
681 if(typedNewFC != NULL)
683 dcast()->push_back(typedNewFC);
687 else if(0x0000 != (accessFlags & Field::FStdAccess))
689 if(typedNewFC != NULL || newFC == NULL)
691 dcast()->push_back(typedNewFC);
697 // this should never happen
698 FFATAL(("EditFCPtrMFieldHandle<%s>::add: Field has unknown "
699 "access.\n", typeid(FieldT).name() ));
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.
708 \note This operation is only available if \c supportsRemove returns \c true.
710 template <class FieldT>
711 bool EditFCPtrMFieldHandle<FieldT>::remove(UInt32 index) const
714 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
716 if(0x0000 != (accessFlags & Field::FCustomAccess))
718 if(!_fRemoveMethod.empty())
720 _fRemoveMethod(index);
725 FFATAL(("EditFCPtrMFieldHandle<%s>::remove called, but "
726 "_fRemoveMethod is not set.\n", typeid(FieldT).name()));
729 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
731 dcast()->erase(index);
734 else if(0x0000 != (accessFlags & Field::FStdAccess))
736 dcast()->erase(index);
741 // this should never happen
742 FFATAL(("EditFCPtrMFieldHandle<%s>::remove: Field has unknown "
743 "access.\n", typeid(FieldT).name() ));
749 /*! Removes the given \a existingFC from the edited field and returns \c true
752 \note This operation is only available if \c supportsRemoveObject
755 template <class FieldT>
756 bool EditFCPtrMFieldHandle<FieldT>::removeObject(
757 FieldContainer *existingFC) const
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))
767 if(typedExistingFC != NULL || existingFC == NULL)
769 if(!_fRemoveObjMethod.empty())
771 _fRemoveObjMethod(typedExistingFC);
776 FFATAL(("EditFCPtrMFieldHandle<%s>::removeObject called, "
777 "but _fRemoveObjMethod is not set.\n",
778 typeid(FieldT).name() ));
782 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
784 if(typedExistingFC != NULL)
786 Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
790 dcast()->erase(iElemIdx);
795 else if(0x0000 != (accessFlags & Field::FStdAccess))
797 if(typedExistingFC != NULL || existingFC == NULL)
799 Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
803 dcast()->erase(iElemIdx);
810 // this should never happen
811 FFATAL(("EditFCPtrMFieldHandle<%s>::removeObject: Field has unknown "
812 "access.\n", typeid(FieldT).name()));
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.
821 \note This operation is only available if \c supportsInsert returns \c true.
823 template <class FieldT>
824 bool EditFCPtrMFieldHandle<FieldT>::insert(
825 UInt32 index, FieldContainer *newFC) const
828 typename FieldT::const_value typedNewFC =
829 dynamic_cast<typename FieldT::const_value>(newFC);
830 BitVector accessFlags =
831 _pDescription->getFlags() & Field::FAccessMask;
833 if(0x0000 != (accessFlags & Field::FCustomAccess))
835 if(typedNewFC != NULL || newFC == NULL)
837 if(!_fInsertMethod.empty())
839 _fInsertMethod(index, typedNewFC);
844 FFATAL(("EditFCPtrMFieldHandle<%s>::insert called, but "
845 "_fInsertMethod is not set.\n", typeid(FieldT).name()));
849 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
851 if(typedNewFC != NULL)
853 dcast()->insert(dcast()->begin_nc() + index, typedNewFC);
857 else if(0x0000 != (accessFlags & Field::FStdAccess))
859 if(typedNewFC != NULL || newFC == NULL)
861 dcast()->insert(dcast()->begin_nc() + index, typedNewFC);
867 // this should never happen
868 FFATAL(("EditFCPtrMFieldHandle<%s>::insert: Field has unknown "
869 " access.\n", typeid(FieldT).name() ));
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.
878 \note This operation is only available if \c supportsReplace returns \c true.
880 template <class FieldT>
881 bool EditFCPtrMFieldHandle<FieldT>::replace(
882 UInt32 index, FieldContainer *newFC) const
885 typename FieldT::const_value typedNewFC =
886 dynamic_cast<typename FieldT::const_value>(newFC);
887 BitVector accessFlags =
888 _pDescription->getFlags() & Field::FAccessMask;
890 if(0x0000 != (accessFlags & Field::FCustomAccess))
892 if(typedNewFC != NULL || newFC == NULL)
894 if(!_fReplaceMethod.empty())
896 _fReplaceMethod(index, typedNewFC);
901 FFATAL(("EditFCPtrMFieldHandle<%s>::replace called, but "
902 "_fReplaceMethod is not set.\n",
903 typeid(FieldT).name()));
907 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
909 if(typedNewFC != NULL)
911 dcast()->replace(index, typedNewFC);
915 else if(0x0000 != (accessFlags & Field::FStdAccess))
917 if(typedNewFC != NULL || newFC == NULL)
919 dcast()->replace(index, typedNewFC);
925 // this should never happen
926 FFATAL(("EditFCPtrMFieldHandle<%s>::replace: Field has unknown "
927 "access.\n", typeid(FieldT).name() ));
933 /*! Replaces the value \a existingFC with \a newFC in the edited field and
934 returns \c true iff successful.
936 \note This operation is only available if \c supportsReplaceObject
939 template <class FieldT>
940 bool EditFCPtrMFieldHandle<FieldT>::replaceObject(
941 FieldContainer *existingFC, FieldContainer *newFC) const
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;
951 if(0x0000 != (accessFlags & Field::FCustomAccess))
953 if((typedExistingFC != NULL || existingFC == NULL) &&
954 (typedNewFC != NULL || newFC == NULL) )
956 if(!_fReplaceObjMethod.empty())
958 _fReplaceObjMethod(typedExistingFC, typedNewFC);
963 FFATAL(("EditFCPtrMFieldHandle<%s>::replaceObject called, "
964 "but _fReplaceMethod is not set.\n",
965 typeid(FieldT).name()));
969 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
971 if((typedExistingFC != NULL) && (typedNewFC != NULL))
973 Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
977 dcast()->replace(iElemIdx, typedNewFC);
982 else if(0x0000 != (accessFlags & Field::FStdAccess))
984 if((typedExistingFC != NULL || existingFC == NULL) &&
985 (typedNewFC != NULL || newFC == NULL) )
987 Int32 iElemIdx = dcast()->findIndex(typedExistingFC);
991 dcast()->replace(iElemIdx, typedNewFC);
998 // this should never happen
999 FFATAL(("EditFCPtrMFieldHandle<%s>::replaceObject: Field has unknown "
1000 "access.\n", typeid(FieldT).name()));
1006 /*! Clears the edited field and returns \c true iff successful.
1008 \note This operation is only available if \c supportsClear returns \c true.
1010 template <class FieldT>
1011 bool EditFCPtrMFieldHandle<FieldT>::clear(void) const
1013 bool retVal = false;
1014 BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
1016 if(0x0000 != (accessFlags & Field::FCustomAccess))
1018 if(!_fClearMethod.empty())
1025 FFATAL(("EditFCPtrMFieldHandle<%s>::clear called, but "
1026 "_fClearMethod is not set.\n", typeid(FieldT).name()));
1029 else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
1034 else if(0x0000 != (accessFlags & Field::FStdAccess))
1041 // this should never happen
1042 FFATAL(("EditFCPtrMFieldHandle<%s>::clear: Field has unknown "
1043 "access.\n", typeid(FieldT).name() ));
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()));
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()));
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()));
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()));
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)
1143 const FieldContainerPtrMFieldBase *pSrcField = pSrcBase->getField();
1145 for(SizeT i = 0; i < pSrcField->size(); ++i)
1147 this->add((*pSrcField)[i]);
1152 FWARNING(("shareValues illegal source for %s\n",
1153 this->getName().c_str()));
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)
1172 const FieldContainerPtrMFieldBase *pSrcField = pSrcBase->getField();
1174 for(SizeT i = 0; i < pSrcField->size(); ++i)
1176 StoredPtrType pSrcTyped =
1177 dynamic_cast<StoredPtrType>((*pSrcField)[i]);
1179 if(pSrcTyped != NULL)
1181 pDst = deepClone(pSrcTyped,
1197 FWARNING(("cloneValues illegal source for %s\n",
1198 this->getName().c_str()));
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);