fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FieldContainer / Misc / OSGContainerCollectionBase.cpp
blob40fe62d7348a50c3e685e3e578281e3c6c1bcb2a
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 ContainerCollection!
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 "OSGFieldContainer.h" // Containers Class
67 #include "OSGContainerCollectionBase.h"
68 #include "OSGContainerCollection.h"
70 #include <boost/bind.hpp>
72 OSG_BEGIN_NAMESPACE
74 /***************************************************************************\
75 * Description *
76 \***************************************************************************/
78 /*! \class OSG::ContainerCollection
82 /***************************************************************************\
83 * Field Documentation *
84 \***************************************************************************/
86 /*! \var std::string ContainerCollectionBase::_sfName
87 The name of the container collection. Can be used to identify collections.
90 /*! \var FieldContainer * ContainerCollectionBase::_mfContainers
91 A list of containers held in the collection.
95 /***************************************************************************\
96 * FieldType/FieldTrait Instantiation *
97 \***************************************************************************/
99 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
100 PointerType FieldTraits<ContainerCollection *, nsOSG>::_type(
101 "ContainerCollectionPtr",
102 "AttachmentPtr",
103 ContainerCollection::getClassType(),
104 nsOSG);
105 #endif
107 OSG_FIELDTRAITS_GETTYPE_NS(ContainerCollection *, nsOSG)
109 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
110 ContainerCollection *,
111 nsOSG)
113 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
114 ContainerCollection *,
115 nsOSG)
117 /***************************************************************************\
118 * Field Description *
119 \***************************************************************************/
121 void ContainerCollectionBase::classDescInserter(TypeObject &oType)
123 FieldDescriptionBase *pDesc = NULL;
126 pDesc = new SFString::Description(
127 SFString::getClassType(),
128 "name",
129 "The name of the container collection. Can be used to identify collections.\n",
130 NameFieldId, NameFieldMask,
131 false,
132 (Field::SFDefaultFlags | Field::FStdAccess),
133 static_cast<FieldEditMethodSig>(&ContainerCollection::editHandleName),
134 static_cast<FieldGetMethodSig >(&ContainerCollection::getHandleName));
136 oType.addInitialDesc(pDesc);
138 pDesc = new MFUnrecFieldContainerPtr::Description(
139 MFUnrecFieldContainerPtr::getClassType(),
140 "containers",
141 "A list of containers held in the collection.\n",
142 ContainersFieldId, ContainersFieldMask,
143 false,
144 (Field::MFDefaultFlags | Field::FStdAccess),
145 static_cast<FieldEditMethodSig>(&ContainerCollection::editHandleContainers),
146 static_cast<FieldGetMethodSig >(&ContainerCollection::getHandleContainers));
148 oType.addInitialDesc(pDesc);
152 ContainerCollectionBase::TypeObject ContainerCollectionBase::_type(
153 ContainerCollectionBase::getClassname(),
154 Inherited::getClassname(),
155 "ContainerCollection",
156 nsOSG, //Namespace
157 reinterpret_cast<PrototypeCreateF>(&ContainerCollectionBase::createEmptyLocal),
158 reinterpret_cast<InitContainerF>(&ContainerCollection::initMethod),
159 reinterpret_cast<ExitContainerF>(&ContainerCollection::exitMethod),
160 reinterpret_cast<InitalInsertDescFunc>(
161 reinterpret_cast<void *>(&ContainerCollection::classDescInserter)),
162 false,
164 "<?xml version=\"1.0\" ?>\n"
165 "\n"
166 "<FieldContainer\n"
167 " name=\"ContainerCollection\"\n"
168 " parent=\"Attachment\"\n"
169 " library=\"System\"\n"
170 " structure=\"concrete\"\n"
171 " pointerfieldtypes=\"both\"\n"
172 " systemcomponent=\"true\"\n"
173 " parentsystemcomponent=\"true\"\n"
174 " docGroupBase=\"GrpSystemFieldContainer\"\n"
175 " >\n"
176 " <Field\n"
177 "\t name=\"name\"\n"
178 "\t type=\"std::string\"\n"
179 "\t cardinality=\"single\"\n"
180 "\t visibility=\"external\"\n"
181 "\t access=\"public\"\n"
182 "\t >\n"
183 "\tThe name of the container collection. Can be used to identify collections.\n"
184 " </Field>\n"
185 " <Field\n"
186 "\t name=\"containers\"\n"
187 "\t type=\"FieldContainerPtr\"\n"
188 "\t cardinality=\"multi\"\n"
189 "\t visibility=\"external\"\n"
190 " access=\"public\"\n"
191 "\t >\n"
192 " A list of containers held in the collection.\n"
193 " </Field>\n"
194 "</FieldContainer>\n",
198 /*------------------------------ get -----------------------------------*/
200 FieldContainerType &ContainerCollectionBase::getType(void)
202 return _type;
205 const FieldContainerType &ContainerCollectionBase::getType(void) const
207 return _type;
210 UInt32 ContainerCollectionBase::getContainerSize(void) const
212 return sizeof(ContainerCollection);
215 /*------------------------- decorator get ------------------------------*/
218 SFString *ContainerCollectionBase::editSFName(void)
220 editSField(NameFieldMask);
222 return &_sfName;
225 const SFString *ContainerCollectionBase::getSFName(void) const
227 return &_sfName;
231 //! Get the ContainerCollection::_mfContainers field.
232 const MFUnrecFieldContainerPtr *ContainerCollectionBase::getMFContainers(void) const
234 return &_mfContainers;
237 MFUnrecFieldContainerPtr *ContainerCollectionBase::editMFContainers (void)
239 editMField(ContainersFieldMask, _mfContainers);
241 return &_mfContainers;
243 FieldContainer * ContainerCollectionBase::getContainers(const UInt32 index) const
245 return _mfContainers[index];
250 void ContainerCollectionBase::pushToContainers(FieldContainer * const value)
252 editMField(ContainersFieldMask, _mfContainers);
254 _mfContainers.push_back(value);
257 void ContainerCollectionBase::assignContainers(const MFUnrecFieldContainerPtr &value)
259 MFUnrecFieldContainerPtr::const_iterator elemIt =
260 value.begin();
261 MFUnrecFieldContainerPtr::const_iterator elemEnd =
262 value.end ();
264 static_cast<ContainerCollection *>(this)->clearContainers();
266 while(elemIt != elemEnd)
268 this->pushToContainers(*elemIt);
270 ++elemIt;
274 void ContainerCollectionBase::removeFromContainers(UInt32 uiIndex)
276 if(uiIndex < _mfContainers.size())
278 editMField(ContainersFieldMask, _mfContainers);
280 _mfContainers.erase(uiIndex);
284 void ContainerCollectionBase::removeObjFromContainers(FieldContainer * const value)
286 Int32 iElemIdx = _mfContainers.findIndex(value);
288 if(iElemIdx != -1)
290 editMField(ContainersFieldMask, _mfContainers);
292 _mfContainers.erase(iElemIdx);
295 void ContainerCollectionBase::clearContainers(void)
297 editMField(ContainersFieldMask, _mfContainers);
300 _mfContainers.clear();
305 /*------------------------------ access -----------------------------------*/
307 SizeT ContainerCollectionBase::getBinSize(ConstFieldMaskArg whichField)
309 SizeT returnValue = Inherited::getBinSize(whichField);
311 if(FieldBits::NoField != (NameFieldMask & whichField))
313 returnValue += _sfName.getBinSize();
315 if(FieldBits::NoField != (ContainersFieldMask & whichField))
317 returnValue += _mfContainers.getBinSize();
320 return returnValue;
323 void ContainerCollectionBase::copyToBin(BinaryDataHandler &pMem,
324 ConstFieldMaskArg whichField)
326 Inherited::copyToBin(pMem, whichField);
328 if(FieldBits::NoField != (NameFieldMask & whichField))
330 _sfName.copyToBin(pMem);
332 if(FieldBits::NoField != (ContainersFieldMask & whichField))
334 _mfContainers.copyToBin(pMem);
338 void ContainerCollectionBase::copyFromBin(BinaryDataHandler &pMem,
339 ConstFieldMaskArg whichField)
341 Inherited::copyFromBin(pMem, whichField);
343 if(FieldBits::NoField != (NameFieldMask & whichField))
345 editSField(NameFieldMask);
346 _sfName.copyFromBin(pMem);
348 if(FieldBits::NoField != (ContainersFieldMask & whichField))
350 editMField(ContainersFieldMask, _mfContainers);
351 _mfContainers.copyFromBin(pMem);
355 //! create a new instance of the class
356 ContainerCollectionTransitPtr ContainerCollectionBase::createLocal(BitVector bFlags)
358 ContainerCollectionTransitPtr fc;
360 if(getClassType().getPrototype() != NULL)
362 FieldContainerTransitPtr tmpPtr =
363 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
365 fc = dynamic_pointer_cast<ContainerCollection>(tmpPtr);
368 return fc;
371 //! create a new instance of the class, copy the container flags
372 ContainerCollectionTransitPtr ContainerCollectionBase::createDependent(BitVector bFlags)
374 ContainerCollectionTransitPtr fc;
376 if(getClassType().getPrototype() != NULL)
378 FieldContainerTransitPtr tmpPtr =
379 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
381 fc = dynamic_pointer_cast<ContainerCollection>(tmpPtr);
384 return fc;
387 //! create a new instance of the class
388 ContainerCollectionTransitPtr ContainerCollectionBase::create(void)
390 ContainerCollectionTransitPtr fc;
392 if(getClassType().getPrototype() != NULL)
394 FieldContainerTransitPtr tmpPtr =
395 getClassType().getPrototype()-> shallowCopy();
397 fc = dynamic_pointer_cast<ContainerCollection>(tmpPtr);
400 return fc;
403 ContainerCollection *ContainerCollectionBase::createEmptyLocal(BitVector bFlags)
405 ContainerCollection *returnValue;
407 newPtr<ContainerCollection>(returnValue, bFlags);
409 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
411 return returnValue;
414 //! create an empty new instance of the class, do not copy the prototype
415 ContainerCollection *ContainerCollectionBase::createEmpty(void)
417 ContainerCollection *returnValue;
419 newPtr<ContainerCollection>(returnValue, Thread::getCurrentLocalFlags());
421 returnValue->_pFieldFlags->_bNamespaceMask &=
422 ~Thread::getCurrentLocalFlags();
424 return returnValue;
428 FieldContainerTransitPtr ContainerCollectionBase::shallowCopyLocal(
429 BitVector bFlags) const
431 ContainerCollection *tmpPtr;
433 newPtr(tmpPtr, dynamic_cast<const ContainerCollection *>(this), bFlags);
435 FieldContainerTransitPtr returnValue(tmpPtr);
437 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
439 return returnValue;
442 FieldContainerTransitPtr ContainerCollectionBase::shallowCopyDependent(
443 BitVector bFlags) const
445 ContainerCollection *tmpPtr;
447 newPtr(tmpPtr, dynamic_cast<const ContainerCollection *>(this), ~bFlags);
449 FieldContainerTransitPtr returnValue(tmpPtr);
451 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
453 return returnValue;
456 FieldContainerTransitPtr ContainerCollectionBase::shallowCopy(void) const
458 ContainerCollection *tmpPtr;
460 newPtr(tmpPtr,
461 dynamic_cast<const ContainerCollection *>(this),
462 Thread::getCurrentLocalFlags());
464 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
466 FieldContainerTransitPtr returnValue(tmpPtr);
468 return returnValue;
474 /*------------------------- constructors ----------------------------------*/
476 ContainerCollectionBase::ContainerCollectionBase(void) :
477 Inherited(),
478 _sfName (),
479 _mfContainers ()
483 ContainerCollectionBase::ContainerCollectionBase(const ContainerCollectionBase &source) :
484 Inherited(source),
485 _sfName (source._sfName ),
486 _mfContainers ()
491 /*-------------------------- destructors ----------------------------------*/
493 ContainerCollectionBase::~ContainerCollectionBase(void)
497 void ContainerCollectionBase::onCreate(const ContainerCollection *source)
499 Inherited::onCreate(source);
501 if(source != NULL)
503 ContainerCollection *pThis = static_cast<ContainerCollection *>(this);
505 MFUnrecFieldContainerPtr::const_iterator ContainersIt =
506 source->_mfContainers.begin();
507 MFUnrecFieldContainerPtr::const_iterator ContainersEnd =
508 source->_mfContainers.end ();
510 while(ContainersIt != ContainersEnd)
512 pThis->pushToContainers(*ContainersIt);
514 ++ContainersIt;
519 GetFieldHandlePtr ContainerCollectionBase::getHandleName (void) const
521 SFString::GetHandlePtr returnValue(
522 new SFString::GetHandle(
523 &_sfName,
524 this->getType().getFieldDesc(NameFieldId),
525 const_cast<ContainerCollectionBase *>(this)));
527 return returnValue;
530 EditFieldHandlePtr ContainerCollectionBase::editHandleName (void)
532 SFString::EditHandlePtr returnValue(
533 new SFString::EditHandle(
534 &_sfName,
535 this->getType().getFieldDesc(NameFieldId),
536 this));
539 editSField(NameFieldMask);
541 return returnValue;
544 GetFieldHandlePtr ContainerCollectionBase::getHandleContainers (void) const
546 MFUnrecFieldContainerPtr::GetHandlePtr returnValue(
547 new MFUnrecFieldContainerPtr::GetHandle(
548 &_mfContainers,
549 this->getType().getFieldDesc(ContainersFieldId),
550 const_cast<ContainerCollectionBase *>(this)));
552 return returnValue;
555 EditFieldHandlePtr ContainerCollectionBase::editHandleContainers (void)
557 MFUnrecFieldContainerPtr::EditHandlePtr returnValue(
558 new MFUnrecFieldContainerPtr::EditHandle(
559 &_mfContainers,
560 this->getType().getFieldDesc(ContainersFieldId),
561 this));
563 returnValue->setAddMethod(
564 boost::bind(&ContainerCollection::pushToContainers,
565 static_cast<ContainerCollection *>(this), _1));
566 returnValue->setRemoveMethod(
567 boost::bind(&ContainerCollection::removeFromContainers,
568 static_cast<ContainerCollection *>(this), _1));
569 returnValue->setRemoveObjMethod(
570 boost::bind(&ContainerCollection::removeObjFromContainers,
571 static_cast<ContainerCollection *>(this), _1));
572 returnValue->setClearMethod(
573 boost::bind(&ContainerCollection::clearContainers,
574 static_cast<ContainerCollection *>(this)));
576 editMField(ContainersFieldMask, _mfContainers);
578 return returnValue;
582 #ifdef OSG_MT_CPTR_ASPECT
583 void ContainerCollectionBase::execSyncV( FieldContainer &oFrom,
584 ConstFieldMaskArg whichField,
585 AspectOffsetStore &oOffsets,
586 ConstFieldMaskArg syncMode,
587 const UInt32 uiSyncInfo)
589 ContainerCollection *pThis = static_cast<ContainerCollection *>(this);
591 pThis->execSync(static_cast<ContainerCollection *>(&oFrom),
592 whichField,
593 oOffsets,
594 syncMode,
595 uiSyncInfo);
597 #endif
600 #ifdef OSG_MT_CPTR_ASPECT
601 FieldContainer *ContainerCollectionBase::createAspectCopy(
602 const FieldContainer *pRefAspect) const
604 ContainerCollection *returnValue;
606 newAspectCopy(returnValue,
607 dynamic_cast<const ContainerCollection *>(pRefAspect),
608 dynamic_cast<const ContainerCollection *>(this));
610 return returnValue;
612 #endif
614 void ContainerCollectionBase::resolveLinks(void)
616 Inherited::resolveLinks();
618 static_cast<ContainerCollection *>(this)->clearContainers();
624 OSG_END_NAMESPACE