fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Misc / OSGFieldContainerUtils.cpp
blobbbd323c893e0ea7981641ba391cbf66d1496ec15
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
285 struct FieldPathEntry
287 std::string szName;
288 Int32 iIndex;
290 FieldPathEntry(void) : szName(), iIndex(0) {}
293 void splitFieldPath( std::vector<FieldPathEntry> &vSplitPath,
294 const Char8 *szFieldPath)
296 std::string tmpName(szFieldPath);
298 std::string::size_type sStart = 0;
299 std::string::size_type sEnd = 0;
300 std::string::size_type sLength = 0;
301 std::string::size_type sLastChar = 0;
302 FieldPathEntry tmpEntry;
304 std::string szIdx;
308 sEnd = tmpName.find("/", sStart);
310 if(sEnd != std::string::npos)
312 sLength = sEnd - sStart;
314 else
316 sLength = tmpName.length() - sStart;
319 sLastChar = sStart + sLength - 1;
321 vSplitPath.push_back(tmpEntry);
323 vSplitPath.back().iIndex = -1;
325 if(tmpName[sLastChar] == ')')
327 std::string::size_type sIdxStart =
328 tmpName.rfind('(', sLastChar); //, sLength);
330 if(sIdxStart == std::string::npos)
332 vSplitPath.clear();
334 return;
337 tmpName[sIdxStart] = '$';
338 tmpName[sLastChar] = '$';
340 sLength -= sLastChar - sIdxStart + 1;
342 ++sIdxStart;
344 szIdx.assign(tmpName,
345 sIdxStart,
346 sLastChar - sIdxStart);
348 vSplitPath.back().iIndex =
349 TypeTraits<UInt32>::getFromCString(szIdx.c_str());
352 vSplitPath.back().szName.assign(tmpName, sStart, sLength);
354 sStart = sEnd + 1;
356 while(sEnd != std::string::npos);
359 FieldContainer *resolveFieldPath(std::vector<FieldPathEntry> &vSplitPath,
360 FieldContainer *pRoot )
362 if(pRoot == NULL)
363 return NULL;
365 FieldContainer *returnValue = pRoot;
367 OSG::GetFieldHandlePtr fHandle;
369 for(UInt32 i = 1; i < vSplitPath.size(); ++i)
371 fHandle = returnValue->getField(vSplitPath[i].szName.c_str());
373 if(fHandle == NULL || fHandle->isValid() == false)
375 FWARNING(("Unknown field '%s'\n",
376 vSplitPath[i].szName.c_str()));
378 returnValue = NULL;
380 break;
383 OSG::FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr =
384 boost::dynamic_pointer_cast<
385 OSG::FieldContainerPtrSFieldBase::GetHandle>(fHandle);
387 OSG::FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr =
388 boost::dynamic_pointer_cast<
389 OSG::FieldContainerPtrMFieldBase::GetHandle>(fHandle);
391 if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
393 returnValue = (*sfFCPtr)->getValue();
395 else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
397 UInt32 uiIndex =
398 vSplitPath[i].iIndex == -1 ? 0 : vSplitPath[i].iIndex;
400 if(uiIndex >= mfFCPtr->size())
402 FWARNING(("Unknown index %d to large for field '%s'\n",
403 uiIndex,
404 vSplitPath[i].szName.c_str()));
406 returnValue = NULL;
408 break;
411 returnValue = (**mfFCPtr)[uiIndex];
415 return returnValue;
418 FieldContainer *resolveFieldPathImpl(const Char8 *szNodeName,
419 ContainerResolver oResolver )
421 std::vector<FieldPathEntry> vSplitPath;
423 splitFieldPath(vSplitPath, szNodeName);
425 if(vSplitPath.size() == 0)
426 return NULL;
428 FieldContainer *returnValue = oResolver(vSplitPath[0].szName.c_str());
430 returnValue = resolveFieldPath(vSplitPath, returnValue);
432 return returnValue;
437 struct ContainerVisitRecord
439 typedef std::vector<UInt32>::iterator VisitedIt;
441 std::vector<UInt32> vVisitedIds;
443 bool visit(UInt32 uiContainerId);
445 ContainerVisitRecord(void) : vVisitedIds() {}
448 bool ContainerVisitRecord::visit(UInt32 uiContainerId)
450 VisitedIt vIt = std::lower_bound(vVisitedIds.begin(),
451 vVisitedIds.end (),
452 uiContainerId );
454 if(vIt != vVisitedIds.end())
456 if(*vIt == uiContainerId)
457 return false;
459 vVisitedIds.insert(vIt, uiContainerId);
461 else
463 vVisitedIds.push_back(uiContainerId);
466 return true;
469 FieldContainer *findNamedComponentImpl( ContainerVisitRecord &oVisited,
470 FieldContainer *pCnt,
471 const Char8 *szName )
473 if(pCnt == NULL)
474 return NULL;
476 const Char8 *szTmpName = NULL;
478 const AttachmentContainer *pAC =
479 dynamic_cast<const AttachmentContainer *>(pCnt);
481 #if 0
482 fprintf(stderr, "findNamedComponent::visit %p type %s\n",
483 pCnt,
484 pCnt->getType().getCName());
485 #endif
487 szTmpName = OSG::getName(pAC);
489 if(szTmpName != NULL && osgStringCmp(szTmpName, szName) == 0)
491 return pCnt;
494 if(oVisited.visit(pCnt->getId()) == false)
496 return NULL;
499 const Node *pNode = dynamic_cast<const Node *>(pCnt);
501 if(pNode != NULL)
503 if(0x0000 == (pNode->getTravMask() &
504 TraversalMasks::FindNamedComponentTraversal))
506 return NULL;
510 BitVector bvExcludedFields = TypeTraits<BitVector>::BitsSet;
512 const ControlFindNamedElemInterface *pCFNInterface =
513 dynamic_cast<ControlFindNamedElemInterface *>(pCnt);
515 if(pCFNInterface != NULL)
517 bvExcludedFields = pCFNInterface->excludeFields();
520 const FieldContainerType &fcType = pCnt->getType();
521 UInt32 fCount = fcType.getNumFieldDescs();
523 for(UInt32 i = 1; i <= fCount; ++i)
525 const FieldDescriptionBase *fDesc = fcType.getFieldDesc(i);
527 if(fDesc->getFieldType().getClass() == FieldType::ParentPtrField)
528 continue;
530 if(0x0000 == (bvExcludedFields & fDesc->getFieldMask()))
531 continue;
533 GetFieldHandlePtr srcField = pCnt->getField(i);
535 FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr =
536 boost::dynamic_pointer_cast<
537 FieldContainerPtrSFieldBase::GetHandle>(srcField);
539 FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr =
540 boost::dynamic_pointer_cast<
541 FieldContainerPtrMFieldBase::GetHandle>(srcField);
543 if( sfFCPtr != NULL &&
544 sfFCPtr->isValid() == true &&
545 (*sfFCPtr)->getValue() != NULL )
547 FieldContainer *rc = findNamedComponentImpl(oVisited,
548 (*sfFCPtr)->getValue(),
549 szName );
550 if(rc != NULL)
551 return rc;
553 else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
555 SizeT mfSize = (*mfFCPtr)->size();
557 for(SizeT j = 0; j < mfSize; j++)
559 if((**mfFCPtr)[j] != NULL)
561 FieldContainer *rc = findNamedComponentImpl(oVisited,
562 (**mfFCPtr)[j],
563 szName);
565 if(rc != NULL)
566 return rc;
572 return NULL;
575 FieldContainer *findNamedComponentImpl( FieldContainer *pCnt,
576 const Char8 *szName)
578 ContainerVisitRecord oVisited;
580 return findNamedComponentImpl(oVisited, pCnt, szName);
583 } // namespace
585 /*! Compares two FieldContainer \a lhs and \a rhs for equivalence. The meaning
586 of this comparison can be tweaked with the additional arguments.
587 If \a ignoreAttachments is \c true, Attachments are excluded from the
588 comparison.
589 If \a compareIdentity is \c true, pointers are compared by
590 address otherwise the pointed-to objects are compared for equivalence.
592 bool compareContainerEqual(
593 const FieldContainer *lhs,
594 const FieldContainer *rhs,
595 bool ignoreAttachments,
596 bool compareIdentity )
598 FCSet lhsVisitedSet;
599 FCSet rhsVisitedSet;
601 return compareContainerEqualImpl(
602 lhs, rhs, lhsVisitedSet, rhsVisitedSet,
603 ignoreAttachments, compareIdentity );
606 //---------------------------------------------------------------------------
607 // MemoryConsumption
608 //---------------------------------------------------------------------------
610 void MemoryConsumption::scan(void)
612 FieldContainerFactory::the()->lockStore();
614 FieldContainerFactoryBase::ContainerStoreConstIt sIt =
615 FieldContainerFactory::the()->beginStore();
616 FieldContainerFactoryBase::ContainerStoreConstIt sEnd =
617 FieldContainerFactory::the()->endStore();
619 for(; sIt != sEnd; ++sIt)
621 FieldContainer *pFC = (*sIt).second->getPtr();
623 if(pFC == NULL)
624 continue;
626 TypeMemMapIt tmIt = _memMap.find(pFC->getType().getId());
627 SizeT binSize = pFC->getBinSize(TypeTraits<BitVector>::BitsSet);
629 if(tmIt != _memMap.end())
631 tmIt->second.first += binSize;
632 tmIt->second.second += 1;
634 else
636 _memMap[pFC->getType().getId()] = MemCountPair(binSize, 1);
640 FieldContainerFactory::the()->unlockStore();
644 void MemoryConsumption::print(std::ostream &os, bool ignoreProto) const
646 TypeMemMapConstIt tmIt = _memMap.begin();
647 TypeMemMapConstIt tmEnd = _memMap.end ();
649 SizeT totalMem = 0;
650 UInt32 totalCount = 0;
651 boost::format formatter("%|1$-25| [%|2$8|] Byte [%|3$8.0f|] kByte [%|4$4|]\n");
653 for(; tmIt != tmEnd; ++tmIt)
655 FieldContainerType *fcType =
656 FieldContainerFactory::the()->findType(tmIt->first);
658 if(fcType == NULL)
659 continue;
661 if(ignoreProto && tmIt->second.second == 1)
662 continue;
664 os << formatter % fcType->getCName()
665 % tmIt->second.first
666 % (tmIt->second.first / 1024.f)
667 % tmIt->second.second;
669 totalMem += tmIt->second.first;
670 totalCount += tmIt->second.second;
673 os << "--------------------------------------------\n";
674 os << formatter % "Total"
675 % totalMem
676 % (totalMem / 1024.f)
677 % totalCount;
680 MemoryConsumption::TypeMemMapConstIt MemoryConsumption::beginMap(void) const
682 return _memMap.begin();
685 MemoryConsumption::TypeMemMapConstIt MemoryConsumption::endMap(void) const
687 return _memMap.end();
690 ControlFindNamedElemInterface::ControlFindNamedElemInterface(void)
694 ControlFindNamedElemInterface::~ControlFindNamedElemInterface(void)
699 FieldContainer *resolveFieldPath(const Char8 *szNodeName,
700 ContainerResolver oResolver )
702 return resolveFieldPathImpl(szNodeName, oResolver);
705 FieldContainer *findNamedComponent( FieldContainer *pCnt,
706 const Char8 *szName)
708 return findNamedComponentImpl(pCnt, szName);
713 FieldContainer *getFieldContainer(const std::string &szTypeName,
714 const std::string &szName)
716 return getFieldContainer(
717 FieldContainerFactory::the()->findType(szTypeName.c_str()), szName);
720 FieldContainer *getFieldContainer(const FieldContainerType *pType,
721 const std::string &szName)
723 if(pType == NULL)
725 SWARNING << "getFieldContainer(): The Field type is not defined."
726 << std::endl;
728 return NULL;
731 const FieldContainerFactoryBase::ContainerStore &oFCStore(
732 FieldContainerFactory::the()->getFieldContainerStore());
734 FieldContainerFactoryBase::ContainerStore::const_iterator fcStoreIt =
735 oFCStore.begin();
737 FieldContainerFactoryBase::ContainerPtr pCont = NULL;
739 for(; fcStoreIt != oFCStore.end() ; ++fcStoreIt)
741 #ifdef OSG_MT_CPTR_ASPECT
742 pCont = (*fcStoreIt).second->getPtr();
743 #else
744 pCont = *fcStoreIt .second;
745 #endif
747 if(pCont != NULL && pCont->getType() == (*pType))
749 const Char8 *szCntName =
750 getName(dynamic_cast<AttachmentContainer *>(pCont));
752 if(szCntName != NULL && szName.compare(szCntName) == 0)
754 return pCont;
759 return NULL;
763 FieldContainer *getFieldContainer(const std::string &szName)
765 const FieldContainerFactoryBase::ContainerStore &oFCStore =
766 FieldContainerFactory::the()->getFieldContainerStore();
768 FieldContainerFactoryBase::ContainerStore::const_iterator fcStoreIt =
769 oFCStore.begin();
771 FieldContainerFactoryBase::ContainerPtr pCont = NULL;
773 for(; fcStoreIt != oFCStore.end() ; ++fcStoreIt)
775 if((*fcStoreIt).second == NULL)
777 continue;
780 #ifdef OSG_MT_CPTR_ASPECT
781 pCont = (*fcStoreIt).second->getPtr();
782 #else
783 pCont = *fcStoreIt .second;
784 #endif
785 const Char8 *szCntName =
786 getName(dynamic_cast<AttachmentContainer *>(pCont));
788 if(szCntName != NULL && szName.compare(szCntName) == 0)
790 return pCont;
794 return NULL;
798 bool isFieldContentDerivedFrom(const FieldType &oFieldType,
799 const FieldContainerType *pFCType)
801 if(oFieldType.isPtrField())
803 std::string szFieldPtrTypeName(oFieldType.getContentType().getName());
805 switch(oFieldType.getClass())
807 case FieldType::PtrField:
808 case FieldType::ParentPtrField:
809 case FieldType::ChildPtrField:
810 szFieldPtrTypeName = szFieldPtrTypeName.substr(
812 szFieldPtrTypeName.size() - 3);
813 break;
814 default:
815 case FieldType::ValueField:
816 return false;
817 break;
820 const FieldContainerType *pPtrContentType =
821 FieldContainerFactory::the()->findType(szFieldPtrTypeName.c_str());
823 return pFCType->isDerivedFrom(*pPtrContentType);
825 else
827 return false;
830 return false;
833 const FieldContainerType *getFieldContainerTypeFromPtrType(
834 const DataType &oType)
836 std::string szFCPtrTypeName =
837 oType.getName().substr(0, oType.getName().size() - 3);
839 return FieldContainerFactory::the()->findType(szFCPtrTypeName.c_str());
844 const FieldContainerType *getClosestAncestor(
845 const FieldContainerType *pType,
846 MFUnrecFieldContainerPtr::const_iterator begin,
847 MFUnrecFieldContainerPtr::const_iterator end)
849 if(pType == NULL)
851 return NULL;
854 const FieldContainerType *pAncestorType = NULL;
855 const FieldContainerType *pFCType = NULL;
857 MFUnrecFieldContainerPtr::const_iterator it = begin;
859 for(; it != end ; ++it)
861 pFCType = &((*it)->getType());
863 if(pType->isDerivedFrom(*pFCType) &&
864 (pAncestorType == NULL || pFCType->isDerivedFrom(*pAncestorType)))
866 pAncestorType = pFCType;
870 return pAncestorType;
873 std::vector<FieldContainer *> getAllContainersByDerivedType(
874 const FieldContainerType *pType)
876 std::vector<FieldContainer *> vResult;
878 const FieldContainerFactoryBase::ContainerStore &oFCStore =
879 FieldContainerFactory::the()->getFieldContainerStore();
881 FieldContainerFactoryBase::ContainerStore::const_iterator fcStoreIt =
882 oFCStore.begin();
884 FieldContainerFactoryBase::ContainerPtr pCont =
885 NULL;
887 for(;fcStoreIt != oFCStore.end() ; ++fcStoreIt)
889 if((*fcStoreIt).second != NULL)
891 #ifdef OSG_MT_CPTR_ASPECT
892 pCont = (*fcStoreIt).second->getPtr();
893 #else
894 pCont = *fcStoreIt .second;
895 #endif
897 else
899 pCont = NULL;
901 if(pCont != NULL && pCont->getType().isDerivedFrom(*pType))
903 vResult.push_back(pCont);
907 return vResult;
910 #if 0
911 std::vector<FieldContainerPtr> getAllContainersByType(const FieldContainerType *szType)
913 std::vector<FieldContainerPtr> Result;
915 const std::vector<FieldContainerPtr>* FCStore( FieldContainerFactory::the()->getFieldContainerStore () );
917 std::vector<FieldContainerPtr>::const_iterator FCStoreIter;
918 for(FCStoreIter = FCStore->begin() ; FCStoreIter != FCStore->end() ; ++FCStoreIter)
920 if( (*FCStoreIter) != NullFC && (*FCStoreIter)->getType() == (*szType) )
922 Result.push_back(*FCStoreIter);
926 return Result;
930 std::vector<FieldContainerPtr> getAllFieldContainers(const std::string &namestring)
932 std::vector<FieldContainerPtr> Result;
933 std::vector<FieldContainerPtr>::const_iterator FCStoreIter;
935 const std::vector<FieldContainerPtr>* FCStore( FieldContainerFactory::the()->getFieldContainerStore () );
937 for(FCStoreIter = FCStore->begin() ; FCStoreIter != FCStore->end() ; ++FCStoreIter)
939 const Char8 *Name( getName(AttachmentContainerPtr::dcast(*FCStoreIter)) );
940 if(Name != NULL && namestring.compare(Name) == 0)
942 //Result.push_back(*FCStoreIter);
945 return Result;
948 #endif
950 OSG_END_NAMESPACE