CMS 3D CMS Logo

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  if (regular_expression)
9  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  addElement(parents.top().first);
19  parents.pop();
20  if (!parents.empty())
21  ++(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  if (iter == elements.end())
46  return nullptr;
47  ++iter;
48  return current();
49 }
50 
51 TEveElement* TEveElementIter::current() {
52  if (iter == elements.end())
53  return nullptr;
54  else
55  return *iter;
56 }
57 
58 TEveElement* TEveElementIter::reset() {
59  iter = elements.begin();
60  return current();
61 }
62 
63 void TEveElementIter::addElement(TEveElement* element) {
64  if (!element)
65  return;
66  TNamed* named = dynamic_cast<TNamed*>(element);
67  if (named && !regexp.MatchB(named->GetName()))
68  return;
69  elements.push_back(element);
70 }
TPRegexp parents
Definition: eve_filter.cc:21
TEveElement * next()
TEveElement * current()
std::vector< TEveElement * >::iterator iter
std::vector< TEveElement * > elements
#define fwLog(_level_)
Definition: fwLog.h:45
TEveElement * reset()
void addElement(TEveElement *)
TEveElementIter(TEveElement *, const char *regular_expression=nullptr)