fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FieldContainer / Mixins / OSGTraversalValidationHandlerMixin.inl
blobf92a3d58a97af108da7e9581e2c96ccdf387ce07
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 template <class ParentT> inline
42 void TraversalValidationHandlerMixin<ParentT>::classDescInserter(
43     TypeObject &oType)
45     FieldDescriptionBase *pDesc;
47     typedef typename SFUInt32::Description SFDesc;
49     pDesc = new SFDesc(
50         SFUInt32::getClassType(),
51         "updateMode",
52         "how the element is updated.",
53         OSG_RC_FIELD_DESC(Self::UpdateMode),
54         false,
55         Field::SFDefaultFlags,
56         static_cast<FieldEditMethodSig>(&Self::editHandleUpdateMode),
57         static_cast<FieldGetMethodSig >(&Self::getHandleUpdateMode ));
59     oType.addInitialDesc(pDesc);
61     pDesc = new SFDesc(
62         SFOSGAny::getClassType(),
63         "requestRun",
64         "",
65         OSG_RC_FIELD_DESC(Self::RequestRun),
66         true,
67         Field::SFDefaultFlags,
68         static_cast<FieldEditMethodSig>(&Self::invalidEditField   ),
69         static_cast<FieldGetMethodSig >(&Self::getHandleRequestRun));
71     oType.addInitialDesc(pDesc);
73     pDesc = new MFChangedFunctorCallback::Description(
74         MFChangedFunctorCallback::getClassType(),
75         "destroyedFunctors",
76         "",
77         OSG_RC_FIELD_DESC(Self::DestroyedFunctors),
78         true,
79         (Field::MFDefaultFlags | Field::FStdAccess),
80         static_cast     <FieldEditMethodSig>(&Self::invalidEditField),
81         static_cast     <FieldGetMethodSig >(&Self::invalidGetField));
83     oType.addInitialDesc(pDesc);
86 template <class ParentT> inline
87 bool TraversalValidationHandlerMixin<ParentT>::requestRun(void)
89     Self::editSField(RequestRunFieldMask);
91     return true;
94 template <class ParentT> inline
95 void TraversalValidationHandlerMixin<ParentT>::changed(
96     ConstFieldMaskArg whichField, 
97     UInt32            origin,
98     BitVector         details)
100     if(0x0000 != (whichField & RequestRunFieldMask))
101     {
102         Window::requestStageRun(this->_iElementId);
103     }
105     Inherited::changed(whichField, origin, details);
108 template <class ParentT> inline
109 typename TraversalValidationHandlerMixin<ParentT>::ValidationStatus 
110     TraversalValidationHandlerMixin<ParentT>::validate(
111         RenderActionBase *pAction)
114     TraversalValidator *pVal = NULL;
116     if(_sfUpdateMode.getValue() == Self::PerWindow)
117     {
118         Window *pWin = pAction->getWindow();
120         pVal = pWin->getTravValidator();
121     }
122     else if(_sfUpdateMode.getValue() == Self::PerViewport)
123     {
124         Viewarea *pVP = pAction->getViewarea();
126         pVal = pVP->getTravValidator();
127     }
128     else if(_sfUpdateMode.getValue() == Self::PerTraversal)
129     {
130         pVal = pAction->getTravValidator();
131     }
132     else if(_sfUpdateMode.getValue() == Self::OnRequest)
133     {
134         Window *pWin = pAction->getWindow();
136         pVal = pWin->getTravValidator();
138         return pVal->checkRunRequest(this->_iElementId);
139     }
140     else
141     {
142         return TraversalValidator::Run;
143     }
145     return pVal->validate(this->_iElementId, pAction->getFrameTravCount());
148 template <class ParentT> inline
149 void TraversalValidationHandlerMixin<ParentT>::addDestroyedFunctor(
150     ChangedFunctor func,
151     std::string    createSymbol)
153     ChangedFunctorCallback oTmp;
155     oTmp._func         = func;
156     oTmp._createSymbol = createSymbol;
158     _mfDestroyedFunctors.push_back(oTmp);
161 template <class ParentT> 
162 template<class FunctorT> inline
163 void TraversalValidationHandlerMixin<ParentT>::subDestroyedFunctor(
164     FunctorT func)
166     MFChangedFunctorCallback::iterator       cfIt = 
167         _mfDestroyedFunctors.begin();
169     MFChangedFunctorCallback::const_iterator cfEnd= 
170         _mfDestroyedFunctors.end();
172     for(; cfIt != cfEnd; ++cfIt)
173     {
174         if(cfIt->_func == func)
175             break;
176     }
178     if(cfIt != cfEnd)
179         _mfDestroyedFunctors.erase(cfIt);
182 template <class ParentT> 
183 template<class FunctorT> inline
184 bool TraversalValidationHandlerMixin<ParentT>::hasDestroyedFunctor(
185     FunctorT func)
187     bool returnValue = false;
189     MFChangedFunctorCallback::iterator       cfIt = 
190         _mfDestroyedFunctors.begin();
192     MFChangedFunctorCallback::const_iterator cfEnd= 
193         _mfDestroyedFunctors.end();
196     for(; cfIt != cfEnd; ++cfIt)
197     {
198         if(cfIt->_func == func)
199         {
200             returnValue = true;
201             break;
202         }
203     }
204     
205     return returnValue;
207 template <class ParentT> inline 
208 void TraversalValidationHandlerMixin<ParentT>::clearDestroyedFunctors(void)
210     _mfDestroyedFunctors.clear();
213 template <class ParentT> 
214 template<class DataSlotHandlerT> inline
215 void TraversalValidationHandlerMixin<ParentT>::clearDestroyedFunctorFor(
216     DataSlotHandlerT *pHandler)
218     this->subDestroyedFunctor(boost::bind(&DataSlotHandlerT::clearData,
219                                             pHandler,
220                                            _1,
221                                            _2,
222                                            _iDataSlotId));
225 /*-------------------------------------------------------------------------*/
226 /*                                Set                                      */
228 template <class ParentT> inline
229 void TraversalValidationHandlerMixin<ParentT>::setUpdateMode(UpdateMode eMode)
231     Inherited::editSField(UpdateModeFieldMask);
233     _sfUpdateMode.setValue(eMode);
236 template <class ParentT> inline
237 UInt32 TraversalValidationHandlerMixin<ParentT>::getUpdateMode(void) const
239     return _sfUpdateMode.getValue();
242 template <class ParentT> inline
243 SFUInt32 *TraversalValidationHandlerMixin<ParentT>::editSFUpdateMode(void)
245     Inherited::editSField(UpdateModeFieldMask);
247     return &_sfUpdateMode;
250 template <class ParentT> inline
251 const SFUInt32 *
252     TraversalValidationHandlerMixin<ParentT>::getSFUpdateMode(void) const
254     return &_sfUpdateMode;
257 /*-------------------------------------------------------------------------*/
258 /* Binary access                                                           */
260 template <class ParentT> inline
261 SizeT TraversalValidationHandlerMixin<ParentT>::getBinSize(
262     ConstFieldMaskArg whichField)
264     SizeT returnValue = Inherited::getBinSize(whichField);
266     if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
267     {
268         returnValue += _sfUpdateMode.getBinSize();
269     }
270     if(FieldBits::NoField != (RequestRunFieldMask & whichField))
271     {
272         returnValue += _sfRequestRun.getBinSize();
273     }
274     if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
275     {
276         returnValue += _mfDestroyedFunctors.getBinSize();
277     }
279     return returnValue;
282 template <class ParentT> inline
283 void TraversalValidationHandlerMixin<ParentT>::copyToBin(
284     BinaryDataHandler  &pMem, ConstFieldMaskArg whichField)
286     Inherited::copyToBin(pMem, whichField);
288     if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
289     {
290         _sfUpdateMode.copyToBin(pMem);
291     }
292     if(FieldBits::NoField != (RequestRunFieldMask & whichField))
293     {
294         _sfRequestRun.copyToBin(pMem);
295     }
296     if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
297     {
298         _mfDestroyedFunctors.copyToBin(pMem);
299     }
302 template <class ParentT> inline
303 void TraversalValidationHandlerMixin<ParentT>::copyFromBin(
304     BinaryDataHandler &pMem, ConstFieldMaskArg whichField)
306     Inherited::copyFromBin(pMem, whichField);
308     if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
309     {
310         Self::editSField(UpdateModeFieldMask);
312         _sfUpdateMode.copyFromBin(pMem);
313     }
314     if(FieldBits::NoField != (RequestRunFieldMask & whichField))
315     {
316         _sfRequestRun.copyFromBin(pMem);
317     }
318     if(FieldBits::NoField != (DestroyedFunctorsFieldMask & whichField))
319     {
320         Self::editMField(DestroyedFunctorsFieldMask, _mfDestroyedFunctors);
322         _mfDestroyedFunctors.copyFromBin(pMem);
323     }
326 /*-------------------------------------------------------------------------*/
327 /*                             Assignment                                  */
330 /*-------------------------------------------------------------------------*/
331 /*                            Constructors                                 */
333 template <class ParentT> inline
334 TraversalValidationHandlerMixin<ParentT>::TraversalValidationHandlerMixin(void):
335      Inherited          (            ),
336     _iDataSlotId        (-1          ),
337     _iElementId         (-1          ),
338     _sfUpdateMode       (PerTraversal),
339     _sfRequestRun       (            ),
340     _mfDestroyedFunctors(            )
342 #if 0
343     _tmpStatus = StageValidator::Finished;
344 #endif
347 template <class ParentT> inline
348 TraversalValidationHandlerMixin<ParentT>::TraversalValidationHandlerMixin(
349     const Self &source) :
351      Inherited          (source                     ),
352     _iDataSlotId        (-1                         ),
353     _iElementId         (-1                         ),
354     _sfUpdateMode       (source._sfUpdateMode       ),
355     _sfRequestRun       (source._sfRequestRun       ),
356     _mfDestroyedFunctors(source._mfDestroyedFunctors)
358 #if 0
359     _tmpStatus = StageValidator::Finished;
360 #endif
363 template <class ParentT> inline
364 TraversalValidationHandlerMixin<ParentT>::~TraversalValidationHandlerMixin(void)
368 template <class ParentT> inline
369 void TraversalValidationHandlerMixin<ParentT>::dump(
370           UInt32    uiIndent,
371     const BitVector bvFlags ) const
375 template <class ParentT> inline
376 EditFieldHandlePtr 
377     TraversalValidationHandlerMixin<ParentT>::editHandleUpdateMode(void)
379     SFUInt32::EditHandlePtr returnValue(
380         new  SFUInt32::EditHandle(
381              &_sfUpdateMode, 
382              this->getType().getFieldDesc(UpdateModeFieldId),
383              this));
385     Self::editSField(UpdateModeFieldMask);
387     return returnValue;
390 template <class ParentT> inline
391 GetFieldHandlePtr 
392     TraversalValidationHandlerMixin<ParentT>::getHandleUpdateMode(void) const
394     SFUInt32::GetHandlePtr returnValue(
395         new  SFUInt32::GetHandle(
396              &_sfUpdateMode, 
397              this->getType().getFieldDesc(UpdateModeFieldId),
398              const_cast<Self *>(this)));
400     return returnValue;
403 template <class ParentT> inline
404 GetFieldHandlePtr 
405     TraversalValidationHandlerMixin<ParentT>::getHandleRequestRun(void) const
407     SFOSGAny::GetHandlePtr returnValue(
408         new  SFOSGAny::GetHandle(
409              &_sfRequestRun, 
410              this->getType().getFieldDesc(RequestRunFieldId),
411              const_cast<Self *>(this)));
413     return returnValue;
416 template <class ParentT> inline
417 GetFieldHandlePtr
418     TraversalValidationHandlerMixin<ParentT>::getHandleDestroyedFunctors(
419         void) const
421     MFChangedFunctorCallback::GetHandlePtr returnValue(
422         new MFChangedFunctorCallback::GetHandle(
423             &_mfDestroyedFunctors,
424             this->getType().getFieldDesc(DestroyedFunctorsFieldId),
425             const_cast<Self *>(this)));
426     
427     return returnValue;
430 template <class ParentT> inline
431 EditFieldHandlePtr 
432     TraversalValidationHandlerMixin<ParentT>::editHandleDestroyedFunctors(void)
434     MFChangedFunctorCallback::EditHandlePtr returnValue(
435         new MFChangedFunctorCallback::EditHandle(
436             &_mfDestroyedFunctors,
437             this->getType().getFieldDesc(DestroyedFunctorsFieldId),
438             this));
439     
440     Self::editMField(DestroyedFunctorsFieldMask, _mfDestroyedFunctors);
441     
442     return returnValue;
445 /*-------------------------------------------------------------------------*/
446 /*                             Destructor                                  */
449 #ifdef OSG_MT_CPTR_ASPECT
450 template <class ParentT> inline
451 void TraversalValidationHandlerMixin<ParentT>::execSync(
452           Self              *pFrom,
453           ConstFieldMaskArg  whichField,
454                              AspectOffsetStore &oOffsets,
455           ConstFieldMaskArg  syncMode  ,
456     const UInt32             uiSyncInfo)
458     Inherited::execSync(pFrom, whichField, oOffsets, syncMode, uiSyncInfo);
460     if(FieldBits::NoField != (UpdateModeFieldMask & whichField))
461     {
462         _sfUpdateMode.syncWith(pFrom->_sfUpdateMode);
463     }
464     if(FieldBits::NoField != (RequestRunFieldMask & whichField))
465     {
466         _sfRequestRun.syncWith(pFrom->_sfRequestRun);
467     }
469 #endif
471 template <class ParentT> inline
472 void TraversalValidationHandlerMixin<ParentT>::onCreateAspect(
473     const Self   *createAspect,
474     const Self   *source      )
476     Inherited::onCreateAspect(createAspect, source);
478     // avoid prototype
479     if(GlobalSystemState == OSG::Running)
480     {
481         _iDataSlotId = createAspect->_iDataSlotId;
482         _iElementId  = createAspect->_iElementId;
483     }
486 template <class ParentT> inline
487 void TraversalValidationHandlerMixin<ParentT>::onCreate(const Self *source)
489     Inherited::onCreate(source);
491     // avoid prototype
492     if(GlobalSystemState == OSG::Running)
493     {
494         _iDataSlotId = DataSlotIdPool::the()->create();
495         _iElementId  = ElementIdPool ::the()->create();
496     }
499 template <class ParentT> inline
500 void TraversalValidationHandlerMixin<ParentT>::onDestroy(UInt32 uiContainerId)
502     Inherited::onDestroy(uiContainerId);
504     // avoid prototype
505     if(GlobalSystemState == OSG::Running)
506     {
507         DataSlotIdPool::the()->release(_iDataSlotId);
508         ElementIdPool ::the()->release(_iElementId );
509     }
512 template <class ParentT> inline
513 void TraversalValidationHandlerMixin<ParentT>::onDestroyAspect(
514     UInt32  uiContainerId,
515     UInt32  uiAspect     )
517     Inherited::onDestroy(uiContainerId);
519     // avoid prototype
520     if(GlobalSystemState == OSG::Running)
521     {
522         MFChangedFunctorCallback::iterator       cfIt = 
523             _mfDestroyedFunctors.begin();
525         MFChangedFunctorCallback::const_iterator cfEnd= 
526             _mfDestroyedFunctors.end();
527         
528         for(; cfIt != cfEnd; ++cfIt)
529         {
530             if(cfIt->_func)
531                 (cfIt->_func)(this, 0x0000, ChangedOrigin::External);
532         }
533     }
536 /*-------------------------------------------------------------------------*/
537 /*                             Assignment                                  */
539 /*-------------------------------------------------------------------------*/
540 /*                             Comparison                                  */
542 OSG_END_NAMESPACE