fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Fields / Handle / OSGFieldContainerSFieldHandle.inl
blobced76454c31c6cb055cb42e43df80673400fe3e1
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 /* GetSFieldHandle<FieldContainerPtrSFieldBase>                              */
43 /*---------------------------------------------------------------------------*/
45 /*---------------------------------------------------------------------------*/
46 /* Constructors                                                              */
48 inline
49 GetSFieldHandle<FieldContainerPtrSFieldBase>::GetSFieldHandle(
50     const GetSFieldHandle &source) :
52     Inherited(source)
56 inline
57 GetSFieldHandle<FieldContainerPtrSFieldBase>::GetSFieldHandle(
58     const FieldContainerPtrSFieldBase *pField, 
59     const FieldDescriptionBase        *pDescription,
60           FieldContainer              *pContainer  ) :
62     Inherited(pField, pDescription, pContainer)
66 /*---------------------------------------------------------------------------*/
67 /* Field Type Query                                                          */
69 inline
70 const FieldType &
71     GetSFieldHandle<FieldContainerPtrSFieldBase>::getType(void) const
73     return FieldContainerPtrSFieldBase::getClassType();
76 inline
77 bool GetSFieldHandle<FieldContainerPtrSFieldBase>::isPointerField(void) const
79     return true;
82 /*---------------------------------------------------------------------------*/
83 /* Stream/String IO                                                          */
85 inline
86 void GetSFieldHandle<FieldContainerPtrSFieldBase>::pushValueToStream(
87     OutStream &str) const
89     FWARNING(("illegal pushValueToStream called for %s\n", 
90               this->getName().c_str()));
91     OSG_ASSERT(false);
94 inline
95 void GetSFieldHandle<FieldContainerPtrSFieldBase>::pushSizeToStream(
96     OutStream &str) const
98     FWARNING(("illegal pushSizeToStream called for %s\n", 
99               this->getName().c_str()));
100     OSG_ASSERT(false);
103 inline
104 void GetSFieldHandle<FieldContainerPtrSFieldBase>::pushIndexedValueToStream(
105     OutStream &str, 
106     UInt32     index) const
108     FWARNING(("illegal pushIndexedValueToStream called for %s\n", 
109               this->getName().c_str()));
110     OSG_ASSERT(false);
113 /*---------------------------------------------------------------------------*/
114 /* Comparison                                                                */
116 inline
117 bool GetSFieldHandle<FieldContainerPtrSFieldBase>::equal(
118     Inherited::Ptr rhs) const
120     Ptr pOther = boost::dynamic_pointer_cast<GetSFieldHandle>(rhs);
122     if(pOther == NULL)
123     {
124         return false;
125     }
127     FieldContainerPtrSFieldBase const *pLhs = 
128         static_cast<FieldContainerPtrSFieldBase const *>(        _pField);
130     FieldContainerPtrSFieldBase const *pRhs = 
131         static_cast<FieldContainerPtrSFieldBase const *>(pOther->_pField);
133     return (*pLhs) == (*pRhs);
136 inline
137 SizeT GetSFieldHandle<FieldContainerPtrSFieldBase>::size(void) const
139     return 1;
142 /*---------------------------------------------------------------------------*/
143 /* Access                                                                    */
145 inline
146 const FieldContainerPtrSFieldBase *
147     GetSFieldHandle<FieldContainerPtrSFieldBase>::getField(void)
149     return static_cast<const FieldContainerPtrSFieldBase *>(_pField);
152 inline
153 const FieldContainerPtrSFieldBase *
154     GetSFieldHandle<FieldContainerPtrSFieldBase>::operator ->(void)
156     return static_cast<const FieldContainerPtrSFieldBase *>(_pField);
159 inline
160 const FieldContainerPtrSFieldBase &
161     GetSFieldHandle<FieldContainerPtrSFieldBase>::operator * (void)
163     return *(static_cast<const FieldContainerPtrSFieldBase *>(_pField));
166 /*---------------------------------------------------------------------------*/
167 /* EditSFieldHandle<FieldContainerPtrSFieldBase>                             */
168 /*---------------------------------------------------------------------------*/
170 /*---------------------------------------------------------------------------*/
171 /* Constructors                                                              */
173 inline
174 EditSFieldHandle<FieldContainerPtrSFieldBase>::EditSFieldHandle(
175     const EditSFieldHandle &source) :
177      Inherited (source            ),
178     _bStoreless(source._bStoreless)
182 inline
183 EditSFieldHandle<FieldContainerPtrSFieldBase>::EditSFieldHandle(      
184           FieldContainerPtrSFieldBase *pField, 
185     const FieldDescriptionBase        *pDescription,
186           FieldContainer              *pContainer  ) :
188       Inherited (pField, 
189                  pDescription,
190                  pContainer  ),
191      _bStoreless(false       )
195 inline
196 bool EditSFieldHandle<FieldContainerPtrSFieldBase>::isValid(void) const
198     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
200     return 
201         ( (_pField     != NULL)                                      || 
202          ((_bStoreless == true) && (0x0000 != (accessFlags & 
203                                                Field::FCustomAccess))));
206 inline
207 void EditSFieldHandle<FieldContainerPtrSFieldBase>::setStoreless(void)
209     _bStoreless = true;
212 /*---------------------------------------------------------------------------*/
213 /* Field Type Query                                                          */
215 inline
216 const FieldType &
217     EditSFieldHandle<FieldContainerPtrSFieldBase>::getType(void) const
219     return FieldContainerPtrSFieldBase::getClassType();
222 inline
223 bool EditSFieldHandle<FieldContainerPtrSFieldBase>::isPointerField(void) const
225     return true;
228 /*---------------------------------------------------------------------------*/
229 /* Stream/String IO                                                          */
231 inline
232 void EditSFieldHandle<FieldContainerPtrSFieldBase>::pushValueToStream(
233     OutStream &str) const
235     FWARNING(("illegal pushValueToStream called for %s\n", 
236               this->getName().c_str()));
237     OSG_ASSERT(false);
240 inline
241 void EditSFieldHandle<FieldContainerPtrSFieldBase>::pushSizeToStream(
242     OutStream &str) const
244     FWARNING(("illegal pushSizeToStream called for %s\n", 
245               this->getName().c_str()));
246     OSG_ASSERT(false);
249 inline
250 void EditSFieldHandle<FieldContainerPtrSFieldBase>::pushIndexedValueToStream(
251     OutStream &str, 
252     UInt32     index) const
254     FWARNING(("illegal pushIndexedValueToStream called for %s\n", 
255               this->getName().c_str()));
256     OSG_ASSERT(false);
260 inline
261 void EditSFieldHandle<FieldContainerPtrSFieldBase>::pushValueFromCString(
262     const Char8 *str)
264     FWARNING(("illegal pushValueFromCString called for %s\n", 
265               this->getName().c_str()));
266     OSG_ASSERT(false);
269 inline
270 void EditSFieldHandle<FieldContainerPtrSFieldBase>::pushIndexedValueFromCString(
271     const Char8  *str, 
272           UInt32  index)
274     FWARNING(("illegal pushIndexedValueFromCString called for %s\n", 
275               this->getName().c_str()));
276     OSG_ASSERT(false);
279 /*---------------------------------------------------------------------------*/
280 /* Comparison                                                                */
282 inline
283 bool EditSFieldHandle<FieldContainerPtrSFieldBase>::equal(
284     Inherited::Ptr rhs) const
286     Ptr pOther = boost::dynamic_pointer_cast<EditSFieldHandle>(rhs);
288     if(pOther == NULL)
289     {
290         return false;
291     }
293     FieldContainerPtrSFieldBase *pLhs = 
294         static_cast<FieldContainerPtrSFieldBase *>(        _pField);
296     FieldContainerPtrSFieldBase *pRhs = 
297         static_cast<FieldContainerPtrSFieldBase *>(pOther->_pField);
299     return (*pLhs) == (*pRhs);
302 inline
303 SizeT EditSFieldHandle<FieldContainerPtrSFieldBase>::size(void) const
305     return 1;
308 /*---------------------------------------------------------------------------*/
309 /* Copy/Share/Clone                                                          */
311 inline
312 void EditSFieldHandle<FieldContainerPtrSFieldBase>::copyValues(
313     GetFieldHandlePtr source) const
315     FWARNING(("illegal copyValues called for %s\n", 
316               this->getName().c_str()));
317     OSG_ASSERT(false);
320 inline
321 void EditSFieldHandle<FieldContainerPtrSFieldBase>::shareValues(
322     GetFieldHandlePtr source) const
324     OSG_ASSERT(false);
327 inline
328 void EditSFieldHandle<FieldContainerPtrSFieldBase>::cloneValues(
329           GetFieldHandlePtr  pSrc,
330     const TypePtrVector     &shareTypes,
331     const TypePtrVector     &ignoreTypes,
332     const TypeIdVector      &shareGroupIds,
333     const TypeIdVector      &ignoreGroupIds) const
335     OSG_ASSERT(false);
338 /*---------------------------------------------------------------------------*/
339 /* GetFCPtrSFieldHandle<FieldT>                                              */
340 /*---------------------------------------------------------------------------*/
342 /*---------------------------------------------------------------------------*/
343 /* Constructors                                                              */
345 template <class FieldT> inline
346 GetFCPtrSFieldHandle<FieldT>::GetFCPtrSFieldHandle(
347     const GetFCPtrSFieldHandle &source) :
349     Inherited(source)
353 template <class FieldT> inline
354 GetFCPtrSFieldHandle<FieldT>::GetFCPtrSFieldHandle(
355     const FieldT               *pField, 
356     const FieldDescriptionBase *pDescription,
357           FieldContainer       *pContainer  ) :
359     Inherited(pField, pDescription, pContainer)
363 /*---------------------------------------------------------------------------*/
364 /* Field Type Query                                                          */
366 template <class FieldT> inline
367 const FieldType &GetFCPtrSFieldHandle<FieldT>::getType(void) const
369     return FieldT::getClassType();
372 /*---------------------------------------------------------------------------*/
373 /* Stream/String IO                                                          */
375 template <class FieldT> inline
376 void GetFCPtrSFieldHandle<FieldT>::pushValueToStream(OutStream &str) const
378     FWARNING(("illegal pushValueToStream called for %s\n", 
379               this->getName().c_str()));
381     str << this->get();
382 //    OSG_ASSERT(false);
385 template <class FieldT> inline
386 void GetFCPtrSFieldHandle<FieldT>::pushSizeToStream(OutStream &str) const
388     FWARNING(("illegal pushSizeToStream called for %s\n", 
389               this->getName().c_str()));
390     OSG_ASSERT(false);
393 /*---------------------------------------------------------------------------*/
394 /* Access                                                                    */
396 template <class FieldT> inline
397 FieldContainer *GetFCPtrSFieldHandle<FieldT>::get(void) const
399     return dcast_const()->getValue();
402 template <class FieldT> inline
403 const FieldT *GetFCPtrSFieldHandle<FieldT>::getField(void)
405     return static_cast<const FieldT *>(_pField);
408 template <class FieldT> inline
409 const FieldT *GetFCPtrSFieldHandle<FieldT>::operator ->(void)
411     return static_cast<const FieldT *>(_pField);
414 template <class FieldT> inline
415 const FieldT &GetFCPtrSFieldHandle<FieldT>::operator * (void)
417     return *(static_cast<const FieldT *>(_pField));
420 /*---------------------------------------------------------------------------*/
421 /* Private Helper                                                            */
423 template <class FieldT> inline
424 const typename GetFCPtrSFieldHandle<FieldT>::HandledField *
425     GetFCPtrSFieldHandle<FieldT>::dcast_const(void) const
427     return static_cast<const HandledField *>(_pField);
430 /*---------------------------------------------------------------------------*/
431 /* EditFCPtrSFieldHandle<FieldT>                                             */
432 /*---------------------------------------------------------------------------*/
434 /*---------------------------------------------------------------------------*/
435 /* Constructors                                                              */
437 template <class FieldT> inline
438 EditFCPtrSFieldHandle<FieldT>::EditFCPtrSFieldHandle(
439     const EditFCPtrSFieldHandle &source) :
440     
441      Inherited (source            ),
442     _fSetMethod(source._fSetMethod)
446 template <class FieldT> inline
447 EditFCPtrSFieldHandle<FieldT>::EditFCPtrSFieldHandle(
448           FieldT                *pField, 
449     const FieldDescriptionBase  *pDescription,
450           FieldContainer        *pContainer  ) :
451     
452      Inherited (pField, 
453                 pDescription,
454                 pContainer  ),
455     _fSetMethod(NULL        )
459 /*---------------------------------------------------------------------------*/
460 /* Field Type Query                                                          */
462 template <class FieldT> inline
463 const FieldType &EditFCPtrSFieldHandle<FieldT>::getType(void) const
465     return FieldT::getClassType();
468 template <class FieldT> inline
469 bool EditFCPtrSFieldHandle<FieldT>::supportsSet(void) const
471     BitVector accessFlags = _pDescription->getFlags() & Field::FAccessMask;
473     return 
474         ((0x0000 != (accessFlags & Field::FStdAccess      ) ||
475           0x0000 != (accessFlags & Field::FNullCheckAccess)    ) ||
476          (0x0000 != (accessFlags & Field::FCustomAccess   ) &&
477           !_fSetMethod.empty()                                 )   );
480 /*---------------------------------------------------------------------------*/
481 /* Access                                                                    */
483 template <class FieldT> inline
484 FieldContainer *EditFCPtrSFieldHandle<FieldT>::get(void) const
486     return dcast_const()->getValue();
489 template <class FieldT>
490 bool EditFCPtrSFieldHandle<FieldT>::set(FieldContainer *newFC) const
492     bool                         retVal      = false;
493     typename FieldT::const_value typedNewFC  =
494         dynamic_cast<typename FieldT::const_value>(newFC);
495     BitVector                    accessFlags =
496         _pDescription->getFlags() & Field::FAccessMask;
498     if(0x0000 != (accessFlags & Field::FCustomAccess))
499     {
500         if(typedNewFC != NULL || newFC == NULL)
501         {
502             if(!_fSetMethod.empty())
503             {
504                 _fSetMethod(typedNewFC);
505                 retVal = true;
506             }
507             else
508             {
509                 FFATAL(("EditFCPtrSFieldHandle<FieldT>::set called, but "
510                         "_fSetMethod is not set.\n"));
511             }
512         }
513     }
514     else if(0x0000 != (accessFlags & Field::FNullCheckAccess))
515     {
516         if(typedNewFC != NULL)
517         {
518             dcast()->setValue(typedNewFC);
519             retVal = true;
520         }
521     }
522     else if(0x0000 != (accessFlags & Field::FStdAccess))
523     {
524         if(typedNewFC != NULL || newFC == NULL)
525         {
526             dcast()->setValue(typedNewFC);
527             retVal = true;
528         }
529     }
530     else
531     {
532         // this should never happen
533         FFATAL(("EditFCPtrSFieldHandle<FieldT>::set: Field has unknown access.\n"));
534     }
536     return retVal;
539 /*---------------------------------------------------------------------------*/
540 /* Stream/String IO                                                          */
542 template <class FieldT> inline
543 void EditFCPtrSFieldHandle<FieldT>::pushValueToStream(OutStream &str) const
545     FWARNING(("illegal pushValueToStream called for %s\n", 
546               this->getName().c_str()));
548     OSG_ASSERT(false);
551 template <class FieldT> inline
552 void EditFCPtrSFieldHandle<FieldT>::pushSizeToStream(OutStream &str) const
554     FWARNING(("illegal pushSizeToStream called for %s\n", 
555               this->getName().c_str()));
556     OSG_ASSERT(false);
559 template <class FieldT> inline
560 void EditFCPtrSFieldHandle<FieldT>::pushValueFromCString(const Char8 *str)
562     FWARNING(("illegal pushValueFromCString called for %s\n", 
563               this->getName().c_str()));
564     OSG_ASSERT(false);
567 /*---------------------------------------------------------------------------*/
568 /* Callback Setup                                                            */
570 template <class FieldT> inline
571 void EditFCPtrSFieldHandle<FieldT>::setSetMethod(SetMethod fMethod)
573     _fSetMethod = fMethod;
576 /*---------------------------------------------------------------------------*/
577 /* Copy/Share/Clone                                                          */
579 template <class FieldT> inline
580 void EditFCPtrSFieldHandle<FieldT>::copyValues(GetFieldHandlePtr source) const
582     FWARNING(("illegal copyValues called for %s\n", 
583               this->getName().c_str()));
584     OSG_ASSERT(false);
587 template <class FieldT> inline
588 void EditFCPtrSFieldHandle<FieldT>::shareValues(GetFieldHandlePtr source) const
590     typename Self::GetSFHandlePtr pSrcBase = 
591         boost::dynamic_pointer_cast<GetSFHandle>(source);
593     if(pSrcBase != NULL && pSrcBase->isValid() == true)
594     {
595         this->set(pSrcBase->get());
596     }
597     else
598     {
599         FWARNING(("shareValues illegal source for %s\n", 
600                   this->getName().c_str()));
601     }
604 template <class FieldT> inline
605 void EditFCPtrSFieldHandle<FieldT>::cloneValues(
606               GetFieldHandlePtr  pSrc,
607         const TypePtrVector     &shareTypes,
608         const TypePtrVector     &ignoreTypes,
609         const TypeIdVector      &shareGroupIds,
610         const TypeIdVector      &ignoreGroupIds) const
612     typename Self::GetSFHandlePtr pSrcBase = 
613         boost::dynamic_pointer_cast<GetSFHandle>(pSrc);
615     if(pSrcBase != NULL && pSrcBase->isValid() == true)
616     {
617         StoredPtrType pSrcTyped = dynamic_cast<StoredPtrType>(pSrcBase->get());
619         if(pSrcTyped != NULL)
620         {
621             FieldContainerUnrecPtr pDst = deepClone(pSrcTyped,
622                                                     shareTypes,
623                                                     ignoreTypes,
624                                                     shareGroupIds,
625                                                     ignoreGroupIds);
627             this->set(pDst);
628         }
629     }
630     else
631     {
632         FWARNING(("cloneValues illegal source for %s\n", 
633                   this->getName().c_str()));
634     }
637 /*---------------------------------------------------------------------------*/
638 /* Private Helper                                                            */
640 template <class FieldT> inline
641 typename EditFCPtrSFieldHandle<FieldT>::HandledField *
642     EditFCPtrSFieldHandle<FieldT>::dcast(void) const
644     return static_cast<HandledField *>(_pField);
647 template <class FieldT> inline
648 const typename EditFCPtrSFieldHandle<FieldT>::HandledField *
649     EditFCPtrSFieldHandle<FieldT>::dcast_const(void) const
651     return static_cast<const HandledField *>(_pField);
654 OSG_END_NAMESPACE