1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
41 template <class Desc> inline
42 void MapCacheHandlerMixin<Desc>::classDescInserter(TypeObject &oType)
44 Inherited::classDescInserter(oType);
46 FieldDescriptionBase *pDesc;
48 typedef typename MapCacheField::Description SFDesc;
51 MapCacheField::getClassType(),
54 OSG_RC_FIELD_DESC(Self::MapCache),
56 Field::SFDefaultFlags,
57 static_cast<FieldEditMethodSig>(&Self::editHandleMapCache),
58 static_cast<FieldGetMethodSig >(&Self::getHandleMapCache ));
60 oType.addInitialDesc(pDesc);
63 template <class Desc> inline
64 void MapCacheHandlerMixin<Desc>::changed(ConstFieldMaskArg whichField,
68 Inherited::changed(whichField, origin, details);
71 /*-------------------------------------------------------------------------*/
74 template <class Desc> inline
75 typename MapCacheHandlerMixin<Desc>::FinalizedElement *
76 MapCacheHandlerMixin<Desc>::finalize(MapCacheKey oKey)
78 MapCacheFieldConstIt fcI = _fMapCache.getValue().find(oKey);
80 if(fcI == _fMapCache.getValue().end())
82 return Desc::getFallback(this); //_sfFallbackMaterial.getValue();
90 template <class Desc> inline
91 void MapCacheHandlerMixin<Desc>::addElement (
92 MapCacheElement const pElement,
98 if(key == MapKeyPool::the()->getDefault())
100 Desc::setFallback(this, pElement); //setFallbackMaterial(pMaterial);
105 if(this->isMTLocal())
107 pElement->addReferenceRecorded();
111 pElement->addReferenceUnrecorded();
115 pAttachment->linkParent(this,
117 Attachment::ParentsFieldId);
120 Self::editSField(MapCacheFieldMask);
122 MapCacheFieldIt fcI = _fMapCache.getValue().find(key);
124 if(fcI != _fMapCache.getValue().end())
127 (*fcI).second->unlinkParent(this,
128 Attachment::ParentsFieldId);
131 if(this->isMTLocal())
133 (*fcI).second->subReferenceRecorded();
137 (*fcI).second->subReferenceUnrecorded();
140 (*fcI).second = pElement;
144 _fMapCache.getValue()[key] = pElement;
148 template <class Desc> inline
149 void MapCacheHandlerMixin<Desc>::subElement(MapCacheKey key)
151 if(key == MapKeyPool::the()->getDefault())
153 Desc::setFallback(this, NULL); //setFallbackMaterial(NULL);
157 Self::editSField(MapCacheFieldMask);
161 fcI = _fMapCache.getValue().find(key);
163 if(fcI != _fMapCache.getValue().end())
166 (*fcI).second->unlinkParent(this,
167 Attachment::ParentsFieldId);
170 if(this->isMTLocal())
172 (*fcI).second->subReferenceRecorded();
176 (*fcI).second->subReferenceUnrecorded();
179 _fMapCache.getValue().erase(fcI);
183 template <class Desc> inline
184 void MapCacheHandlerMixin<Desc>::clearElements (void)
186 while(_fMapCache.getValue().size() != 0)
188 subElement(_fMapCache.getValue().begin()->first);
193 template <class Desc> inline
194 typename MapCacheHandlerMixin<Desc>::MapCacheElement
195 MapCacheHandlerMixin<Desc>::findElement(MapCacheKey key) const
197 MapCacheFieldConstIt fcI = _fMapCache.getValue().find(key);
199 if(fcI == _fMapCache.getValue().end())
205 return (*fcI).second;
209 template <class Desc> inline
210 const typename MapCacheHandlerMixin<Desc>::MapCacheField *
211 MapCacheHandlerMixin<Desc>::getMapCacheField(void) const
216 /*-------------------------------------------------------------------------*/
219 template <class Desc> inline
220 SizeT MapCacheHandlerMixin<Desc>::getBinSize(ConstFieldMaskArg whichField)
222 SizeT returnValue = Inherited::getBinSize(whichField);
224 if(FieldBits::NoField != (MapCacheFieldMask & whichField))
226 returnValue += _fMapCache.getBinSize();
232 template <class Desc> inline
233 void MapCacheHandlerMixin<Desc>::copyToBin(BinaryDataHandler &pMem,
234 ConstFieldMaskArg whichField)
236 Inherited::copyToBin(pMem, whichField);
238 if(FieldBits::NoField != (MapCacheFieldMask & whichField))
240 _fMapCache.copyToBin(pMem);
244 template <class Desc> inline
245 void MapCacheHandlerMixin<Desc>::copyFromBin(BinaryDataHandler &pMem,
246 ConstFieldMaskArg whichField)
248 Inherited::copyFromBin(pMem, whichField);
250 if(FieldBits::NoField != (MapCacheFieldMask & whichField))
252 _fMapCache.copyFromBin(pMem);
256 /*-------------------------------------------------------------------------*/
260 /*-------------------------------------------------------------------------*/
263 template <class Desc> inline
264 MapCacheHandlerMixin<Desc>::MapCacheHandlerMixin(void) :
270 template <class Desc> inline
271 MapCacheHandlerMixin<Desc>::MapCacheHandlerMixin(
272 const MapCacheHandlerMixin &source) :
279 template <class Desc> inline
280 MapCacheHandlerMixin<Desc>::~MapCacheHandlerMixin(void)
284 template <class Desc> inline
285 void MapCacheHandlerMixin<Desc>::dump( UInt32 uiIndent,
286 const BitVector bvFlags ) const
290 template <class Desc> inline
291 EditFieldHandlePtr MapCacheHandlerMixin<Desc>::editHandleMapCache(void)
293 typename MapCacheField::EditHandlePtr returnValue(
294 new typename MapCacheField::EditHandle(
296 this->getType().getFieldDesc(MapCacheFieldId),
299 returnValue->setAddMethod(
300 boost::bind(&Self::addElement,
301 static_cast<Self *>(this), _1, _2));
303 this->editSField(MapCacheFieldMask);
308 template <class Desc> inline
309 GetFieldHandlePtr MapCacheHandlerMixin<Desc>::getHandleMapCache(void) const
311 typename MapCacheField::GetHandlePtr returnValue(
312 new typename MapCacheField::GetHandle(
314 this->getType().getFieldDesc(MapCacheFieldId),
315 const_cast<Self *>(this)));
320 /*-------------------------------------------------------------------------*/
324 #ifdef OSG_MT_CPTR_ASPECT
325 template <class Desc> inline
326 void MapCacheHandlerMixin<Desc>::execSync(
328 ConstFieldMaskArg whichField,
329 AspectOffsetStore &oOffsets,
330 ConstFieldMaskArg syncMode ,
331 const UInt32 uiSyncInfo)
333 Inherited::execSync(pFrom, whichField, oOffsets, syncMode, uiSyncInfo);
335 if(FieldBits::NoField != (MapCacheFieldMask & whichField))
337 // _sfAttachments.syncWith(pFrom->_sfAttachments);
343 MapCacheFieldIt fcI = pFrom->_fMapCache.getValue().begin();
344 MapCacheFieldIt fcE = pFrom->_fMapCache.getValue().end ();
348 MapCacheElement pMat = Aspect::convertToCurrent((*fcI).second);
352 tmpMap[(*fcI).first] = pMat;
354 pMat->addReferenceUnrecorded();
360 fcI = _fMapCache.getValue().begin();
361 fcE = _fMapCache.getValue().end ();
365 if(this->isMTLocal())
367 (*fcI).second->subReferenceRecorded();
371 (*fcI).second->subReferenceUnrecorded();
377 _fMapCache.setValue(tmpMap);
382 template <class Desc> inline
383 void MapCacheHandlerMixin<Desc>::onCreateAspect(
384 const FinalContainer *createAspect,
385 const FinalContainer *source )
387 Inherited::onCreateAspect(createAspect, source);
390 if(GlobalSystemState == OSG::Running)
395 template <class Desc> inline
396 void MapCacheHandlerMixin<Desc>::onCreate(const FinalContainer *source)
398 Inherited::onCreate(source);
401 if(GlobalSystemState == OSG::Running)
406 template <class Desc> inline
407 void MapCacheHandlerMixin<Desc>::onDestroy(UInt32 uiContainerId)
409 Inherited::onDestroy(uiContainerId);
412 if(GlobalSystemState == OSG::Running)
417 template <class Desc> inline
418 void MapCacheHandlerMixin<Desc>::onDestroyAspect(UInt32 uiContainerId,
421 Inherited::onDestroy(uiContainerId);
424 if(GlobalSystemState == OSG::Running)
429 template <class Desc> inline
430 void MapCacheHandlerMixin<Desc>::resolveLinks(void)
432 Inherited::resolveLinks();
434 MapCacheFieldIt fcI = _fMapCache.getValue().begin();
435 MapCacheFieldIt fcE = _fMapCache.getValue().end ();
440 (*fcI).second->unlinkParent(this,
441 Material::ParentsFieldId);
444 if(this->isMTLocal())
446 (*fcI).second->subReferenceRecorded();
450 (*fcI).second->subReferenceUnrecorded();
456 _fMapCache.getValue().clear();
459 /*-------------------------------------------------------------------------*/
462 /*-------------------------------------------------------------------------*/