changed: gcc8 base update
[opensg.git] / Source / Base / FieldContainer / Fields / OSGAttachmentMapFields.cpp
blob3759ea11f5047da0d9cac05e363ebad030dacf7f
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2003 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
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 // Includes
41 //---------------------------------------------------------------------------
43 #include "OSGFieldContainer.h"
44 #include "OSGAttachmentMapSFields.h"
45 #include "OSGAttachment.h"
46 #include "OSGAttachmentContainer.h"
47 #include "OSGContainerPtrFuncs.h"
49 #include "OSGTypeBasePredicates.h"
50 #include "OSGReflexiveContainerTypePredicates.h"
51 #include "OSGMapHelper.h"
53 #include "OSGSField.ins"
56 OSG_BEGIN_NAMESPACE
58 OSG_FIELD_DLLEXPORT_DEF1(SField, AttachmentMap)
61 const FieldType &GetSFieldHandle<SFAttachmentPtrMap>::getType(void) const
63 return SFAttachmentPtrMap::getClassType();
66 const FieldType &EditSFieldHandle<SFAttachmentPtrMap>::getType(void) const
68 return SFAttachmentPtrMap::getClassType();
71 SizeT FieldTraits<AttachmentMap>::getBinSize(const AttachmentMap &aMap)
73 AttachmentMap::const_iterator mapIt = aMap.begin();
74 AttachmentMap::const_iterator mapEnd = aMap.end ();
76 UInt32 numPublicObjects = 0;
78 for(; mapIt != mapEnd; ++mapIt)
80 if(mapIt->second->getInternal() == false)
82 ++numPublicObjects;
86 // number of elements in map + binding and pointer id for each element
87 return sizeof(UInt32) +
88 numPublicObjects * (sizeof(UInt16) + sizeof(UInt32));
91 void FieldTraits<AttachmentMap>::copyToBin( BinaryDataHandler &pMem,
92 const AttachmentMap &aMap )
94 AttachmentMap::const_iterator mapIt = aMap.begin();
95 AttachmentMap::const_iterator mapEnd = aMap.end ();
97 UInt32 numPublicObjects = 0;
98 UInt16 binding;
99 UInt32 fcId;
101 for(; mapIt != mapEnd; ++mapIt)
103 if(mapIt->second->getInternal() == false)
105 ++numPublicObjects;
109 pMem.putValue(numPublicObjects);
111 for(mapIt = aMap.begin(); mapIt != mapEnd; ++mapIt)
113 if(mapIt->second->getInternal() == false)
115 binding = mapIt->first & 0xFFFF;
116 fcId = mapIt->second->getId();
118 pMem.putValue(binding);
119 pMem.putValue(fcId );
124 void FieldTraits<AttachmentMap>::copyFromBin(BinaryDataHandler &pMem,
125 AttachmentMap &aMap )
127 Attachment *attPtr;
128 UInt32 key;
129 UInt16 binding;
130 UInt32 fcId;
131 UInt32 size;
133 pMem.getValue(size);
136 AttachmentMap::const_iterator mapIt = aMap.begin();
137 AttachmentMap::const_iterator mapEnd = aMap.end ();
139 for(; mapIt != mapEnd; ++mapIt)
141 if((*mapIt).second != NULL)
143 Thread::getCurrentChangeList()->addDelayedSubRef<
144 UnrecordedRefCountPolicy>((*mapIt).second);
148 aMap.clear();
151 for(UInt32 i = 0; i < size; ++i)
153 pMem.getValue(binding);
154 pMem.getValue(fcId );
156 attPtr = dynamic_cast<Attachment *>(
157 FieldContainerFactory::the()->getMappedContainer(fcId));
159 if(attPtr != NULL)
161 key = (static_cast<UInt32>(attPtr->getGroupId()) << 16) | binding;
163 UnrecordedRefCountPolicy::addRef(attPtr);
165 aMap.insert(AttachmentMap::value_type(key, attPtr));
170 void EditSFieldHandle<SFAttachmentPtrMap>::add(
171 FieldContainer *rhs,
172 const std::string &szBindings)
174 Attachment *pVal = dynamic_cast<Attachment *>(rhs);
175 UInt32 uiBindings = 0;
177 if(pVal == NULL)
179 MapHelper *pMHelper = dynamic_cast<MapHelper *>(rhs);
181 if(pMHelper != NULL)
183 pVal = dynamic_cast<Attachment *>(pMHelper->getContainer());
185 if(pMHelper->getMFKeys()->empty() == false)
187 const std::string &szKey = pMHelper->getKeys(0);
189 uiBindings = TypeTraits<UInt32>::getFromCString(szKey.c_str());
193 else
195 if(szBindings.empty() == false)
197 uiBindings = TypeTraits<UInt32>::getFromCString(szBindings.c_str());
201 if(rhs != NULL && pVal == NULL)
202 return;
205 // for whatever reason VS2003 does not like == NULL
206 if(_fAddMethod)
208 _fAddMethod(pVal, uiBindings);
212 void EditSFieldHandle<SFAttachmentPtrMap>::replaceByObj(Attachment * const pOld,
213 Attachment * const pNew)
215 if(_fReplaceMethod)
217 _fReplaceMethod(pOld, pNew);
221 void EditSFieldHandle<SFAttachmentPtrMap>::traverse(TraverseCallback oCallback)
223 const SFAttachmentPtrMap *pMap = static_cast<SFAttachmentPtrMap *>(_pField);
225 if(oCallback && pMap != NULL)
227 AttachmentMap::const_iterator mapIt = pMap->getValue().begin();
228 AttachmentMap::const_iterator mapEnd = pMap->getValue().end ();
230 for(; mapIt != mapEnd; ++mapIt)
232 oCallback(mapIt->second);
237 void EditSFieldHandle<SFAttachmentPtrMap>::flatten(MapList &vList)
239 vList.clear();
241 const SFAttachmentPtrMap *pMap = static_cast<SFAttachmentPtrMap *>(_pField);
243 if(pMap != NULL)
245 AttachmentMap::const_iterator mapIt = pMap->getValue().begin();
246 AttachmentMap::const_iterator mapEnd = pMap->getValue().end ();
248 for(; mapIt != mapEnd; ++mapIt)
250 if(mapIt->second->getInternal() == true)
251 continue;
253 std::string szKey;
255 TypeTraits<UInt32>::putToString((mapIt->first & 0x0000FFFF),
256 szKey);
258 ListEntry tmpEntry;
260 tmpEntry.first.push_back(szKey);
261 tmpEntry.second = mapIt->second;
263 vList.push_back(tmpEntry);
268 void EditSFieldHandle<SFAttachmentPtrMap>::flatten(ContainerList &vList)
270 vList.clear();
272 const SFAttachmentPtrMap *pMap = static_cast<SFAttachmentPtrMap *>(_pField);
274 if(pMap != NULL)
276 AttachmentMap::const_iterator mapIt = pMap->getValue().begin();
277 AttachmentMap::const_iterator mapEnd = pMap->getValue().end ();
279 for(; mapIt != mapEnd; ++mapIt)
281 if(mapIt->second->getInternal() == true)
282 continue;
284 vList.push_back(mapIt->second);
289 bool EditSFieldHandle<SFAttachmentPtrMap>::loadFromBin(
290 BinaryDataHandler *pMem,
291 UInt32 uiNumElements,
292 bool hasBindingInfo,
293 std::vector<UInt16> &vBindings,
294 std::vector<UInt32> &vIds )
296 UInt32 ptrId;
297 UInt16 binding;
299 for(UInt32 i = 0; i < uiNumElements; ++i)
301 pMem->getValue(binding);
302 pMem->getValue(ptrId );
304 FDEBUG(("EditSFieldHandle<SFAttachmentPtrMap>::loadFromBin: "
305 "attachment [%u], binding [%u], id [%u].\n",
306 i, binding, ptrId));
308 vBindings.push_back(binding);
309 vIds .push_back(ptrId );
312 return false;
316 void EditSFieldHandle<SFAttachmentPtrMap>::fillFrom(
317 const std::vector<UInt16> &vBindings,
318 const std::vector<UInt32> &vIds,
319 const std::map<UInt32, UInt32> &vIdMap )
323 void EditSFieldHandle<SFAttachmentPtrMap>::cloneValues(
324 GetFieldHandlePtr pSrc,
325 const TypePtrVector &shareTypes,
326 const TypePtrVector &ignoreTypes,
327 const TypeIdVector &shareGroupIds,
328 const TypeIdVector &ignoreGroupIds) const
330 SFAttachmentPtrMap::GetHandlePtr pGetHandle =
331 boost::dynamic_pointer_cast<
332 SFAttachmentPtrMap::GetHandle>(pSrc);
334 if(pGetHandle == NULL || pGetHandle->isValid() == false)
335 return;
337 const SFAttachmentPtrMap &pAttMap = **pGetHandle;
339 AttachmentMap::const_iterator mapIt = pAttMap.getValue().begin();
340 AttachmentMap::const_iterator mapEnd = pAttMap.getValue().end();
342 for(; mapIt != mapEnd; ++mapIt)
344 AttachmentUnrecPtr att = mapIt->second;
345 UInt16 uiBinding = UInt16(mapIt->first &
346 0x0000FFFF );
348 if(att != NULL)
350 const FieldContainerType &attType = att->getType();
352 // test if att type should NOT be ignored
353 if(!TypePredicates::typeInGroupIds (ignoreGroupIds.begin(),
354 ignoreGroupIds.end(),
355 attType ) &&
356 !TypePredicates::typeDerivedFrom(ignoreTypes.begin(),
357 ignoreTypes.end(),
358 attType ) )
360 // test if att should cloned
361 if(!TypePredicates::typeInGroupIds (shareGroupIds.begin(),
362 shareGroupIds.end(),
363 attType ) &&
364 !TypePredicates::typeDerivedFrom(shareTypes.begin(),
365 shareTypes.end(),
366 attType ) )
368 att = dynamic_pointer_cast<Attachment>(
369 OSG::deepClone(att, shareTypes, ignoreTypes,
370 shareGroupIds, ignoreGroupIds));
375 if(_fAddMethod)
377 _fAddMethod(att, uiBinding);
383 void GetSFieldHandle<SFAttachmentPtrMap>::traverse(TraverseCallback oCallback)
385 SFAttachmentPtrMap const *pMap =
386 static_cast<SFAttachmentPtrMap const *>(_pField);
388 if(oCallback && pMap != NULL)
390 AttachmentMap::const_iterator mapIt = pMap->getValue().begin();
391 AttachmentMap::const_iterator mapEnd = pMap->getValue().end ();
393 for(; mapIt != mapEnd; ++mapIt)
395 oCallback(mapIt->second);
400 void GetSFieldHandle<SFAttachmentPtrMap>::flatten(MapList &vList)
402 vList.clear();
404 SFAttachmentPtrMap const *pMap =
405 static_cast<SFAttachmentPtrMap const *>(_pField);
407 if(pMap != NULL)
409 AttachmentMap::const_iterator mapIt = pMap->getValue().begin();
410 AttachmentMap::const_iterator mapEnd = pMap->getValue().end ();
412 for(; mapIt != mapEnd; ++mapIt)
414 if(mapIt->second->getInternal() == true)
415 continue;
417 std::string szKey;
419 TypeTraits<UInt32>::putToString((mapIt->first & 0x0000FFFF),
420 szKey);
422 ListEntry tmpEntry;
424 tmpEntry.first.push_back(szKey);
425 tmpEntry.second = mapIt->second;
427 vList.push_back(tmpEntry);
432 void GetSFieldHandle<SFAttachmentPtrMap>::flatten(ContainerList &vList)
434 vList.clear();
436 SFAttachmentPtrMap const *pMap =
437 static_cast<SFAttachmentPtrMap const *>(_pField);
439 if(pMap != NULL)
441 AttachmentMap::const_iterator mapIt = pMap->getValue().begin();
442 AttachmentMap::const_iterator mapEnd = pMap->getValue().end ();
444 for(; mapIt != mapEnd; ++mapIt)
446 if(mapIt->second->getInternal() == true)
447 continue;
449 vList.push_back(mapIt->second);
454 #if !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
456 DataType FieldTraits<AttachmentMap>::_type(
457 "AttachmentMap",
458 "FieldContainerPtrMap");
460 OSG_FIELDTRAITS_GETTYPE(AttachmentMap)
462 #endif // !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
464 OSG_END_NAMESPACE