test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TEveElementIter.cc
Go to the documentation of this file.
3 #include "TEveElement.h"
4 #include "TNamed.h"
5 #include <iostream>
6 #include <stack>
7 TEveElementIter::TEveElementIter( TEveElement* element, const char* regular_expression /* = 0 */ )
8 {
9  if ( regular_expression ) regexp = TPRegexp( regular_expression );
10  std::stack<std::pair<TEveElement*,TEveElement::List_i> > parents;
11  parents.push( std::pair<TEveElement*,TEveElement::List_i>( element, element->BeginChildren() ) );
12 
13  unsigned int index = 0; // index number to prevent endless loops
14  unsigned int indexLimit = 1000000;
15  while ( !parents.empty() && ++index < indexLimit ) {
16  // take care of finished loop
17  if ( parents.top().second == parents.top().first->EndChildren() )
18  {
19  addElement( parents.top().first );
20  parents.pop();
21  if ( !parents.empty() ) ++(parents.top().second);
22  continue;
23  }
24 
25  // find element without children
26  if ( (*parents.top().second)->NumChildren() > 0 ) {
27  parents.push( std::pair<TEveElement*,TEveElement::List_i>( *(parents.top().second),
28  (*parents.top().second)->BeginChildren() ) );
29  continue;
30  }
31 
32  // we have a leaf element (no children) to process
33  addElement( *(parents.top().second) );
34  ++(parents.top().second);
35  }
36  if ( index >= indexLimit ) {
37  fwLog(fwlog::kError) << " tree loop limit is reached!\n"
38  << "You either have a tree with loops or navigation logic is broken." << std::endl;
39  elements.clear();
40  }
41  iter = elements.begin();
42 }
43 
44 TEveElement* TEveElementIter::next()
45 {
46  if ( iter == elements.end() ) return 0;
47  ++iter;
48  return current();
49 }
50 
52 {
53  if ( iter == elements.end() )
54  return 0;
55  else
56  return *iter;
57 }
58 
59 TEveElement* TEveElementIter::reset()
60 {
61  iter = elements.begin();
62  return current();
63 }
64 
65 void TEveElementIter::addElement( TEveElement* element )
66 {
67  if (!element ) return;
68  TNamed* named = dynamic_cast<TNamed*>(element);
69  if ( named && !regexp.MatchB(named->GetName()) ) return;
70  elements.push_back( element );
71 }
72 
TPRegexp parents
Definition: eve_filter.cc:21
TEveElement * next()
TEveElementIter(TEveElement *, const char *regular_expression=0)
TEveElement * current()
std::vector< TEveElement * >::iterator iter
std::vector< TEveElement * > elements
#define fwLog(_level_)
Definition: fwLog.h:50
TEveElement * reset()
void addElement(TEveElement *)