changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / FieldContainer / Misc / OSGFieldContainerUtils.cpp
blobdaddb11784365aaa271ebf05990afd7eb850f3e8
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2008 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 #include "OSGFieldContainerUtils.h"
40 #include "OSGFieldContainerSFields.h"
41 #include "OSGFieldContainerMFields.h"
42 #include "OSGAttachment.h"
43 #include "OSGAttachmentMapSFields.h"
44 #include "OSGNameAttachment.h"
45 #include "OSGNode.h"
47 #include <boost/bind.hpp>
48 #include <boost/format.hpp>
50 #include <ostream>
51 #include <set>
53 OSG_BEGIN_NAMESPACE
55 namespace
57 // anonymous namespace for implementation details of the container
58 // function.
60 typedef std::set<const FieldContainer *> FCSet;
62 // forward declarations
63 bool comparePointerFields(
64 GetFieldHandlePtr lhsField,
65 GetFieldHandlePtr rhsField,
66 FCSet &lhsVisitedSet,
67 FCSet &rhsVisitedSet,
68 bool ignoreAttachments,
69 bool compareIdentity );
71 /*! Implementation of \c compareContainerEqual. The two \c FCSet parameters
72 keep track of visited fields in each hierarchy to avoid looping.
74 bool compareContainerEqualImpl(
75 const FieldContainer *lhs,
76 const FieldContainer *rhs,
77 FCSet &lhsVisitedSet,
78 FCSet &rhsVisitedSet,
79 bool ignoreAttachments,
80 bool compareIdentity )
82 // compare pointers
83 if(lhs == rhs)
84 return true;
86 if(lhs == NULL || rhs == NULL)
87 return false;
89 // different types ?
90 if(lhs->getType() != rhs->getType())
91 return false;
93 UInt32 lhsFCount = lhs->getType().getNumFieldDescs();
94 UInt32 rhsFCount = rhs->getType().getNumFieldDescs();
96 // different number of (dynamic) fields ?
97 if(lhsFCount != rhsFCount)
98 return false;
100 lhsVisitedSet.insert(lhs);
101 rhsVisitedSet.insert(rhs);
103 bool returnValue = true;
105 for(UInt32 i = 1; i <= lhsFCount && returnValue == true; ++i)
107 GetFieldHandlePtr lhsField = lhs->getField(i);
108 GetFieldHandlePtr rhsField = rhs->getField(i);
110 // valid handles ?
111 if(lhsField == NULL || lhsField->isValid() == false ||
112 rhsField == NULL || rhsField->isValid() == false )
113 continue;
115 if(lhsField->getType() != rhsField->getType())
117 returnValue = false;
118 continue;
121 // skip internal and parent fields
122 if(lhsField->isInternal() == true ||
123 lhsField->getType ().getClass() == FieldType::ParentPtrField )
124 continue;
126 SFAttachmentPtrMap::GetHandlePtr lhsAMHandle =
127 boost::dynamic_pointer_cast<SFAttachmentPtrMap::GetHandle>(
128 lhsField);
130 if(lhsAMHandle != NULL &&
131 lhsAMHandle->isValid() == true &&
132 ignoreAttachments == true )
134 continue;
137 if(compareIdentity == true)
139 if(lhsField->equal(rhsField) == false)
140 returnValue = false;
142 else
144 if(lhsField->isPointerField() == true)
146 returnValue = comparePointerFields(
147 lhsField, rhsField,
148 lhsVisitedSet, rhsVisitedSet,
149 ignoreAttachments, compareIdentity);
151 else
153 if(lhsField->equal(rhsField) == false)
154 returnValue = false;
159 return returnValue;
162 /*! Compares two PointerFields \a lhsField and \a rhsField by recursively
163 comparing the pointed-to containers.
164 This function is only used in \c compareContainer below.
166 bool comparePointerFields(
167 GetFieldHandlePtr lhsField,
168 GetFieldHandlePtr rhsField,
169 FCSet &lhsVisitedSet,
170 FCSet &rhsVisitedSet,
171 bool ignoreAttachments,
172 bool compareIdentity )
174 bool returnValue = true;
176 if(lhsField->getCardinality() == FieldType::SingleField)
178 FieldContainerPtrSFieldBase::GetHandlePtr lhsSFHandle =
179 boost::dynamic_pointer_cast<
180 FieldContainerPtrSFieldBase::GetHandle>(lhsField);
181 FieldContainerPtrSFieldBase::GetHandlePtr rhsSFHandle =
182 boost::dynamic_pointer_cast<
183 FieldContainerPtrSFieldBase::GetHandle>(rhsField);
185 if(lhsSFHandle != NULL && lhsSFHandle->isValid() &&
186 rhsSFHandle != NULL && rhsSFHandle->isValid() )
188 if(lhsVisitedSet.count(lhsSFHandle->get()) == 0 ||
189 rhsVisitedSet.count(rhsSFHandle->get()) == 0 )
191 returnValue = compareContainerEqualImpl(
192 lhsSFHandle->get(), rhsSFHandle->get(),
193 lhsVisitedSet, rhsVisitedSet,
194 ignoreAttachments, compareIdentity );
197 else
199 SFAttachmentPtrMap::GetHandlePtr lhsAMHandle =
200 boost::dynamic_pointer_cast<SFAttachmentPtrMap::GetHandle>(
201 lhsField);
202 SFAttachmentPtrMap::GetHandlePtr rhsAMHandle =
203 boost::dynamic_pointer_cast<SFAttachmentPtrMap::GetHandle>(
204 rhsField);
206 if(lhsAMHandle != NULL && lhsAMHandle->isValid() &&
207 rhsAMHandle != NULL && rhsAMHandle->isValid() )
209 const AttachmentMap &lhsAM = (*lhsAMHandle)->getValue();
210 const AttachmentMap &rhsAM = (*rhsAMHandle)->getValue();
212 // skip attachments, if the option is set
213 if(ignoreAttachments)
215 returnValue = true;
217 else if(lhsAM.size() != rhsAM.size())
219 returnValue = false;
221 else
223 AttachmentMap::const_iterator lhsAMIt = lhsAM.begin();
224 AttachmentMap::const_iterator lhsAMEnd = lhsAM.end ();
226 AttachmentMap::const_iterator rhsAMIt = rhsAM.begin();
228 for(; lhsAMIt != lhsAMEnd && returnValue == true;
229 ++lhsAMIt, ++rhsAMIt)
231 if(lhsVisitedSet.count(lhsAMIt->second) == 0 ||
232 rhsVisitedSet.count(rhsAMIt->second) == 0 )
234 returnValue = compareContainerEqualImpl(
235 lhsAMIt->second, rhsAMIt->second,
236 lhsVisitedSet, rhsVisitedSet,
237 ignoreAttachments, compareIdentity );
244 else
246 FieldContainerPtrMFieldBase::GetHandlePtr lhsMFHandle =
247 boost::dynamic_pointer_cast<
248 FieldContainerPtrMFieldBase::GetHandle>(lhsField);
249 FieldContainerPtrMFieldBase::GetHandlePtr rhsMFHandle =
250 boost::dynamic_pointer_cast<
251 FieldContainerPtrMFieldBase::GetHandle>(rhsField);
253 if(lhsMFHandle != NULL && lhsMFHandle->isValid() &&
254 rhsMFHandle != NULL && rhsMFHandle->isValid() )
256 if(lhsMFHandle->size() != rhsMFHandle->size())
258 returnValue = false;
260 else
262 for(UInt32 i = 0; i < lhsMFHandle->size() &&
263 returnValue == true; ++i)
265 if(lhsVisitedSet.count(lhsMFHandle->get(i)) == 0 ||
266 rhsVisitedSet.count(rhsMFHandle->get(i)) == 0 )
268 returnValue = compareContainerEqualImpl(
269 lhsMFHandle->get(i), rhsMFHandle->get(i),
270 lhsVisitedSet, rhsVisitedSet,
271 ignoreAttachments, compareIdentity );
278 return returnValue;
281 /*! \nohierarchy
284 struct FieldPathEntry
286 std::string szName;
287 Int32 iIndex;
290 void splitFieldPath( std::vector<FieldPathEntry> &vSplitPath,
291 const Char8 *szFieldPath)
293 std::string tmpName(szFieldPath);
295 std::string::size_type sStart = 0;
296 std::string::size_type sEnd = 0;
297 std::string::size_type sLength = 0;
298 std::string::size_type sLastChar = 0;
299 FieldPathEntry tmpEntry;
301 std::string szIdx;
305 sEnd = tmpName.find("/", sStart);
307 if(sEnd != std::string::npos)
309 sLength = sEnd - sStart;
311 else
313 sLength = tmpName.length() - sStart;
316 sLastChar = sStart + sLength - 1;
318 vSplitPath.push_back(tmpEntry);
320 vSplitPath.back().iIndex = -1;
322 if(tmpName[sLastChar] == ')')
324 std::string::size_type sIdxStart =
325 tmpName.rfind('(', sLastChar); //, sLength);
327 if(sIdxStart == std::string::npos)
329 vSplitPath.clear();
331 return;
334 tmpName[sIdxStart] = '$';
335 tmpName[sLastChar] = '$';
337 sLength -= sLastChar - sIdxStart + 1;
339 ++sIdxStart;
341 szIdx.assign(tmpName,
342 sIdxStart,
343 sLastChar - sIdxStart);
345 vSplitPath.back().iIndex =
346 TypeTraits<UInt32>::getFromCString(szIdx.c_str());
349 vSplitPath.back().szName.assign(tmpName, sStart, sLength);
351 sStart = sEnd + 1;
353 while(sEnd != std::string::npos);
356 FieldContainer *resolveFieldPath(std::vector<FieldPathEntry> &vSplitPath,
357 FieldContainer *pRoot )
359 if(pRoot == NULL)
360 return NULL;
362 FieldContainer *returnValue = pRoot;
364 OSG::GetFieldHandlePtr fHandle;
366 for(UInt32 i = 1; i < vSplitPath.size(); ++i)
368 fHandle = returnValue->getField(vSplitPath[i].szName.c_str());
370 if(fHandle == NULL || fHandle->isValid() == false)
372 FWARNING(("Unknown field '%s'\n",
373 vSplitPath[i].szName.c_str()));
375 returnValue = NULL;
377 break;
380 OSG::FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr =
381 boost::dynamic_pointer_cast<
382 OSG::FieldContainerPtrSFieldBase::GetHandle>(fHandle);
384 OSG::FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr =
385 boost::dynamic_pointer_cast<
386 OSG::FieldContainerPtrMFieldBase::GetHandle>(fHandle);
388 if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
390 returnValue = (*sfFCPtr)->getValue();
392 else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
394 UInt32 uiIndex =
395 vSplitPath[i].iIndex == -1 ? 0 : vSplitPath[i].iIndex;
397 if(uiIndex >= mfFCPtr->size())
399 FWARNING(("Unknown index %d to large for field '%s'\n",
400 uiIndex,
401 vSplitPath[i].szName.c_str()));
403 returnValue = NULL;
405 break;
408 returnValue = (**mfFCPtr)[uiIndex];
412 return returnValue;
415 FieldContainer *resolveFieldPathImpl(const Char8 *szNodeName,
416 ContainerResolver oResolver )
418 std::vector<FieldPathEntry> vSplitPath;
420 splitFieldPath(vSplitPath, szNodeName);
422 if(vSplitPath.size() == 0)
423 return NULL;
425 FieldContainer *returnValue = oResolver(vSplitPath[0].szName.c_str());
427 returnValue = resolveFieldPath(vSplitPath, returnValue);
429 return returnValue;
434 struct ContainerVisitRecord
436 typedef std::vector<UInt32>::iterator VisitedIt;
438 std::vector<UInt32> vVisitedIds;
440 bool visit(UInt32 uiContainerId);
443 bool ContainerVisitRecord::visit(UInt32 uiContainerId)
445 VisitedIt vIt = std::lower_bound(vVisitedIds.begin(),
446 vVisitedIds.end (),
447 uiContainerId );
449 if(vIt != vVisitedIds.end())
451 if(*vIt == uiContainerId)
452 return false;
454 vVisitedIds.insert(vIt, uiContainerId);
456 else
458 vVisitedIds.push_back(uiContainerId);
461 return true;
464 FieldContainer *findNamedComponentImpl( ContainerVisitRecord &oVisited,
465 FieldContainer *pCnt,
466 const Char8 *szName )
468 if(pCnt == NULL)
469 return NULL;
471 const Char8 *szTmpName = NULL;
473 const AttachmentContainer *pAC =
474 dynamic_cast<const AttachmentContainer *>(pCnt);
476 #if 0
477 fprintf(stderr, "findNamedComponent::visit %p type %s\n",
478 pCnt,
479 pCnt->getType().getCName());
480 #endif
482 szTmpName = OSG::getName(pAC);
484 if(szTmpName != NULL && osgStringCmp(szTmpName, szName) == 0)
486 return pCnt;
489 if(oVisited.visit(pCnt->getId()) == false)
491 return NULL;
494 const Node *pNode = dynamic_cast<const Node *>(pCnt);
496 if(pNode != NULL)
498 if(0x0000 == (pNode->getTravMask() &
499 TraversalMasks::FindNamedComponentTraversal))
501 return NULL;
505 BitVector bvExcludedFields = TypeTraits<BitVector>::BitsSet;
507 const ControlFindNamedElemInterface *pCFNInterface =
508 dynamic_cast<ControlFindNamedElemInterface *>(pCnt);
510 if(pCFNInterface != NULL)
512 bvExcludedFields = pCFNInterface->excludeFields();
515 const FieldContainerType &fcType = pCnt->getType();
516 UInt32 fCount = fcType.getNumFieldDescs();
518 for(UInt32 i = 1; i <= fCount; ++i)
520 const FieldDescriptionBase *fDesc = fcType.getFieldDesc(i);
522 if(fDesc->getFieldType().getClass() == FieldType::ParentPtrField)
523 continue;
525 if(0x0000 == (bvExcludedFields & fDesc->getFieldMask()))
526 continue;
528 GetFieldHandlePtr srcField = pCnt->getField(i);
530 FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr =
531 boost::dynamic_pointer_cast<
532 FieldContainerPtrSFieldBase::GetHandle>(srcField);
534 FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr =
535 boost::dynamic_pointer_cast<
536 FieldContainerPtrMFieldBase::GetHandle>(srcField);
538 if( sfFCPtr != NULL &&
539 sfFCPtr->isValid() == true &&
540 (*sfFCPtr)->getValue() != NULL )
542 FieldContainer *rc = findNamedComponentImpl(oVisited,
543 (*sfFCPtr)->getValue(),
544 szName );
545 if(rc != NULL)
546 return rc;
548 else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
550 SizeT mfSize = (*mfFCPtr)->size();
552 for(SizeT i = 0; i < mfSize; i++)
554 if((**mfFCPtr)[i] != NULL)
556 FieldContainer *rc = findNamedComponentImpl(oVisited,
557 (**mfFCPtr)[i],
558 szName);
560 if(rc != NULL)
561 return rc;
567 return NULL;
570 FieldContainer *findNamedComponentImpl( FieldContainer *pCnt,
571 const Char8 *szName)
573 ContainerVisitRecord oVisited;
575 return findNamedComponentImpl(oVisited, pCnt, szName);
578 } // namespace
580 /*! Compares two FieldContainer \a lhs and \a rhs for equivalence. The meaning
581 of this comparison can be tweaked with the additional arguments.
582 If \a ignoreAttachments is \c true, Attachments are excluded from the
583 comparison.
584 If \a compareIdentity is \c true, pointers are compared by
585 address otherwise the pointed-to objects are compared for equivalence.
587 bool compareContainerEqual(
588 const FieldContainer *lhs,
589 const FieldContainer *rhs,
590 bool ignoreAttachments,
591 bool compareIdentity )
593 FCSet lhsVisitedSet;
594 FCSet rhsVisitedSet;
596 return compareContainerEqualImpl(
597 lhs, rhs, lhsVisitedSet, rhsVisitedSet,
598 ignoreAttachments, compareIdentity );
601 //---------------------------------------------------------------------------
602 // MemoryConsumption
603 //---------------------------------------------------------------------------
605 void MemoryConsumption::scan(void)
607 FieldContainerFactory::the()->lockStore();
609 FieldContainerFactoryBase::ContainerStoreConstIt sIt =
610 FieldContainerFactory::the()->beginStore();
611 FieldContainerFactoryBase::ContainerStoreConstIt sEnd =
612 FieldContainerFactory::the()->endStore();
614 for(; sIt != sEnd; ++sIt)
616 FieldContainer *pFC = (*sIt).second->getPtr();
618 if(pFC == NULL)
619 continue;
621 TypeMemMapIt tmIt = _memMap.find(pFC->getType().getId());
622 SizeT binSize = pFC->getBinSize(TypeTraits<BitVector>::BitsSet);
624 if(tmIt != _memMap.end())
626 tmIt->second.first += binSize;
627 tmIt->second.second += 1;
629 else
631 _memMap[pFC->getType().getId()] = MemCountPair(binSize, 1);
635 FieldContainerFactory::the()->unlockStore();
639 void MemoryConsumption::print(std::ostream &os, bool ignoreProto) const
641 TypeMemMapConstIt tmIt = _memMap.begin();
642 TypeMemMapConstIt tmEnd = _memMap.end ();
644 SizeT totalMem = 0;
645 UInt32 totalCount = 0;
646 boost::format formatter("%|1$-25| [%|2$8|] Byte [%|3$8.0f|] kByte [%|4$4|]\n");
648 for(; tmIt != tmEnd; ++tmIt)
650 FieldContainerType *fcType =
651 FieldContainerFactory::the()->findType(tmIt->first);
653 if(fcType == NULL)
654 continue;
656 if(ignoreProto && tmIt->second.second == 1)
657 continue;
659 os << formatter % fcType->getCName()
660 % tmIt->second.first
661 % (tmIt->second.first / 1024.f)
662 % tmIt->second.second;
664 totalMem += tmIt->second.first;
665 totalCount += tmIt->second.second;
668 os << "--------------------------------------------\n";
669 os << formatter % "Total"
670 % totalMem
671 % (totalMem / 1024.f)
672 % totalCount;
675 MemoryConsumption::TypeMemMapConstIt MemoryConsumption::beginMap(void) const
677 return _memMap.begin();
680 MemoryConsumption::TypeMemMapConstIt MemoryConsumption::endMap(void) const
682 return _memMap.end();
685 ControlFindNamedElemInterface::ControlFindNamedElemInterface(void)
689 ControlFindNamedElemInterface::~ControlFindNamedElemInterface(void)
694 FieldContainer *resolveFieldPath(const Char8 *szNodeName,
695 ContainerResolver oResolver )
697 return resolveFieldPathImpl(szNodeName, oResolver);
700 FieldContainer *findNamedComponent( FieldContainer *pCnt,
701 const Char8 *szName)
703 return findNamedComponentImpl(pCnt, szName);
708 FieldContainer *getFieldContainer(const std::string &szTypeName,
709 const std::string &szName)
711 return getFieldContainer(
712 FieldContainerFactory::the()->findType(szTypeName.c_str()), szName);
715 FieldContainer *getFieldContainer(const FieldContainerType *pType,
716 const std::string &szName)
718 if(pType == NULL)
720 SWARNING << "getFieldContainer(): The Field type is not defined."
721 << std::endl;
723 return NULL;
726 const FieldContainerFactoryBase::ContainerStore &oFCStore(
727 FieldContainerFactory::the()->getFieldContainerStore());
729 FieldContainerFactoryBase::ContainerStore::const_iterator fcStoreIt =
730 oFCStore.begin();
732 FieldContainerFactoryBase::ContainerPtr pCont = NULL;
734 for(; fcStoreIt != oFCStore.end() ; ++fcStoreIt)
736 #ifdef OSG_MT_CPTR_ASPECT
737 pCont = (*fcStoreIt).second->getPtr();
738 #else
739 pCont = *fcStoreIt .second;
740 #endif
742 if(pCont != NULL && pCont->getType() == (*pType))
744 const Char8 *szCntName =
745 getName(dynamic_cast<AttachmentContainer *>(pCont));
747 if(szCntName != NULL && szName.compare(szCntName) == 0)
749 return pCont;
754 return NULL;
758 FieldContainer *getFieldContainer(const std::string &szName)
760 const FieldContainerFactoryBase::ContainerStore &oFCStore =
761 FieldContainerFactory::the()->getFieldContainerStore();
763 FieldContainerFactoryBase::ContainerStore::const_iterator fcStoreIt =
764 oFCStore.begin();
766 FieldContainerFactoryBase::ContainerPtr pCont = NULL;
768 for(; fcStoreIt != oFCStore.end() ; ++fcStoreIt)
770 if((*fcStoreIt).second == NULL)
772 continue;
775 #ifdef OSG_MT_CPTR_ASPECT
776 pCont = (*fcStoreIt).second->getPtr();
777 #else
778 pCont = *fcStoreIt .second;
779 #endif
780 const Char8 *szCntName =
781 getName(dynamic_cast<AttachmentContainer *>(pCont));
783 if(szCntName != NULL && szName.compare(szCntName) == 0)
785 return pCont;
789 return NULL;
793 bool isFieldContentDerivedFrom(const FieldType &oFieldType,
794 const FieldContainerType *pFCType)
796 if(oFieldType.isPtrField())
798 std::string szFieldPtrTypeName(oFieldType.getContentType().getName());
800 switch(oFieldType.getClass())
802 case FieldType::PtrField:
803 case FieldType::ParentPtrField:
804 case FieldType::ChildPtrField:
805 szFieldPtrTypeName = szFieldPtrTypeName.substr(
807 szFieldPtrTypeName.size() - 3);
808 break;
809 default:
810 case FieldType::ValueField:
811 return false;
812 break;
815 const FieldContainerType *pPtrContentType =
816 FieldContainerFactory::the()->findType(szFieldPtrTypeName.c_str());
818 return pFCType->isDerivedFrom(*pPtrContentType);
820 else
822 return false;
825 return false;
828 const FieldContainerType *getFieldContainerTypeFromPtrType(
829 const DataType &oType)
831 std::string szFCPtrTypeName =
832 oType.getName().substr(0, oType.getName().size() - 3);
834 return FieldContainerFactory::the()->findType(szFCPtrTypeName.c_str());
839 const FieldContainerType *getClosestAncestor(
840 const FieldContainerType *pType,
841 MFUnrecFieldContainerPtr::const_iterator begin,
842 MFUnrecFieldContainerPtr::const_iterator end)
844 if(pType == NULL)
846 return NULL;
849 const FieldContainerType *pAncestorType = NULL;
850 const FieldContainerType *pFCType = NULL;
852 MFUnrecFieldContainerPtr::const_iterator it = begin;
854 for(; it != end ; ++it)
856 pFCType = &((*it)->getType());
858 if(pType->isDerivedFrom(*pFCType) &&
859 (pAncestorType == NULL || pFCType->isDerivedFrom(*pAncestorType)))
861 pAncestorType = pFCType;
865 return pAncestorType;
868 std::vector<FieldContainer *> getAllContainersByDerivedType(
869 const FieldContainerType *pType)
871 std::vector<FieldContainer *> vResult;
873 const FieldContainerFactoryBase::ContainerStore &oFCStore =
874 FieldContainerFactory::the()->getFieldContainerStore();
876 FieldContainerFactoryBase::ContainerStore::const_iterator fcStoreIt =
877 oFCStore.begin();
879 FieldContainerFactoryBase::ContainerPtr pCont =
880 NULL;
882 for(;fcStoreIt != oFCStore.end() ; ++fcStoreIt)
884 if((*fcStoreIt).second != NULL)
886 #ifdef OSG_MT_CPTR_ASPECT
887 pCont = (*fcStoreIt).second->getPtr();
888 #else
889 pCont = *fcStoreIt .second;
890 #endif
892 else
894 pCont = NULL;
896 if(pCont != NULL && pCont->getType().isDerivedFrom(*pType))
898 vResult.push_back(pCont);
902 return vResult;
905 #if 0
906 std::vector<FieldContainerPtr> getAllContainersByType(const FieldContainerType *szType)
908 std::vector<FieldContainerPtr> Result;
910 const std::vector<FieldContainerPtr>* FCStore( FieldContainerFactory::the()->getFieldContainerStore () );
912 std::vector<FieldContainerPtr>::const_iterator FCStoreIter;
913 for(FCStoreIter = FCStore->begin() ; FCStoreIter != FCStore->end() ; ++FCStoreIter)
915 if( (*FCStoreIter) != NullFC && (*FCStoreIter)->getType() == (*szType) )
917 Result.push_back(*FCStoreIter);
921 return Result;
925 std::vector<FieldContainerPtr> getAllFieldContainers(const std::string &namestring)
927 std::vector<FieldContainerPtr> Result;
928 std::vector<FieldContainerPtr>::const_iterator FCStoreIter;
930 const std::vector<FieldContainerPtr>* FCStore( FieldContainerFactory::the()->getFieldContainerStore () );
932 for(FCStoreIter = FCStore->begin() ; FCStoreIter != FCStore->end() ; ++FCStoreIter)
934 const Char8 *Name( getName(AttachmentContainerPtr::dcast(*FCStoreIter)) );
935 if(Name != NULL && namestring.compare(Name) == 0)
937 //Result.push_back(*FCStoreIter);
940 return Result;
943 #endif
945 OSG_END_NAMESPACE