CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

TEveElementIter Class Reference

#include <TEveElementIter.h>

List of all members.

Public Member Functions

TEveElement * current ()
TEveElement * next ()
TEveElement * reset ()
unsigned int size ()
 TEveElementIter (TEveElement *, const char *regular_expression=0)

Private Member Functions

void addElement (TEveElement *)

Private Attributes

std::vector< TEveElement * > elements
std::vector< TEveElement * >
::iterator 
iter
TPRegexp regexp

Detailed Description

Definition at line 15 of file TEveElementIter.h.


Constructor & Destructor Documentation

TEveElementIter::TEveElementIter ( TEveElement *  element,
const char *  regular_expression = 0 
)

Definition at line 7 of file TEveElementIter.cc.

References addElement(), elements, fwLog, getHLTprescales::index, iter, fwlog::kError, parents, and regexp.

{
   if ( regular_expression ) regexp = TPRegexp( regular_expression );
   std::stack<std::pair<TEveElement*,TEveElement::List_i> > parents;
   parents.push( std::pair<TEveElement*,TEveElement::List_i>( element, element->BeginChildren() ) );

   unsigned int index = 0; // index number to prevent endless loops
   unsigned int indexLimit = 1000000;
   while ( !parents.empty() && ++index < indexLimit ) {
      // take care of finished loop
      if ( parents.top().second == parents.top().first->EndChildren() )
      {
         addElement( parents.top().first );
         parents.pop();
         if ( !parents.empty() ) ++(parents.top().second);
         continue;
      }

      // find element without children
      if ( (*parents.top().second)->NumChildren() > 0 ) {
         parents.push( std::pair<TEveElement*,TEveElement::List_i>( *(parents.top().second),
                                                                    (*parents.top().second)->BeginChildren() ) );
         continue;
      }

      // we have a leaf element (no children) to process
      addElement( *(parents.top().second) );
      ++(parents.top().second);
   }
   if ( index >= indexLimit ) {
      fwLog(fwlog::kError) << " tree loop limit is reached!\n"
                << "You either have a tree with loops or navigation logic is broken." << std::endl;
      elements.clear();
   }
   iter = elements.begin();
}

Member Function Documentation

void TEveElementIter::addElement ( TEveElement *  element) [private]

Definition at line 65 of file TEveElementIter.cc.

References elements, and regexp.

Referenced by TEveElementIter().

{
   if (!element ) return;
   TNamed* named = dynamic_cast<TNamed*>(element);
   if ( named && !regexp.MatchB(named->GetName()) ) return;
   elements.push_back( element );
}
TEveElement * TEveElementIter::current ( )

Definition at line 51 of file TEveElementIter.cc.

References elements, and iter.

Referenced by next(), and reset().

{
   if ( iter == elements.end() )
      return 0;
   else
      return *iter;
}
TEveElement * TEveElementIter::next ( void  )

Definition at line 44 of file TEveElementIter.cc.

References current(), elements, and iter.

{
   if ( iter == elements.end() ) return 0;
   ++iter;
   return current();
}
TEveElement * TEveElementIter::reset ( void  )

Definition at line 59 of file TEveElementIter.cc.

References current(), elements, and iter.

{
   iter = elements.begin();
   return current();
}
unsigned int TEveElementIter::size ( void  ) [inline]

Definition at line 25 of file TEveElementIter.h.

References elements.

                       {
      return elements.size();
   }

Member Data Documentation

std::vector<TEveElement*> TEveElementIter::elements [private]

Definition at line 18 of file TEveElementIter.h.

Referenced by addElement(), current(), next(), reset(), size(), and TEveElementIter().

std::vector<TEveElement*>::iterator TEveElementIter::iter [private]

Definition at line 19 of file TEveElementIter.h.

Referenced by current(), next(), reset(), and TEveElementIter().

TPRegexp TEveElementIter::regexp [private]

Definition at line 17 of file TEveElementIter.h.

Referenced by addElement(), and TEveElementIter().