fixed: gcc8 compile issues
[opensg.git] / Source / Contrib / ComplexSceneManager / VRMLNodes / OSGLimitedCounters.inl
blobbfbe5b716a98b29abd4ba2cb305eb95c6104d5e3
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 LimitedCounterImpl<Desc>::getContainerSize(void) const
42     return sizeof(Self);
45 /*------------------------- decorator get ------------------------------*/
48 template<class Desc> inline
49 typename LimitedCounterImpl<Desc>::SFLimitType *
50     LimitedCounterImpl<Desc>::editSFUpperLimit(void)
52     Self::editSField(UpperLimitFieldMask);
54     return &_sfUpperLimit;
57 template<class Desc> inline
58 const typename LimitedCounterImpl<Desc>::SFLimitType *
59     LimitedCounterImpl<Desc>::getSFUpperLimit(void) const
61     return &_sfUpperLimit;
64 template<class Desc> inline
65 typename LimitedCounterImpl<Desc>::SFLimitType *
66     LimitedCounterImpl<Desc>::editSFLowerLimit(void)
68     Self::editSField(LowerLimitFieldMask);
70     return &_sfLowerLimit;
73 template<class Desc> inline
74 const typename LimitedCounterImpl<Desc>::SFLimitType *
75     LimitedCounterImpl<Desc>::getSFLowerLimit(void) const
77     return &_sfLowerLimit;
80 template<class Desc> inline
81 SFBool *LimitedCounterImpl<Desc>::editSFLoop(void)
83     Self::editSField(LoopFieldMask);
85     return &_sfLoop;
88 template<class Desc> inline
89 const SFBool *LimitedCounterImpl<Desc>::getSFLoop(void) const
91     return &_sfLoop;
94 /*------------------------------ get -----------------------------------*/
96 //! Get the value of the LimitedReal32Counter::_sfUpperLimit field.
98 template<class Desc> inline
99 typename LimitedCounterImpl<Desc>::LimitType &
100     LimitedCounterImpl<Desc>::editUpperLimit(void)
102     Self::editSField(UpperLimitFieldMask);
104     return _sfUpperLimit.getValue();
107 //! Get the value of the LimitedReal32Counter::_sfUpperLimit field.
108 template<class Desc> inline
109 typename LimitedCounterImpl<Desc>::LimitType 
110     LimitedCounterImpl<Desc>::getUpperLimit(void) const
112     return _sfUpperLimit.getValue();
115 //! Set the value of the LimitedReal32Counter::_sfUpperLimit field.
116 template<class Desc> inline
117 void LimitedCounterImpl<Desc>::setUpperLimit(const LimitType value)
119     Self::editSField(UpperLimitFieldMask);
121     _sfUpperLimit.setValue(value);
123 //! Get the value of the LimitedReal32Counter::_sfLowerLimit field.
125 template<class Desc> inline
126 typename LimitedCounterImpl<Desc>::LimitType &
127     LimitedCounterImpl<Desc>::editLowerLimit(void)
129     Self::editSField(LowerLimitFieldMask);
131     return _sfLowerLimit.getValue();
134 //! Get the value of the LimitedReal32Counter::_sfLowerLimit field.
135 template<class Desc> inline
136 typename LimitedCounterImpl<Desc>::LimitType 
137     LimitedCounterImpl<Desc>::getLowerLimit(void) const
139     return _sfLowerLimit.getValue();
142 //! Set the value of the LimitedReal32Counter::_sfLowerLimit field.
143 template<class Desc> inline
144 void LimitedCounterImpl<Desc>::setLowerLimit(const LimitType value)
146     Self::editSField(LowerLimitFieldMask);
148     _sfLowerLimit.setValue(value);
150 //! Get the value of the LimitedReal32Counter::_sfLoop field.
152 template<class Desc> inline
153 bool &LimitedCounterImpl<Desc>::editLoop(void)
155     Self::editSField(LoopFieldMask);
157     return _sfLoop.getValue();
160 //! Get the value of the LimitedReal32Counter::_sfLoop field.
161 template<class Desc> inline
162 bool  LimitedCounterImpl<Desc>::getLoop(void) const
164     return _sfLoop.getValue();
167 //! Set the value of the LimitedReal32Counter::_sfLoop field.
168 template<class Desc> inline
169 void LimitedCounterImpl<Desc>::setLoop(const bool value)
171     Self::editSField(LoopFieldMask);
173     _sfLoop.setValue(value);
177 template<class Desc> inline
178 void LimitedCounterImpl<Desc>::changed(ConstFieldMaskArg whichField, 
179                                        UInt32            origin,
180                                        BitVector         details)
182     Inherited::Inherited::changed(whichField, origin, details);
184     if((Self::IncTriggerFieldMask | Self::DecTriggerFieldMask) !=
185        (whichField & (Self::IncTriggerFieldMask | Self::DecTriggerFieldMask)))
186     {
188         if(0x0000 != (whichField & Self::IncTriggerFieldMask))
189         {
190             if(Self::getValue() >= getUpperLimit())
191             {
192                 if(Self::getLoop() == true)
193                 {
194                     Self::setValue(getLowerLimit());
195                 }
196                 else
197                 {
198                     Self::setValue(getUpperLimit());
199                 }
200             }
201             else
202             {
203                 Self::setValue(Self::getValue() + Self::getStep());
204             }
205         }
206         
207         if(0x0000 != (whichField & Self::DecTriggerFieldMask))
208         {
209             if(Self::getValue() <= getLowerLimit())
210             {
211                 if(Self::getLoop() == true)
212                 {
213                     Self::setValue(getUpperLimit());
214                 }
215                 else
216                 {
217                     Self::setValue(getLowerLimit());
218                 }
219             }
220             else
221             {
222                 Self::setValue(Self::getValue() - Self::getStep());
223             }
224         }
225     }
229 /*------------------------------ access -----------------------------------*/
231 template<class Desc> inline
232 SizeT LimitedCounterImpl<Desc>::getBinSize(ConstFieldMaskArg whichField)
234     SizeT returnValue = Inherited::getBinSize(whichField);
236     if(FieldBits::NoField != (UpperLimitFieldMask & whichField))
237     {
238         returnValue += _sfUpperLimit.getBinSize();
239     }
240     if(FieldBits::NoField != (LowerLimitFieldMask & whichField))
241     {
242         returnValue += _sfLowerLimit.getBinSize();
243     }
244     if(FieldBits::NoField != (LoopFieldMask & whichField))
245     {
246         returnValue += _sfLoop.getBinSize();
247     }
249     return returnValue;
252 template<class Desc> inline
253 void LimitedCounterImpl<Desc>::copyToBin(BinaryDataHandler &pMem,
254                                          ConstFieldMaskArg  whichField)
256     Inherited::copyToBin(pMem, whichField);
258     if(FieldBits::NoField != (UpperLimitFieldMask & whichField))
259     {
260         _sfUpperLimit.copyToBin(pMem);
261     }
262     if(FieldBits::NoField != (LowerLimitFieldMask & whichField))
263     {
264         _sfLowerLimit.copyToBin(pMem);
265     }
266     if(FieldBits::NoField != (LoopFieldMask & whichField))
267     {
268         _sfLoop.copyToBin(pMem);
269     }
272 template<class Desc> inline
273 void LimitedCounterImpl<Desc>::copyFromBin(BinaryDataHandler &pMem,
274                                            ConstFieldMaskArg  whichField)
276     Inherited::copyFromBin(pMem, whichField);
278     if(FieldBits::NoField != (UpperLimitFieldMask & whichField))
279     {
280         _sfUpperLimit.copyFromBin(pMem);
281     }
282     if(FieldBits::NoField != (LowerLimitFieldMask & whichField))
283     {
284         _sfLowerLimit.copyFromBin(pMem);
285     }
286     if(FieldBits::NoField != (LoopFieldMask & whichField))
287     {
288         _sfLoop.copyFromBin(pMem);
289     }
292 //! create a new instance of the class
293 template<class Desc> inline
294 typename LimitedCounterImpl<Desc>::ObjTransitPtr
295     LimitedCounterImpl<Desc>::createLocal(BitVector bFlags)
297     ObjTransitPtr fc;
299     if(getClassType().getPrototype() != NULL)
300     {
301         FieldContainerTransitPtr tmpPtr =
302             getClassType().getPrototype()-> shallowCopyLocal(bFlags);
304         fc = dynamic_pointer_cast<Self>(tmpPtr);
305     }
307     return fc;
310 //! create a new instance of the class
311 template<class Desc> inline
312 typename LimitedCounterImpl<Desc>::ObjTransitPtr
313     LimitedCounterImpl<Desc>::createDependent(BitVector bFlags)
315     ObjTransitPtr fc;
317     if(getClassType().getPrototype() != NULL)
318     {
319         FieldContainerTransitPtr tmpPtr =
320             getClassType().getPrototype()-> shallowCopyDependent(bFlags);
322         fc = dynamic_pointer_cast<Self>(tmpPtr);
323     }
325     return fc;
328 //! create a new instance of the class
329 template<class Desc> inline
330 typename LimitedCounterImpl<Desc>::ObjTransitPtr
331     LimitedCounterImpl<Desc>::create(void)
333     return createLocal();
336 template<class Desc> inline
337 typename LimitedCounterImpl<Desc>::Self *
338     LimitedCounterImpl<Desc>::createEmptyLocal(BitVector bFlags)
340     Self *returnValue;
342     Counter::newPtr<Self>(returnValue, bFlags);
344     returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
346     return returnValue;
349 //! create an empty new instance of the class, do not copy the prototype
350 template<class Desc> inline
351 typename LimitedCounterImpl<Desc>::Self *
352     LimitedCounterImpl<Desc>::createEmpty(void)
354     return createEmptyLocal();
357 template<class Desc> inline
358 FieldContainerTransitPtr LimitedCounterImpl<Desc>::shallowCopyLocal(
359     BitVector bFlags) const
361     Self *tmpPtr;
363     Self::newPtr(tmpPtr, dynamic_cast<const Self *>(this), bFlags);
365     FieldContainerTransitPtr returnValue(tmpPtr);
367     tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
369     return returnValue;
372 template<class Desc> inline
373 FieldContainerTransitPtr LimitedCounterImpl<Desc>::shallowCopyDependent(
374     BitVector bFlags) const
376     Self *tmpPtr;
378     Self::newPtr(tmpPtr, dynamic_cast<const Self *>(this), ~bFlags);
380     FieldContainerTransitPtr returnValue(tmpPtr);
382     tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
384     return returnValue;
387 template<class Desc> inline
388 FieldContainerTransitPtr LimitedCounterImpl<Desc>::shallowCopy(void) const
390     return shallowCopyLocal();
394 template<class Desc> inline
395 const Char8 *LimitedCounterImpl<Desc>::getClassname(void)
397     return Desc::getClassname();
400 /*------------------------- constructors ----------------------------------*/
402 template<class Desc> inline
403 LimitedCounterImpl<Desc>::LimitedCounterImpl(void) :
404      Inherited(),
405     _sfUpperLimit             (TypeTraits<LimitType>::getMin()),
406     _sfLowerLimit             (TypeTraits<LimitType>::getMax()),
407     _sfLoop                   (false)
411 template<class Desc> inline
412 LimitedCounterImpl<Desc>::LimitedCounterImpl(const LimitedCounterImpl &source) :
413      Inherited(source),
414     _sfUpperLimit             (source._sfUpperLimit             ),
415     _sfLowerLimit             (source._sfLowerLimit             ),
416     _sfLoop                   (source._sfLoop                   )
421 /*-------------------------- destructors ----------------------------------*/
423 template<class Desc> inline
424 LimitedCounterImpl<Desc>::~LimitedCounterImpl(void)
428 template<class Desc> inline
429 GetFieldHandlePtr LimitedCounterImpl<Desc>::getHandleUpperLimit(void) const
431     typename SFLimitType::GetHandlePtr returnValue(
432         new typename SFLimitType::GetHandle(
433              &_sfUpperLimit,
434              this->getType().getFieldDesc(UpperLimitFieldId),
435              const_cast<Self *>(this)));
436     
437     return returnValue;
440 template<class Desc> inline
441 EditFieldHandlePtr LimitedCounterImpl<Desc>::editHandleUpperLimit(void)
443     typename SFLimitType::EditHandlePtr returnValue(
444         new typename SFLimitType::EditHandle(
445              &_sfUpperLimit,
446              this->getType().getFieldDesc(UpperLimitFieldId),
447              this));
450     Self::editSField(UpperLimitFieldMask);
452     return returnValue;
455 template<class Desc> inline
456 GetFieldHandlePtr LimitedCounterImpl<Desc>::getHandleLowerLimit(void) const
458     typename SFLimitType::GetHandlePtr returnValue(
459         new typename SFLimitType::GetHandle(
460              &_sfLowerLimit,
461              this->getType().getFieldDesc(LowerLimitFieldId),
462              const_cast<Self *>(this)));
464     return returnValue;
467 template<class Desc> inline
468 EditFieldHandlePtr LimitedCounterImpl<Desc>::editHandleLowerLimit(void)
470     typename SFLimitType::EditHandlePtr returnValue(
471         new typename SFLimitType::EditHandle(
472              &_sfLowerLimit,
473              this->getType().getFieldDesc(LowerLimitFieldId),
474              this));
477     Self::editSField(LowerLimitFieldMask);
479     return returnValue;
482 template<class Desc> inline
483 GetFieldHandlePtr LimitedCounterImpl<Desc>::getHandleLoop(void) const
485     SFBool::GetHandlePtr returnValue(
486         new  SFBool::GetHandle(
487              &_sfLoop,
488              this->getType().getFieldDesc(LoopFieldId),
489              const_cast<Self *>(this)));
491     return returnValue;
494 template<class Desc> inline
495 EditFieldHandlePtr LimitedCounterImpl<Desc>::editHandleLoop(void)
497     SFBool::EditHandlePtr returnValue(
498         new  SFBool::EditHandle(
499              &_sfLoop,
500              this->getType().getFieldDesc(LoopFieldId),
501              this));
504     Self::editSField(LoopFieldMask);
506     return returnValue;
511 #ifdef OSG_MT_CPTR_ASPECT
512 template<class Desc> inline
513 void LimitedCounterImpl<Desc>::execSync (      Self              *pFrom,
514                                                ConstFieldMaskArg  whichField,
515                                                AspectOffsetStore &oOffsets,
516                                                ConstFieldMaskArg  syncMode,
517                                          const UInt32             uiSyncInfo)
519     Inherited::execSync(pFrom, whichField, oOffsets, syncMode, uiSyncInfo);
521     if(FieldBits::NoField != (UpperLimitFieldMask & whichField))
522         _sfUpperLimit.syncWith(pFrom->_sfUpperLimit);
524     if(FieldBits::NoField != (LowerLimitFieldMask & whichField))
525         _sfLowerLimit.syncWith(pFrom->_sfLowerLimit);
527     if(FieldBits::NoField != (LoopFieldMask & whichField))
528         _sfLoop.syncWith(pFrom->_sfLoop);
531 template<class Desc> inline
532 void LimitedCounterImpl<Desc>::execSyncV(      FieldContainer    &oFrom,
533                                                ConstFieldMaskArg  whichField,
534                                                AspectOffsetStore &oOffsets,
535                                                ConstFieldMaskArg  syncMode,
536                                          const UInt32             uiSyncInfo)
538     Self *pThis = static_cast<Self *>(this);
540     pThis->execSync(static_cast<Self *>(&oFrom),
541                     whichField,
542                     oOffsets,
543                     syncMode,
544                     uiSyncInfo);
547 template<class Desc> inline
548 FieldContainer *LimitedCounterImpl<Desc>::createAspectCopy(
549     const FieldContainer *pRefAspect) const
551     Self *returnValue;
553     this->newAspectCopy(returnValue,
554                         dynamic_cast<const Self *>(pRefAspect),
555                         dynamic_cast<const Self *>(this));
557     return returnValue;
559 #endif
561 template<class Desc> inline
562 void LimitedCounterImpl<Desc>::resolveLinks(void)
564     Inherited::resolveLinks();
569 template<class Desc> inline
570 void LimitedCounterImpl<Desc>::initMethod(InitPhase ePhase)
572     Inherited::initMethod(ePhase);
574     if(ePhase == TypeObject::SystemPost)
575     {
576     }
580 OSG_END_NAMESPACE