fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Base / OSGMultiCoreBase.cpp
blob586fd90a23f99efd673ef46bab6a0d8350788732
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 /*****************************************************************************\
40 *****************************************************************************
41 ** **
42 ** This file is automatically generated. **
43 ** **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
46 ** **
47 ** Do not change this file, changes should be done in the derived **
48 ** class MultiCore!
49 ** **
50 *****************************************************************************
51 \*****************************************************************************/
53 #include <cstdlib>
54 #include <cstdio>
56 #ifdef WIN32
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
59 #endif
61 #include "OSGConfig.h"
65 #include "OSGNodeCore.h" // Cores Class
67 #include "OSGMultiCoreBase.h"
68 #include "OSGMultiCore.h"
70 #include <boost/bind.hpp>
72 OSG_BEGIN_NAMESPACE
74 /***************************************************************************\
75 * Description *
76 \***************************************************************************/
78 /*! \class OSG::MultiCore
82 /***************************************************************************\
83 * Field Documentation *
84 \***************************************************************************/
86 /*! \var NodeCore * MultiCoreBase::_mfCores
90 /*! \var bool MultiCoreBase::_sfExitOnSkip
95 /***************************************************************************\
96 * FieldType/FieldTrait Instantiation *
97 \***************************************************************************/
99 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
100 PointerType FieldTraits<MultiCore *, nsOSG>::_type(
101 "MultiCorePtr",
102 "GroupPtr",
103 MultiCore::getClassType(),
104 nsOSG);
105 #endif
107 OSG_FIELDTRAITS_GETTYPE_NS(MultiCore *, nsOSG)
109 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
110 MultiCore *,
111 nsOSG)
113 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
114 MultiCore *,
115 nsOSG)
117 /***************************************************************************\
118 * Field Description *
119 \***************************************************************************/
121 void MultiCoreBase::classDescInserter(TypeObject &oType)
123 FieldDescriptionBase *pDesc = NULL;
126 pDesc = new MFUnrecChildNodeCorePtr::Description(
127 MFUnrecChildNodeCorePtr::getClassType(),
128 "cores",
130 CoresFieldId, CoresFieldMask,
131 false,
132 (Field::MFDefaultFlags | Field::FStdAccess),
133 static_cast<FieldEditMethodSig>(&MultiCore::editHandleCores),
134 static_cast<FieldGetMethodSig >(&MultiCore::getHandleCores));
136 oType.addInitialDesc(pDesc);
138 pDesc = new SFBool::Description(
139 SFBool::getClassType(),
140 "exitOnSkip",
142 ExitOnSkipFieldId, ExitOnSkipFieldMask,
143 false,
144 (Field::SFDefaultFlags | Field::FStdAccess),
145 static_cast<FieldEditMethodSig>(&MultiCore::editHandleExitOnSkip),
146 static_cast<FieldGetMethodSig >(&MultiCore::getHandleExitOnSkip));
148 oType.addInitialDesc(pDesc);
152 MultiCoreBase::TypeObject MultiCoreBase::_type(
153 MultiCoreBase::getClassname(),
154 Inherited::getClassname(),
155 "NULL",
156 nsOSG, //Namespace
157 reinterpret_cast<PrototypeCreateF>(&MultiCoreBase::createEmptyLocal),
158 reinterpret_cast<InitContainerF>(&MultiCore::initMethod),
159 reinterpret_cast<ExitContainerF>(&MultiCore::exitMethod),
160 reinterpret_cast<InitalInsertDescFunc>(
161 reinterpret_cast<void *>(&MultiCore::classDescInserter)),
162 false,
164 "<?xml version=\"1.0\" ?>\n"
165 "\n"
166 "<FieldContainer\n"
167 " name=\"MultiCore\"\n"
168 " parent=\"Group\"\n"
169 " library=\"System\"\n"
170 " structure=\"concrete\"\n"
171 " pointerfieldtypes=\"both\"\n"
172 " systemcomponent=\"true\"\n"
173 " parentsystemcomponent=\"true\"\n"
174 " docGroupBase=\"GrpSystemNodeCoreGroups\"\n"
175 " >\n"
176 " <Field\n"
177 " name=\"cores\"\n"
178 " type=\"NodeCore\"\n"
179 " cardinality=\"multi\"\n"
180 " visibility=\"external\"\n"
181 " access=\"protected\"\n"
182 " category=\"childpointer\"\n"
183 " childParentType=\"FieldContainer\"\n"
184 " linkParentField=\"Parents\"\n"
185 " \n"
186 " pushToFieldAs=\"addCore\"\n"
187 " assignMFieldAs=\"assignCoresFrom\"\n"
188 " insertIntoMFieldAs=\"insertCore\"\n"
189 " replaceInMFieldIndexAs=\"replaceCore\"\n"
190 " replaceInMFieldObjectAs=\"replaceCoreByObj\"\n"
191 " removeFromMFieldIndexAs=\"subCore\"\n"
192 " removeFromMFieldObjectAs=\"subCoreByObj\"\n"
193 " clearFieldAs=\"clearCores\"\n"
194 " >\n"
195 " </Field>\n"
196 "\n"
197 " <Field\n"
198 " name=\"exitOnSkip\"\n"
199 " type=\"bool\"\n"
200 " cardinality=\"single\"\n"
201 " visibility=\"external\"\n"
202 " defaultValue=\"false\">\n"
203 " </Field>\n"
204 "</FieldContainer>\n",
208 /*------------------------------ get -----------------------------------*/
210 FieldContainerType &MultiCoreBase::getType(void)
212 return _type;
215 const FieldContainerType &MultiCoreBase::getType(void) const
217 return _type;
220 UInt32 MultiCoreBase::getContainerSize(void) const
222 return sizeof(MultiCore);
225 /*------------------------- decorator get ------------------------------*/
228 //! Get the MultiCore::_mfCores field.
229 const MFUnrecChildNodeCorePtr *MultiCoreBase::getMFCores(void) const
231 return &_mfCores;
234 MFUnrecChildNodeCorePtr *MultiCoreBase::editMFCores (void)
236 editMField(CoresFieldMask, _mfCores);
238 return &_mfCores;
240 NodeCore * MultiCoreBase::getCores(const UInt32 index) const
242 return _mfCores[index];
245 SFBool *MultiCoreBase::editSFExitOnSkip(void)
247 editSField(ExitOnSkipFieldMask);
249 return &_sfExitOnSkip;
252 const SFBool *MultiCoreBase::getSFExitOnSkip(void) const
254 return &_sfExitOnSkip;
260 void MultiCoreBase::addCore(NodeCore * const value)
262 editMField(CoresFieldMask, _mfCores);
264 _mfCores.push_back(value);
267 void MultiCoreBase::assignCoresFrom(const MFUnrecChildNodeCorePtr &value)
269 MFUnrecChildNodeCorePtr::const_iterator elemIt =
270 value.begin();
271 MFUnrecChildNodeCorePtr::const_iterator elemEnd =
272 value.end ();
274 static_cast<MultiCore *>(this)->clearCores();
276 while(elemIt != elemEnd)
278 this->addCore(*elemIt);
280 ++elemIt;
284 void MultiCoreBase::subCore(UInt32 uiIndex)
286 if(uiIndex < _mfCores.size())
288 editMField(CoresFieldMask, _mfCores);
290 _mfCores.erase(uiIndex);
294 void MultiCoreBase::subCoreByObj(NodeCore * const value)
296 Int32 iElemIdx = _mfCores.findIndex(value);
298 if(iElemIdx != -1)
300 editMField(CoresFieldMask, _mfCores);
302 _mfCores.erase(iElemIdx);
305 void MultiCoreBase::clearCores(void)
307 editMField(CoresFieldMask, _mfCores);
310 _mfCores.clear();
315 /*------------------------------ access -----------------------------------*/
317 SizeT MultiCoreBase::getBinSize(ConstFieldMaskArg whichField)
319 SizeT returnValue = Inherited::getBinSize(whichField);
321 if(FieldBits::NoField != (CoresFieldMask & whichField))
323 returnValue += _mfCores.getBinSize();
325 if(FieldBits::NoField != (ExitOnSkipFieldMask & whichField))
327 returnValue += _sfExitOnSkip.getBinSize();
330 return returnValue;
333 void MultiCoreBase::copyToBin(BinaryDataHandler &pMem,
334 ConstFieldMaskArg whichField)
336 Inherited::copyToBin(pMem, whichField);
338 if(FieldBits::NoField != (CoresFieldMask & whichField))
340 _mfCores.copyToBin(pMem);
342 if(FieldBits::NoField != (ExitOnSkipFieldMask & whichField))
344 _sfExitOnSkip.copyToBin(pMem);
348 void MultiCoreBase::copyFromBin(BinaryDataHandler &pMem,
349 ConstFieldMaskArg whichField)
351 Inherited::copyFromBin(pMem, whichField);
353 if(FieldBits::NoField != (CoresFieldMask & whichField))
355 editMField(CoresFieldMask, _mfCores);
356 _mfCores.copyFromBin(pMem);
358 if(FieldBits::NoField != (ExitOnSkipFieldMask & whichField))
360 editSField(ExitOnSkipFieldMask);
361 _sfExitOnSkip.copyFromBin(pMem);
365 //! create a new instance of the class
366 MultiCoreTransitPtr MultiCoreBase::createLocal(BitVector bFlags)
368 MultiCoreTransitPtr fc;
370 if(getClassType().getPrototype() != NULL)
372 FieldContainerTransitPtr tmpPtr =
373 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
375 fc = dynamic_pointer_cast<MultiCore>(tmpPtr);
378 return fc;
381 //! create a new instance of the class, copy the container flags
382 MultiCoreTransitPtr MultiCoreBase::createDependent(BitVector bFlags)
384 MultiCoreTransitPtr fc;
386 if(getClassType().getPrototype() != NULL)
388 FieldContainerTransitPtr tmpPtr =
389 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
391 fc = dynamic_pointer_cast<MultiCore>(tmpPtr);
394 return fc;
397 //! create a new instance of the class
398 MultiCoreTransitPtr MultiCoreBase::create(void)
400 MultiCoreTransitPtr fc;
402 if(getClassType().getPrototype() != NULL)
404 FieldContainerTransitPtr tmpPtr =
405 getClassType().getPrototype()-> shallowCopy();
407 fc = dynamic_pointer_cast<MultiCore>(tmpPtr);
410 return fc;
413 MultiCore *MultiCoreBase::createEmptyLocal(BitVector bFlags)
415 MultiCore *returnValue;
417 newPtr<MultiCore>(returnValue, bFlags);
419 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
421 return returnValue;
424 //! create an empty new instance of the class, do not copy the prototype
425 MultiCore *MultiCoreBase::createEmpty(void)
427 MultiCore *returnValue;
429 newPtr<MultiCore>(returnValue, Thread::getCurrentLocalFlags());
431 returnValue->_pFieldFlags->_bNamespaceMask &=
432 ~Thread::getCurrentLocalFlags();
434 return returnValue;
438 FieldContainerTransitPtr MultiCoreBase::shallowCopyLocal(
439 BitVector bFlags) const
441 MultiCore *tmpPtr;
443 newPtr(tmpPtr, dynamic_cast<const MultiCore *>(this), bFlags);
445 FieldContainerTransitPtr returnValue(tmpPtr);
447 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
449 return returnValue;
452 FieldContainerTransitPtr MultiCoreBase::shallowCopyDependent(
453 BitVector bFlags) const
455 MultiCore *tmpPtr;
457 newPtr(tmpPtr, dynamic_cast<const MultiCore *>(this), ~bFlags);
459 FieldContainerTransitPtr returnValue(tmpPtr);
461 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
463 return returnValue;
466 FieldContainerTransitPtr MultiCoreBase::shallowCopy(void) const
468 MultiCore *tmpPtr;
470 newPtr(tmpPtr,
471 dynamic_cast<const MultiCore *>(this),
472 Thread::getCurrentLocalFlags());
474 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
476 FieldContainerTransitPtr returnValue(tmpPtr);
478 return returnValue;
484 /*------------------------- constructors ----------------------------------*/
486 MultiCoreBase::MultiCoreBase(void) :
487 Inherited(),
488 _mfCores (this,
489 CoresFieldId,
490 NodeCore::ParentsFieldId),
491 _sfExitOnSkip (bool(false))
495 MultiCoreBase::MultiCoreBase(const MultiCoreBase &source) :
496 Inherited(source),
497 _mfCores (this,
498 CoresFieldId,
499 NodeCore::ParentsFieldId),
500 _sfExitOnSkip (source._sfExitOnSkip )
505 /*-------------------------- destructors ----------------------------------*/
507 MultiCoreBase::~MultiCoreBase(void)
511 /*-------------------------------------------------------------------------*/
512 /* Child linking */
514 bool MultiCoreBase::unlinkChild(
515 FieldContainer * const pChild,
516 UInt16 const childFieldId)
518 if(childFieldId == CoresFieldId)
520 NodeCore * pTypedChild =
521 dynamic_cast<NodeCore *>(pChild);
523 if(pTypedChild != NULL)
525 Int32 iChildIdx = _mfCores.findIndex(pTypedChild);
527 if(iChildIdx != -1)
529 editMField(CoresFieldMask, _mfCores);
531 _mfCores.erase(iChildIdx);
533 return true;
536 SWARNING << "Parent ([" << this
537 << "] id [" << this->getId()
538 << "] type [" << this->getType().getCName()
539 << "] childFieldId [" << childFieldId
540 << "]) - Child ([" << pChild
541 << "] id [" << pChild->getId()
542 << "] type [" << pChild->getType().getCName()
543 << "]): link inconsistent!"
544 << std::endl;
546 return false;
549 return false;
553 return Inherited::unlinkChild(pChild, childFieldId);
556 void MultiCoreBase::onCreate(const MultiCore *source)
558 Inherited::onCreate(source);
560 if(source != NULL)
562 MultiCore *pThis = static_cast<MultiCore *>(this);
564 MFUnrecChildNodeCorePtr::const_iterator CoresIt =
565 source->_mfCores.begin();
566 MFUnrecChildNodeCorePtr::const_iterator CoresEnd =
567 source->_mfCores.end ();
569 while(CoresIt != CoresEnd)
571 pThis->addCore(*CoresIt);
573 ++CoresIt;
578 GetFieldHandlePtr MultiCoreBase::getHandleCores (void) const
580 MFUnrecChildNodeCorePtr::GetHandlePtr returnValue(
581 new MFUnrecChildNodeCorePtr::GetHandle(
582 &_mfCores,
583 this->getType().getFieldDesc(CoresFieldId),
584 const_cast<MultiCoreBase *>(this)));
586 return returnValue;
589 EditFieldHandlePtr MultiCoreBase::editHandleCores (void)
591 MFUnrecChildNodeCorePtr::EditHandlePtr returnValue(
592 new MFUnrecChildNodeCorePtr::EditHandle(
593 &_mfCores,
594 this->getType().getFieldDesc(CoresFieldId),
595 this));
597 returnValue->setAddMethod(
598 boost::bind(&MultiCore::addCore,
599 static_cast<MultiCore *>(this), _1));
600 returnValue->setRemoveMethod(
601 boost::bind(&MultiCore::subCore,
602 static_cast<MultiCore *>(this), _1));
603 returnValue->setRemoveObjMethod(
604 boost::bind(&MultiCore::subCoreByObj,
605 static_cast<MultiCore *>(this), _1));
606 returnValue->setClearMethod(
607 boost::bind(&MultiCore::clearCores,
608 static_cast<MultiCore *>(this)));
610 editMField(CoresFieldMask, _mfCores);
612 return returnValue;
615 GetFieldHandlePtr MultiCoreBase::getHandleExitOnSkip (void) const
617 SFBool::GetHandlePtr returnValue(
618 new SFBool::GetHandle(
619 &_sfExitOnSkip,
620 this->getType().getFieldDesc(ExitOnSkipFieldId),
621 const_cast<MultiCoreBase *>(this)));
623 return returnValue;
626 EditFieldHandlePtr MultiCoreBase::editHandleExitOnSkip (void)
628 SFBool::EditHandlePtr returnValue(
629 new SFBool::EditHandle(
630 &_sfExitOnSkip,
631 this->getType().getFieldDesc(ExitOnSkipFieldId),
632 this));
635 editSField(ExitOnSkipFieldMask);
637 return returnValue;
641 #ifdef OSG_MT_CPTR_ASPECT
642 void MultiCoreBase::execSyncV( FieldContainer &oFrom,
643 ConstFieldMaskArg whichField,
644 AspectOffsetStore &oOffsets,
645 ConstFieldMaskArg syncMode,
646 const UInt32 uiSyncInfo)
648 MultiCore *pThis = static_cast<MultiCore *>(this);
650 pThis->execSync(static_cast<MultiCore *>(&oFrom),
651 whichField,
652 oOffsets,
653 syncMode,
654 uiSyncInfo);
656 #endif
659 #ifdef OSG_MT_CPTR_ASPECT
660 FieldContainer *MultiCoreBase::createAspectCopy(
661 const FieldContainer *pRefAspect) const
663 MultiCore *returnValue;
665 newAspectCopy(returnValue,
666 dynamic_cast<const MultiCore *>(pRefAspect),
667 dynamic_cast<const MultiCore *>(this));
669 return returnValue;
671 #endif
673 void MultiCoreBase::resolveLinks(void)
675 Inherited::resolveLinks();
677 static_cast<MultiCore *>(this)->clearCores();
683 OSG_END_NAMESPACE