Go to the documentation of this file.00001 #include "Fireworks/Core/interface/TEveElementIter.h"
00002 #include "Fireworks/Core/interface/fwLog.h"
00003 #include "TEveElement.h"
00004 #include "TNamed.h"
00005 #include <iostream>
00006 #include <stack>
00007 TEveElementIter::TEveElementIter( TEveElement* element, const char* regular_expression )
00008 {
00009 if ( regular_expression ) regexp = TPRegexp( regular_expression );
00010 std::stack<std::pair<TEveElement*,TEveElement::List_i> > parents;
00011 parents.push( std::pair<TEveElement*,TEveElement::List_i>( element, element->BeginChildren() ) );
00012
00013 unsigned int index = 0;
00014 unsigned int indexLimit = 1000000;
00015 while ( !parents.empty() && ++index < indexLimit ) {
00016
00017 if ( parents.top().second == parents.top().first->EndChildren() )
00018 {
00019 addElement( parents.top().first );
00020 parents.pop();
00021 if ( !parents.empty() ) ++(parents.top().second);
00022 continue;
00023 }
00024
00025
00026 if ( (*parents.top().second)->NumChildren() > 0 ) {
00027 parents.push( std::pair<TEveElement*,TEveElement::List_i>( *(parents.top().second),
00028 (*parents.top().second)->BeginChildren() ) );
00029 continue;
00030 }
00031
00032
00033 addElement( *(parents.top().second) );
00034 ++(parents.top().second);
00035 }
00036 if ( index >= indexLimit ) {
00037 fwLog(fwlog::kError) << " tree loop limit is reached!\n"
00038 << "You either have a tree with loops or navigation logic is broken." << std::endl;
00039 elements.clear();
00040 }
00041 iter = elements.begin();
00042 }
00043
00044 TEveElement* TEveElementIter::next()
00045 {
00046 if ( iter == elements.end() ) return 0;
00047 ++iter;
00048 return current();
00049 }
00050
00051 TEveElement* TEveElementIter::current()
00052 {
00053 if ( iter == elements.end() )
00054 return 0;
00055 else
00056 return *iter;
00057 }
00058
00059 TEveElement* TEveElementIter::reset()
00060 {
00061 iter = elements.begin();
00062 return current();
00063 }
00064
00065 void TEveElementIter::addElement( TEveElement* element )
00066 {
00067 if (!element ) return;
00068 TNamed* named = dynamic_cast<TNamed*>(element);
00069 if ( named && !regexp.MatchB(named->GetName()) ) return;
00070 elements.push_back( element );
00071 }
00072