fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Shader / SHL / OSGSimpleSHLVariableChunkBase.cpp
blobe8232bfc5e43e9b7cb8b74ee73acc16d520fa2a3
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 SimpleSHLVariableChunk!
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 "OSGShaderProgramVariables.h" // Variables Class
67 #include "OSGSimpleSHLVariableChunkBase.h"
68 #include "OSGSimpleSHLVariableChunk.h"
70 #include <boost/bind.hpp>
72 OSG_BEGIN_NAMESPACE
74 /***************************************************************************\
75 * Description *
76 \***************************************************************************/
78 /*! \class OSG::SimpleSHLVariableChunk
82 /***************************************************************************\
83 * Field Documentation *
84 \***************************************************************************/
86 /*! \var ShaderProgramVariables * SimpleSHLVariableChunkBase::_sfVariables
87 fragment program object
90 /*! \var Int32 SimpleSHLVariableChunkBase::_mfVariableLocations
91 fragment program object
95 /***************************************************************************\
96 * FieldType/FieldTrait Instantiation *
97 \***************************************************************************/
99 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
100 PointerType FieldTraits<SimpleSHLVariableChunk *, nsOSG>::_type(
101 "SimpleSHLVariableChunkPtr",
102 "StateChunkPtr",
103 SimpleSHLVariableChunk::getClassType(),
104 nsOSG);
105 #endif
107 OSG_FIELDTRAITS_GETTYPE_NS(SimpleSHLVariableChunk *, nsOSG)
109 OSG_EXPORT_PTR_SFIELD_FULL(PointerSField,
110 SimpleSHLVariableChunk *,
111 nsOSG)
113 OSG_EXPORT_PTR_MFIELD_FULL(PointerMField,
114 SimpleSHLVariableChunk *,
115 nsOSG)
117 /***************************************************************************\
118 * Field Description *
119 \***************************************************************************/
121 void SimpleSHLVariableChunkBase::classDescInserter(TypeObject &oType)
123 FieldDescriptionBase *pDesc = NULL;
126 pDesc = new SFUnrecChildShaderProgramVariablesPtr::Description(
127 SFUnrecChildShaderProgramVariablesPtr::getClassType(),
128 "variables",
129 "fragment program object\n",
130 VariablesFieldId, VariablesFieldMask,
131 false,
132 (Field::SFDefaultFlags | Field::FStdAccess),
133 static_cast<FieldEditMethodSig>(&SimpleSHLVariableChunk::editHandleVariables),
134 static_cast<FieldGetMethodSig >(&SimpleSHLVariableChunk::getHandleVariables));
136 oType.addInitialDesc(pDesc);
138 pDesc = new MFInt32::Description(
139 MFInt32::getClassType(),
140 "variableLocations",
141 "fragment program object\n",
142 VariableLocationsFieldId, VariableLocationsFieldMask,
143 true,
144 (Field::MFDefaultFlags | Field::FStdAccess),
145 static_cast<FieldEditMethodSig>(&SimpleSHLVariableChunk::editHandleVariableLocations),
146 static_cast<FieldGetMethodSig >(&SimpleSHLVariableChunk::getHandleVariableLocations));
148 oType.addInitialDesc(pDesc);
152 SimpleSHLVariableChunkBase::TypeObject SimpleSHLVariableChunkBase::_type(
153 SimpleSHLVariableChunkBase::getClassname(),
154 Inherited::getClassname(),
155 "NULL",
156 nsOSG, //Namespace
157 reinterpret_cast<PrototypeCreateF>(&SimpleSHLVariableChunkBase::createEmptyLocal),
158 reinterpret_cast<InitContainerF>(&SimpleSHLVariableChunk::initMethod),
159 reinterpret_cast<ExitContainerF>(&SimpleSHLVariableChunk::exitMethod),
160 reinterpret_cast<InitalInsertDescFunc>(
161 reinterpret_cast<void *>(&SimpleSHLVariableChunk::classDescInserter)),
162 false,
164 "<?xml version=\"1.0\"?>\n"
165 "\n"
166 "<FieldContainer\n"
167 " name=\"SimpleSHLVariableChunk\"\n"
168 " parent=\"StateChunk\"\n"
169 " library=\"System\"\n"
170 " pointerfieldtypes=\"both\"\n"
171 " structure=\"concrete\"\n"
172 " systemcomponent=\"true\"\n"
173 " parentsystemcomponent=\"true\"\n"
174 " decoratable=\"false\"\n"
175 " useLocalIncludes=\"false\"\n"
176 " docGroupBase=\"GrpSystemShader\"\n"
177 ">\n"
178 "<!-- <Field\n"
179 "\t name=\"SHLChunk\"\n"
180 "\t type=\"SHLChunk\"\n"
181 "\t cardinality=\"single\"\n"
182 "\t visibility=\"external\"\n"
183 "\t defaultValue=\"NULL\"\n"
184 "\t access=\"public\"\n"
185 " category=\"pointer\"\n"
186 "\t >\n"
187 " </Field> -->\n"
188 " <Field\n"
189 "\t name=\"variables\"\n"
190 "\t type=\"ShaderProgramVariables\"\n"
191 "\t cardinality=\"single\"\n"
192 "\t visibility=\"external\"\n"
193 "\t access=\"public\"\n"
194 " category=\"childpointer\"\n"
195 " childParentType=\"FieldContainer\"\n"
196 " linkParentField=\"Parents\"\n"
197 "\t >\n"
198 "\tfragment program object\n"
199 " </Field>\n"
200 " <Field\n"
201 "\t name=\"variableLocations\"\n"
202 "\t type=\"Int32\"\n"
203 "\t cardinality=\"multi\"\n"
204 "\t visibility=\"internal\"\n"
205 "\t access=\"protected\"\n"
206 "\t >\n"
207 "\tfragment program object\n"
208 " </Field>\n"
209 "</FieldContainer>\n",
213 /*------------------------------ get -----------------------------------*/
215 FieldContainerType &SimpleSHLVariableChunkBase::getType(void)
217 return _type;
220 const FieldContainerType &SimpleSHLVariableChunkBase::getType(void) const
222 return _type;
225 UInt32 SimpleSHLVariableChunkBase::getContainerSize(void) const
227 return sizeof(SimpleSHLVariableChunk);
230 /*------------------------- decorator get ------------------------------*/
233 //! Get the SimpleSHLVariableChunk::_sfVariables field.
234 const SFUnrecChildShaderProgramVariablesPtr *SimpleSHLVariableChunkBase::getSFVariables(void) const
236 return &_sfVariables;
239 SFUnrecChildShaderProgramVariablesPtr *SimpleSHLVariableChunkBase::editSFVariables (void)
241 editSField(VariablesFieldMask);
243 return &_sfVariables;
246 //! Get the value of the SimpleSHLVariableChunk::_sfVariables field.
247 ShaderProgramVariables * SimpleSHLVariableChunkBase::getVariables(void) const
249 return _sfVariables.getValue();
252 //! Set the value of the SimpleSHLVariableChunk::_sfVariables field.
253 void SimpleSHLVariableChunkBase::setVariables(ShaderProgramVariables * const value)
255 editSField(VariablesFieldMask);
257 _sfVariables.setValue(value);
261 MFInt32 *SimpleSHLVariableChunkBase::editMFVariableLocations(void)
263 editMField(VariableLocationsFieldMask, _mfVariableLocations);
265 return &_mfVariableLocations;
268 const MFInt32 *SimpleSHLVariableChunkBase::getMFVariableLocations(void) const
270 return &_mfVariableLocations;
278 /*------------------------------ access -----------------------------------*/
280 SizeT SimpleSHLVariableChunkBase::getBinSize(ConstFieldMaskArg whichField)
282 SizeT returnValue = Inherited::getBinSize(whichField);
284 if(FieldBits::NoField != (VariablesFieldMask & whichField))
286 returnValue += _sfVariables.getBinSize();
288 if(FieldBits::NoField != (VariableLocationsFieldMask & whichField))
290 returnValue += _mfVariableLocations.getBinSize();
293 return returnValue;
296 void SimpleSHLVariableChunkBase::copyToBin(BinaryDataHandler &pMem,
297 ConstFieldMaskArg whichField)
299 Inherited::copyToBin(pMem, whichField);
301 if(FieldBits::NoField != (VariablesFieldMask & whichField))
303 _sfVariables.copyToBin(pMem);
305 if(FieldBits::NoField != (VariableLocationsFieldMask & whichField))
307 _mfVariableLocations.copyToBin(pMem);
311 void SimpleSHLVariableChunkBase::copyFromBin(BinaryDataHandler &pMem,
312 ConstFieldMaskArg whichField)
314 Inherited::copyFromBin(pMem, whichField);
316 if(FieldBits::NoField != (VariablesFieldMask & whichField))
318 editSField(VariablesFieldMask);
319 _sfVariables.copyFromBin(pMem);
321 if(FieldBits::NoField != (VariableLocationsFieldMask & whichField))
323 editMField(VariableLocationsFieldMask, _mfVariableLocations);
324 _mfVariableLocations.copyFromBin(pMem);
328 //! create a new instance of the class
329 SimpleSHLVariableChunkTransitPtr SimpleSHLVariableChunkBase::createLocal(BitVector bFlags)
331 SimpleSHLVariableChunkTransitPtr fc;
333 if(getClassType().getPrototype() != NULL)
335 FieldContainerTransitPtr tmpPtr =
336 getClassType().getPrototype()-> shallowCopyLocal(bFlags);
338 fc = dynamic_pointer_cast<SimpleSHLVariableChunk>(tmpPtr);
341 return fc;
344 //! create a new instance of the class, copy the container flags
345 SimpleSHLVariableChunkTransitPtr SimpleSHLVariableChunkBase::createDependent(BitVector bFlags)
347 SimpleSHLVariableChunkTransitPtr fc;
349 if(getClassType().getPrototype() != NULL)
351 FieldContainerTransitPtr tmpPtr =
352 getClassType().getPrototype()-> shallowCopyDependent(bFlags);
354 fc = dynamic_pointer_cast<SimpleSHLVariableChunk>(tmpPtr);
357 return fc;
360 //! create a new instance of the class
361 SimpleSHLVariableChunkTransitPtr SimpleSHLVariableChunkBase::create(void)
363 SimpleSHLVariableChunkTransitPtr fc;
365 if(getClassType().getPrototype() != NULL)
367 FieldContainerTransitPtr tmpPtr =
368 getClassType().getPrototype()-> shallowCopy();
370 fc = dynamic_pointer_cast<SimpleSHLVariableChunk>(tmpPtr);
373 return fc;
376 SimpleSHLVariableChunk *SimpleSHLVariableChunkBase::createEmptyLocal(BitVector bFlags)
378 SimpleSHLVariableChunk *returnValue;
380 newPtr<SimpleSHLVariableChunk>(returnValue, bFlags);
382 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
384 return returnValue;
387 //! create an empty new instance of the class, do not copy the prototype
388 SimpleSHLVariableChunk *SimpleSHLVariableChunkBase::createEmpty(void)
390 SimpleSHLVariableChunk *returnValue;
392 newPtr<SimpleSHLVariableChunk>(returnValue, Thread::getCurrentLocalFlags());
394 returnValue->_pFieldFlags->_bNamespaceMask &=
395 ~Thread::getCurrentLocalFlags();
397 return returnValue;
401 FieldContainerTransitPtr SimpleSHLVariableChunkBase::shallowCopyLocal(
402 BitVector bFlags) const
404 SimpleSHLVariableChunk *tmpPtr;
406 newPtr(tmpPtr, dynamic_cast<const SimpleSHLVariableChunk *>(this), bFlags);
408 FieldContainerTransitPtr returnValue(tmpPtr);
410 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
412 return returnValue;
415 FieldContainerTransitPtr SimpleSHLVariableChunkBase::shallowCopyDependent(
416 BitVector bFlags) const
418 SimpleSHLVariableChunk *tmpPtr;
420 newPtr(tmpPtr, dynamic_cast<const SimpleSHLVariableChunk *>(this), ~bFlags);
422 FieldContainerTransitPtr returnValue(tmpPtr);
424 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
426 return returnValue;
429 FieldContainerTransitPtr SimpleSHLVariableChunkBase::shallowCopy(void) const
431 SimpleSHLVariableChunk *tmpPtr;
433 newPtr(tmpPtr,
434 dynamic_cast<const SimpleSHLVariableChunk *>(this),
435 Thread::getCurrentLocalFlags());
437 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
439 FieldContainerTransitPtr returnValue(tmpPtr);
441 return returnValue;
447 /*------------------------- constructors ----------------------------------*/
449 SimpleSHLVariableChunkBase::SimpleSHLVariableChunkBase(void) :
450 Inherited(),
451 _sfVariables (this,
452 VariablesFieldId,
453 ShaderProgramVariables::ParentsFieldId),
454 _mfVariableLocations ()
458 SimpleSHLVariableChunkBase::SimpleSHLVariableChunkBase(const SimpleSHLVariableChunkBase &source) :
459 Inherited(source),
460 _sfVariables (this,
461 VariablesFieldId,
462 ShaderProgramVariables::ParentsFieldId),
463 _mfVariableLocations (source._mfVariableLocations )
468 /*-------------------------- destructors ----------------------------------*/
470 SimpleSHLVariableChunkBase::~SimpleSHLVariableChunkBase(void)
474 /*-------------------------------------------------------------------------*/
475 /* Child linking */
477 bool SimpleSHLVariableChunkBase::unlinkChild(
478 FieldContainer * const pChild,
479 UInt16 const childFieldId)
481 if(childFieldId == VariablesFieldId)
483 ShaderProgramVariables * pTypedChild =
484 dynamic_cast<ShaderProgramVariables *>(pChild);
486 if(pTypedChild != NULL)
488 if(_sfVariables.getValue() == pTypedChild)
490 editSField(VariablesFieldMask);
492 _sfVariables.setValue(NULL);
494 return true;
497 SWARNING << "Parent ([" << this
498 << "] id [" << this->getId()
499 << "] type [" << this->getType().getCName()
500 << "] childFieldId [" << childFieldId
501 << "]) - Child ([" << pChild
502 << "] id [" << pChild->getId()
503 << "] type [" << pChild->getType().getCName()
504 << "]): link inconsistent!"
505 << std::endl;
507 return false;
510 return false;
514 return Inherited::unlinkChild(pChild, childFieldId);
517 void SimpleSHLVariableChunkBase::onCreate(const SimpleSHLVariableChunk *source)
519 Inherited::onCreate(source);
521 if(source != NULL)
523 SimpleSHLVariableChunk *pThis = static_cast<SimpleSHLVariableChunk *>(this);
525 pThis->setVariables(source->getVariables());
529 GetFieldHandlePtr SimpleSHLVariableChunkBase::getHandleVariables (void) const
531 SFUnrecChildShaderProgramVariablesPtr::GetHandlePtr returnValue(
532 new SFUnrecChildShaderProgramVariablesPtr::GetHandle(
533 &_sfVariables,
534 this->getType().getFieldDesc(VariablesFieldId),
535 const_cast<SimpleSHLVariableChunkBase *>(this)));
537 return returnValue;
540 EditFieldHandlePtr SimpleSHLVariableChunkBase::editHandleVariables (void)
542 SFUnrecChildShaderProgramVariablesPtr::EditHandlePtr returnValue(
543 new SFUnrecChildShaderProgramVariablesPtr::EditHandle(
544 &_sfVariables,
545 this->getType().getFieldDesc(VariablesFieldId),
546 this));
548 returnValue->setSetMethod(
549 boost::bind(&SimpleSHLVariableChunk::setVariables,
550 static_cast<SimpleSHLVariableChunk *>(this), _1));
552 editSField(VariablesFieldMask);
554 return returnValue;
557 GetFieldHandlePtr SimpleSHLVariableChunkBase::getHandleVariableLocations (void) const
559 MFInt32::GetHandlePtr returnValue(
560 new MFInt32::GetHandle(
561 &_mfVariableLocations,
562 this->getType().getFieldDesc(VariableLocationsFieldId),
563 const_cast<SimpleSHLVariableChunkBase *>(this)));
565 return returnValue;
568 EditFieldHandlePtr SimpleSHLVariableChunkBase::editHandleVariableLocations(void)
570 MFInt32::EditHandlePtr returnValue(
571 new MFInt32::EditHandle(
572 &_mfVariableLocations,
573 this->getType().getFieldDesc(VariableLocationsFieldId),
574 this));
577 editMField(VariableLocationsFieldMask, _mfVariableLocations);
579 return returnValue;
583 #ifdef OSG_MT_CPTR_ASPECT
584 void SimpleSHLVariableChunkBase::execSyncV( FieldContainer &oFrom,
585 ConstFieldMaskArg whichField,
586 AspectOffsetStore &oOffsets,
587 ConstFieldMaskArg syncMode,
588 const UInt32 uiSyncInfo)
590 SimpleSHLVariableChunk *pThis = static_cast<SimpleSHLVariableChunk *>(this);
592 pThis->execSync(static_cast<SimpleSHLVariableChunk *>(&oFrom),
593 whichField,
594 oOffsets,
595 syncMode,
596 uiSyncInfo);
598 #endif
601 #ifdef OSG_MT_CPTR_ASPECT
602 FieldContainer *SimpleSHLVariableChunkBase::createAspectCopy(
603 const FieldContainer *pRefAspect) const
605 SimpleSHLVariableChunk *returnValue;
607 newAspectCopy(returnValue,
608 dynamic_cast<const SimpleSHLVariableChunk *>(pRefAspect),
609 dynamic_cast<const SimpleSHLVariableChunk *>(this));
611 return returnValue;
613 #endif
615 void SimpleSHLVariableChunkBase::resolveLinks(void)
617 Inherited::resolveLinks();
619 static_cast<SimpleSHLVariableChunk *>(this)->setVariables(NULL);
621 #ifdef OSG_MT_CPTR_ASPECT
622 AspectOffsetStore oOffsets;
624 _pAspectStore->fillOffsetArray(oOffsets, this);
625 #endif
627 #ifdef OSG_MT_CPTR_ASPECT
628 _mfVariableLocations.terminateShare(Thread::getCurrentAspect(),
629 oOffsets);
630 #endif
634 OSG_END_NAMESPACE