inlib  1.2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
inlib::ntu::base_looper< T > Class Template Reference
Inheritance diagram for inlib::ntu::base_looper< T >:
Inheritance graph
[legend]
Collaboration diagram for inlib::ntu::base_looper< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 base_looper (base_ntu &a_ntu, const base_col &a_col)
virtual ~base_looper ()
 base_looper (const base_looper &a_from)
base_looperoperator= (const base_looper &a_from)
bool process ()

Static Public Member Functions

static const std::string & s_class ()

Protected Member Functions

virtual bool action (const T &a_value)=0
bool _looper (base_ntu &a_sub, const std::vector< unsigned int > &a_is, unsigned int a_depth, bool &a_stop)

Static Protected Member Functions

static bool find_is (const base_ntu &a_ntu, const base_col *a_col, std::vector< unsigned int > &a_is, bool &a_found)

Protected Attributes

base_ntum_ntu
const base_colm_col

Detailed Description

template<class T>
class inlib::ntu::base_looper< T >

Definition at line 640 of file aida.


Constructor & Destructor Documentation

template<class T >
inlib::ntu::base_looper< T >::base_looper ( base_ntu a_ntu,
const base_col a_col 
) [inline]

Definition at line 649 of file aida.

  :m_ntu(a_ntu),m_col(a_col){
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }
template<class T >
virtual inlib::ntu::base_looper< T >::~base_looper ( ) [inline, virtual]

Definition at line 655 of file aida.

                        {
#ifdef INLIB_MEM
    mem::decrement(s_class().c_str());
#endif
  }
template<class T >
inlib::ntu::base_looper< T >::base_looper ( const base_looper< T > &  a_from) [inline]

Definition at line 661 of file aida.

  :m_ntu(a_from.m_ntu),m_col(a_from.m_col){
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }

Member Function Documentation

template<class T >
bool inlib::ntu::base_looper< T >::_looper ( base_ntu a_sub,
const std::vector< unsigned int > &  a_is,
unsigned int  a_depth,
bool &  a_stop 
) [inline, protected]

Definition at line 742 of file aida.

                                    {
    if(a_depth>=a_is.size()) return false;

    unsigned int coli = a_is[a_depth];  
    const std::vector<base_col*>& cols = a_sub.cols();
    if(coli>=cols.size()) return false;

    if(a_depth==(a_is.size()-1)) { //we reach the leaf.
      aida_col<T>* col = cast<base_col, aida_col<T> >(*(cols[coli]));
      if(!col) return false;
      a_sub.start();
      while(a_sub.next()) {
        T v;
        if(!col->get_entry(v)) return false;
        if(!action(v)) {a_stop = true;break;}
      }
    } else {
      aida_col_ntu* col = cast<base_col,aida_col_ntu>(*(cols[coli]));
      if(!col) return false;
      a_sub.start();
      while(a_sub.next()) {
        base_ntu* ntu = col->get_entry(); //not const.
        if(!ntu) return false;
        ntu->start();
        while(ntu->next()) {
          if(!_looper(*ntu,a_is,a_depth+1,a_stop)) return false;
          if(a_stop) break;
        }
      }
    }
    return true;
  }
template<class T >
virtual bool inlib::ntu::base_looper< T >::action ( const T &  a_value) [protected, pure virtual]
template<class T >
static bool inlib::ntu::base_looper< T >::find_is ( const base_ntu a_ntu,
const base_col a_col,
std::vector< unsigned int > &  a_is,
bool &  a_found 
) [inline, static, protected]

Definition at line 707 of file aida.

                                           {
    // search the indices to reach the sub leaf a_col from the main a_ntu.    
    // Note : it is assumed that a_is is empty and a_found = false before
    //        calling with function.
  
    const std::vector<base_col*>& cols = a_ntu.cols();
    std::vector<base_col*>::const_iterator it;
  
    // look if a_col is a leaf col of a_ntu :
   {unsigned int index = 0;
    for(it=cols.begin();it!=cols.end();++it,index++) {
      if(*it==a_col) {
        a_is.push_back(index); //leaf index is the last one in a_is.
        a_found = true;
        return true;
      }
    }}
  
    // go down sub ntu :
   {unsigned int index = 0;
    for(it=cols.begin();it!=cols.end();++it,index++) {
      aida_col_ntu* col = cast<base_col,aida_col_ntu>(*(*it));
      if(!col) continue;
      base_ntu* sub = col->get_to_fill(); //it holds the "sub" cols schema.
      if(!sub) {a_is.clear();return false;}
      a_is.push_back(index);
      if(!find_is(*sub,a_col,a_is,a_found)) {a_is.clear();return false;}
      if(a_found) return true;
      a_is.pop_back();
    }}
    return true;
  }  
template<class T >
base_looper& inlib::ntu::base_looper< T >::operator= ( const base_looper< T > &  a_from) [inline]

Definition at line 667 of file aida.

{return *this;}
template<class T >
bool inlib::ntu::base_looper< T >::process ( ) [inline]

Reimplemented in inlib::ntu::stat_looper< T >.

Definition at line 669 of file aida.

                 {
    std::vector<unsigned int> is;
    bool found = false;
    if(!find_is(m_ntu,&m_col,is,found)) {
      m_ntu.out() << s_class() << "::process :"
                  << " find_is failed."
                  << std::endl;
      return false;
    }
    if(!found) {
      m_ntu.out() << s_class() << "::process :"
                  << " find_is : col not found."
                  << std::endl;
      return false;
    }
    if(is.empty()) {
      m_ntu.out() << s_class() << "::process :"
                  << " is vec empty."
                  << std::endl;
      return false;
    }

  //{m_ntu.out() << "debug : sz " << is.size() << std::endl;
  // std::vector<unsigned int>::const_iterator it;
  // for(it=is.begin();it!=is.end();++it){
  //   m_ntu.out() << "  " << *it << std::endl;       
  //}}

    bool stop = false;
    if(!_looper(m_ntu,is,0,stop)) {
      m_ntu.out() << s_class() << "::process :"
                  << " _looper failed."
                  << std::endl;
      return false;
    }
    return true;
  }
template<class T >
static const std::string& inlib::ntu::base_looper< T >::s_class ( ) [inline, static]

Definition at line 642 of file aida.

                                    {
    static const std::string s_v("inlib::ntu::base_looper<"+stype(T())+">");
    return s_v;
  }

Member Data Documentation

template<class T >
const base_col& inlib::ntu::base_looper< T >::m_col [protected]

Definition at line 779 of file aida.

template<class T >
base_ntu& inlib::ntu::base_looper< T >::m_ntu [protected]

Definition at line 778 of file aida.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines