fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / ComplexSceneManager / VRMLNodes / OSGSelectValueEmitter.inl
blobd8b8bd802822384dc43528b6cc74af9e803b3b46
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *               Copyright (C) 2000-2006 by the OpenSG Forum                 *
6  *                                                                           *
7  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
8  *                                                                           *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11  *                                License                                    *
12  *                                                                           *
13  * This library is free software; you can redistribute it and/or modify it   *
14  * under the terms of the GNU Library General Public License as published    *
15  * by the Free Software Foundation, version 2.                               *
16  *                                                                           *
17  * This library is distributed in the hope that it will be useful, but       *
18  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
20  * Library General Public License for more details.                          *
21  *                                                                           *
22  * You should have received a copy of the GNU Library General Public         *
23  * License along with this library; if not, write to the Free Software       *
24  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
25  *                                                                           *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28  *                                Changes                                    *
29  *                                                                           *
30  *                                                                           *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35 \*---------------------------------------------------------------------------*/
37 OSG_BEGIN_NAMESPACE
39 template<class Desc> inline
40 UInt32 SelectSValueEmitter<Desc>::getContainerSize(void) const
42     return sizeof(Self);
45 template<class Desc> inline
46 typename SelectSValueEmitter<Desc>::SFChoiceType *
47     SelectSValueEmitter<Desc>::editSFChoice(void)
49     editSField(ChoiceFieldMask);
51     return &_sfChoice;
54 template<class Desc> inline
55 const typename SelectSValueEmitter<Desc>::SFChoiceType *
56     SelectSValueEmitter<Desc>::getSFChoice(void) const
58     return &_sfChoice;
61 template<class Desc> inline
62 typename SelectSValueEmitter<Desc>::ChoiceType &
63     SelectSValueEmitter<Desc>::editChoice(void)
65     editSField(ChoiceFieldMask);
67     return _sfChoice.getValue();
70 template<class Desc> inline
71 typename SelectSValueEmitter<Desc>::ChoiceType
72     SelectSValueEmitter<Desc>::getChoice(void) const
74     return _sfChoice.getValue();
77 template<class Desc> inline
78 typename SelectSValueEmitter<Desc>::MFChoiceValuesType *
79     SelectSValueEmitter<Desc>::editMFChoiceValues(void)
81     editMField(ChoiceValuesFieldMask, _mfChoiceValues);
82     
83     return &_mfChoiceValues;
86 template<class Desc> inline
87 const typename SelectSValueEmitter<Desc>::MFChoiceValuesType *
88     SelectSValueEmitter<Desc>::getMFChoiceValues(void) const
90     return &_mfChoiceValues;
93 template<class Desc> inline
94 typename SelectSValueEmitter<Desc>::ChoiceValuesType &
95     SelectSValueEmitter<Desc>::editChoiceValue(const UInt32 index)
97     editMField(ChoiceValuesFieldMask, _mfChoiceValues);
99     return _mfChoiceValues[index];
102 template<class Desc> inline
103 typename SelectSValueEmitter<Desc>::ChoiceValuesType    
104     SelectSValueEmitter<Desc>::getChoiceValue(const UInt32 index) const
106     return _mfChoiceValues[index];
109 template<class Desc> inline
110 typename SelectSValueEmitter<Desc>::SFValueType *
111     SelectSValueEmitter<Desc>::editSFValue(void)
113     editSField(ValueFieldMask);
115     return &_sfValue;
118 template<class Desc> inline
119 const typename SelectSValueEmitter<Desc>::SFValueType *
120     SelectSValueEmitter<Desc>::getSFValue(void) const
122     return &_sfValue;
125 //! Get the value of the Real32Counter::_sfValue field.
127 template<class Desc> inline
128 typename SelectSValueEmitter<Desc>::ValueType &
129     SelectSValueEmitter<Desc>::editValue(void)
131     editSField(ValueFieldMask);
133     return _sfValue.getValue();
136 //! Get the value of the Real32Counter::_sfValue field.
137 template<class Desc> inline
138 typename SelectSValueEmitter<Desc>::ValueType 
139     SelectSValueEmitter<Desc>::getValue(void) const
141     return _sfValue.getValue();
144 template<class Desc> inline
145 void SelectSValueEmitter<Desc>::setChoice(const ChoiceType choice)
147     editSField(ChoiceFieldMask);
149     _sfChoice.setValue(choice);
152 //! Set the value of the Real32Counter::_sfValue field.
153 template<class Desc> inline
154 void SelectSValueEmitter<Desc>::setValue(const ValueType value)
156     editSField(ValueFieldMask);
158     _sfValue.setValue(value);
161 template<class Desc> inline
162 SFBool *SelectSValueEmitter<Desc>::editSFIgnoreNextChange(void)
164     editSField(IgnoreNextChangeFieldMask);
166     return &_sfIgnoreNextChange;
169 template<class Desc> inline
170 const SFBool *SelectSValueEmitter<Desc>::getSFIgnoreNextChange (void) const
172     return &_sfIgnoreNextChange;
175 /*----------------------------- class specific ----------------------------*/
177 template<class Desc> inline
178 void SelectSValueEmitter<Desc>::changed(ConstFieldMaskArg whichField, 
179                                         UInt32            origin,
180                                         BitVector         details)
182     if(0x0000 != (whichField & TriggerFieldMask))
183     {
184         editSField(ValueFieldMask);
185     }
187     if(0x0000 != (whichField & (ChoiceFieldMask | ChoiceValuesFieldMask)))
188     {
189         if(_sfChoice.getValue() < _mfChoiceValues.size())
190         {            
191             setValue(Desc::convert(_mfChoiceValues[_sfChoice.getValue()]));
192         }
193     }
195     if(0x0000 != (whichField & IgnoreNextChangeFieldMask))
196     {
197         if(_sfIgnoreNextChange.getValue() == false)
198         {
199             Inherited::changed(whichField, origin, details);
200         }
201     }
202     else
203     {
204         Inherited::changed(whichField, origin, details);
205     }
208 /*------------------------------ access -----------------------------------*/
209 template<class Desc> inline
210 SizeT SelectSValueEmitter<Desc>::getBinSize(ConstFieldMaskArg whichField)
212     SizeT returnValue = Inherited::getBinSize(whichField);
214     if(FieldBits::NoField != (ChoiceFieldMask & whichField))
215     {
216         returnValue += _sfChoice.getBinSize();
217     }
219     if(FieldBits::NoField != (ChoiceValuesFieldMask & whichField))
220     {
221         returnValue += _mfChoiceValues.getBinSize();
222     }
224     if(FieldBits::NoField != (ValueFieldMask & whichField))
225     {
226         returnValue += _sfValue.getBinSize();
227     }
230     return returnValue;
233 template<class Desc> inline
234 void SelectSValueEmitter<Desc>::copyToBin(BinaryDataHandler &pMem,
235                                     ConstFieldMaskArg  whichField)
237     Inherited::copyToBin(pMem, whichField);
239     if(FieldBits::NoField != (ChoiceFieldMask & whichField))
240     {
241         _sfChoice.copyToBin(pMem);
242     }
244     if(FieldBits::NoField != (ChoiceValuesFieldMask & whichField))
245     {
246         _mfChoiceValues.copyToBin(pMem);
247     }
249     if(FieldBits::NoField != (ValueFieldMask & whichField))
250     {
251         _sfValue.copyToBin(pMem);
252     }
255 template<class Desc> inline
256 void SelectSValueEmitter<Desc>::copyFromBin(BinaryDataHandler &pMem,
257                                             ConstFieldMaskArg  whichField)
259     Inherited::copyFromBin(pMem, whichField);
261     if(FieldBits::NoField != (ChoiceFieldMask & whichField))
262     {
263         _sfChoice.copyFromBin(pMem);
264     }
266     if(FieldBits::NoField != (ChoiceValuesFieldMask & whichField))
267     {
268         _mfChoiceValues.copyFromBin(pMem);
269     }
271     if(FieldBits::NoField != (ValueFieldMask & whichField))
272     {
273         _sfValue.copyFromBin(pMem);
274     }
278 //! create a new instance of the class
279 template<class Desc> inline
280 typename SelectSValueEmitter<Desc>::ObjTransitPtr 
281     SelectSValueEmitter<Desc>::createLocal(BitVector bFlags)
283     ObjTransitPtr fc;
285     if(getClassType().getPrototype() != NULL)
286     {
287         FieldContainerTransitPtr tmpPtr =
288             getClassType().getPrototype()-> shallowCopyLocal(bFlags);
290         fc = dynamic_pointer_cast<Self>(tmpPtr);
291     }
293     return fc;
296 //! create a new instance of the class
297 template<class Desc> inline
298 typename SelectSValueEmitter<Desc>::ObjTransitPtr 
299     SelectSValueEmitter<Desc>::createDependent(BitVector bFlags)
301     ObjTransitPtr fc;
303     if(getClassType().getPrototype() != NULL)
304     {
305         FieldContainerTransitPtr tmpPtr =
306             getClassType().getPrototype()-> shallowCopyDependent(bFlags);
308         fc = dynamic_pointer_cast<Self>(tmpPtr);
309     }
311     return fc;
314 //! create a new instance of the class
315 template<class Desc> inline
316 typename SelectSValueEmitter<Desc>::ObjTransitPtr 
317     SelectSValueEmitter<Desc>::create(void)
319     return createLocal();
322 template<class Desc> inline
323 typename SelectSValueEmitter<Desc>::Self *
324     SelectSValueEmitter<Desc>::createEmptyLocal(BitVector bFlags)
326     Self *returnValue;
328     newPtr<Self>(returnValue, bFlags);
330     returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
332     return returnValue;
335 //! create an empty new instance of the class, do not copy the prototype
336 template<class Desc> inline
337 typename SelectSValueEmitter<Desc>::Self *
338     SelectSValueEmitter<Desc>::createEmpty(void)
340     return createEmptyLocal();
344 template<class Desc> inline
345 FieldContainerTransitPtr 
346     SelectSValueEmitter<Desc>::shallowCopyLocal(BitVector bFlags) const
348     Self *tmpPtr;
350     newPtr(tmpPtr, dynamic_cast<const Self *>(this), bFlags);
352     FieldContainerTransitPtr returnValue(tmpPtr);
354     tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
356     return returnValue;
359 template<class Desc> inline
360 FieldContainerTransitPtr 
361     SelectSValueEmitter<Desc>::shallowCopyDependent(BitVector bFlags) const
363     Self *tmpPtr;
365     newPtr(tmpPtr, dynamic_cast<const Self *>(this), ~bFlags);
367     FieldContainerTransitPtr returnValue(tmpPtr);
369     tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
371     return returnValue;
374 template<class Desc> inline
375 FieldContainerTransitPtr SelectSValueEmitter<Desc>::shallowCopy(void) const
377     return shallowCopyLocal();
381 template<class Desc> inline
382 const Char8 *SelectSValueEmitter<Desc>::getClassname(void)
384     return Desc::getClassname();
387 /*------------------------- constructors ----------------------------------*/
389 template<class Desc> inline
390 SelectSValueEmitter<Desc>::SelectSValueEmitter(void) :
391      Inherited         (                  ),
392     _sfTrigger         (                  ),
393     _sfChoice          (                  ),
394     _mfChoiceValues    (                  ),
395     _sfValue           (Desc::getDefault()),
396     _sfIgnoreNextChange(false             )
400 template<class Desc> inline
401 SelectSValueEmitter<Desc>::SelectSValueEmitter(
402     const SelectSValueEmitter &source) :
404      Inherited         (source                    ),
405     _sfTrigger         (source._sfTrigger         ),
406     _sfChoice          (source._sfChoice          ),
407     _mfChoiceValues    (source._mfChoiceValues    ),
408     _sfValue           (source._sfValue           ),
409     _sfIgnoreNextChange(source._sfIgnoreNextChange)
414 /*-------------------------- destructors ----------------------------------*/
416 template<class Desc> inline
417 SelectSValueEmitter<Desc>::~SelectSValueEmitter(void)
421 template<class Desc> inline
422 GetFieldHandlePtr  SelectSValueEmitter<Desc>::getHandleChoice(void) const
424     typename SFChoiceType::GetHandlePtr returnValue(
425         new typename SFChoiceType::GetHandle(
426              &_sfChoice,
427              this->getType().getFieldDesc(ChoiceFieldId),
428              const_cast<Self *>(this)));
430     return returnValue;
433 template<class Desc> inline
434 EditFieldHandlePtr SelectSValueEmitter<Desc>::editHandleChoice(void)
436     typename SFChoiceType::EditHandlePtr returnValue(
437         new typename SFChoiceType::EditHandle(
438              &_sfChoice,
439              this->getType().getFieldDesc(ChoiceFieldId),
440              this));
443     editSField(ChoiceFieldMask);
445     return returnValue;
448 template<class Desc> inline
449 GetFieldHandlePtr  SelectSValueEmitter<Desc>::getHandleChoiceValues(void) const
451     typename MFChoiceValuesType::GetHandlePtr returnValue(
452         new typename MFChoiceValuesType::GetHandle(
453              &_mfChoiceValues,
454              this->getType().getFieldDesc(ChoiceValuesFieldId),
455              const_cast<Self *>(this)));
457     return returnValue;
460 template<class Desc> inline
461 EditFieldHandlePtr SelectSValueEmitter<Desc>::editHandleChoiceValues(void)
463     typename MFChoiceValuesType::EditHandlePtr returnValue(
464         new typename MFChoiceValuesType::EditHandle(
465              &_mfChoiceValues,
466              this->getType().getFieldDesc(ChoiceValuesFieldId),
467              this));
470     editMField(ChoiceValuesFieldMask, _mfChoiceValues);
472     return returnValue;
474   
475 template<class Desc> inline
476 GetFieldHandlePtr SelectSValueEmitter<Desc>::getHandleValue(void) const
478     typename SFValueType::GetHandlePtr returnValue(
479         new typename SFValueType::GetHandle(
480              &_sfValue,
481              this->getType().getFieldDesc(ValueFieldId),
482              const_cast<Self *>(this)));
484     return returnValue;
487 template<class Desc> inline
488 EditFieldHandlePtr SelectSValueEmitter<Desc>::editHandleValue(void)
490     typename SFValueType::EditHandlePtr returnValue(
491         new typename SFValueType::EditHandle(
492              &_sfValue,
493              this->getType().getFieldDesc(ValueFieldId),
494              this));
497     editSField(ValueFieldMask);
499     return returnValue;
502 template<class Desc> inline
503 GetFieldHandlePtr 
504     SelectSValueEmitter<Desc>::getHandleIgnoreNextChange (void) const
506     typename SFBool::GetHandlePtr returnValue(
507         new typename SFBool::GetHandle(
508              &_sfIgnoreNextChange,
509              this->getType().getFieldDesc(IgnoreNextChangeFieldId),
510              const_cast<Self *>(this)));
512     return returnValue;
515 template<class Desc> inline
516 EditFieldHandlePtr SelectSValueEmitter<Desc>::editHandleIgnoreNextChange(void)
518     typename SFBool::EditHandlePtr returnValue(
519         new typename SFBool::EditHandle(
520              &_sfIgnoreNextChange,
521              this->getType().getFieldDesc(IgnoreNextChangeFieldId),
522              this));
525     editSField(IgnoreNextChangeFieldMask);
527     return returnValue;
530 #ifdef OSG_MT_CPTR_ASPECT
531 template<class Desc> inline
532 void SelectSValueEmitter<Desc>::execSync (      Self              *pFrom,
533                                                 ConstFieldMaskArg  whichField,
534                                                 AspectOffsetStore &oOffsets,
535                                                 ConstFieldMaskArg  syncMode,
536                                           const UInt32             uiSyncInfo)
538     Inherited::execSync(pFrom, whichField, oOffsets, syncMode, uiSyncInfo);
540     if(FieldBits::NoField != (ChoiceFieldMask & whichField))
541         _sfChoice.syncWith(pFrom->_sfChoice);
543     if(FieldBits::NoField != (ChoiceValuesFieldMask & whichField))
544     {
545         _mfChoiceValues.syncWith(pFrom->_mfChoiceValues,
546                                  syncMode,
547                                  uiSyncInfo,
548                                  oOffsets);
549     }
551     if(FieldBits::NoField != (ValueFieldMask & whichField))
552         _sfValue.syncWith(pFrom->_sfValue);
555 template<class Desc> inline
556 void SelectSValueEmitter<Desc>::execSyncV(      FieldContainer    &oFrom,
557                                                 ConstFieldMaskArg  whichField,
558                                                 AspectOffsetStore &oOffsets,
559                                                 ConstFieldMaskArg  syncMode,
560                                           const UInt32             uiSyncInfo)
562     Self *pThis = static_cast<Self *>(this);
564     pThis->execSync(static_cast<Self *>(&oFrom),
565                     whichField,
566                     oOffsets,
567                     syncMode,
568                     uiSyncInfo);
572 template<class Desc> inline
573 FieldContainer *SelectSValueEmitter<Desc>::createAspectCopy(
574     const FieldContainer *pRefAspect) const
576     Self *returnValue;
578     newAspectCopy(returnValue,
579                   dynamic_cast<const Self *>(pRefAspect),
580                   dynamic_cast<const Self *>(this));
582     return returnValue;
585 #endif
587 template<class Desc> inline
588 void SelectSValueEmitter<Desc>::resolveLinks(void)
590     Inherited::resolveLinks();
595 template<class Desc> inline
596 void SelectSValueEmitter<Desc>::initMethod(InitPhase ePhase)
598     Inherited::initMethod(ePhase);
600     if(ePhase == TypeObject::SystemPost)
601     {
602     }
604 OSG_END_NAMESPACE