The Iterative Classes


The Iterative classes are a group of helper classes that provide a set interface between each level of compound structure (entity, subentity, and so on) and the procedures that access those structures. An Iterator object navigates through all objects of a List which can be one of the classes derived from the ListMgr base class. Filters enumerate on top of iterators and filter out a set of objects that match a certain criteria. Iterator and Filter objects are generated and destroyed dynamically at run time by application programs, in order to navigate compound structures. Iterative classes reduce the dependancy between application programs, and the underlying compound structure such that modifying the compound structure has minimal impact on application programs.


Click here too see more on Iterators

Click here too see more on Filters


These are the Iterator Classes


These are the Filter Classes


Class ListIter


template class ListIter {

protected:
  ListMgr * _list;
  T * _element;
  ListIter(){ _list=0; _element=0;}

public:
  ListIter(ListMgr& l,int order=0){
    _list=l.CopyOfSelf(order);
    MoveToTop();
  }
  virtual ~ListIter(){
    if (_list) delete _list;
  }
  operator const void *() const {return _element?this:0;}
  T& operator()() const {return *_element;}
  void MoveToNext(){
    ++(*_list);
    _element=&(*_list)();
  }
  void MoveToPrevious(){
    --(*_list);
    _element=&(*_list)();
  }
  void MoveToTop(){_list->ResetToTop(); _element=&(*_list)();}
  void MoveToEnd(){_list->ResetToEnd(); _element=&(*_list)();}
};


Class CompdIter


class CompdIter : public ListIter{
 public:
  CompdIter(const ListMgr & lp){
    if (&lp){
      _list=((ListMgr&)lp).CopyOfSelf();
      MoveToTop();
    }
  }
  void operator++() {MoveToNext();}
  void operator--() {MoveToPrevious();}
};


Class EntityIter


class EntityIter {
  Entity * _entity;
 public:
  EntityIter(){_entity=NULL;}
  EntityIter( const Compound& c){ // All entities of a compound.
    _entity = c.MyPolymers();
  }
  EntityIter( const Entity& e){   // All entities from current entity
    _entity=(Entity*)&e;         // to the last one in an compound object.
  }
  ~EntityIter(){}
  operator const void * () const {return _entity?this:0;}
  Entity& operator() () const {return (*_entity);}
  void operator++(){_entity = _entity->Next();}
  void operator--(){_entity = _entity->Previous();}
};


Class PolyEntityIter


class PolyEntityIter {
  Entity * _entity;
 public:
  PolyEntityIter();
  PolyEntityIter( const Compound&); // All polymer entities.
  PolyEntityIter( const Entity&);   // All polymer entities after (including) 
                                    // current entity.
  ~PolyEntityIter();
  operator const void * () const;
  Entity& operator() () const;
  void operator++();
  void operator--();
};


Class SStrucSEIter


class SStrucSEIter {
  PolyEntityIter _cit;
  SStrucSE * _secondary;
  SSList * _ssList;
public:
  SStrucSEIter():_cit() { _secondary=NULL; _ssList=0; }
  SStrucSEIter(const Compound&);
  SStrucSEIter(const SStrucSE&);
  SStrucSEIter(const Sheet&);
  ~SStrucSEIter(){delete _ssList;}
  operator const void * () const {return _secondary?this:0;}
  SStrucSE& operator() () const {return *_secondary;}
  void operator++();
  void operator--(); 
};


Class SStrucIter


class SStrucIter {
  SStrucSEIter _ssit;
  SStruc * _secondary;
  SSList * _ssList;
public:
  SStrucIter();
  SStrucIter(const Compound&);
  SStrucIter(const SSList&);    // All secondary structures in the list.
  SStrucIter(const SStruc&);    // All secondary structures from the current 
                                // one to the last one in a compound.
  
  ~SStrucIter();
  operator const void * () const;
  SStruc& operator() () const;
  void operator++();
  void operator--();
};


Class SubEntityIter


class SubEntityIter :public ListIter {
  EntityIter _cit;
public:
  SubEntityIter();
  SubEntityIter(const Compound&);     // All subentities of the compound.
  SubEntityIter(const Entity&);       // All subentities of the entity.
  SubEntityIter(const CompSubStruc&); // All subentities of the compound
                                      // sub-structure.
  SubEntityIter(const SubEntity&);    // All subentities from the current 
                                      // subentity to the last one in a 
                                      // compound.
  SubEntityIter(const ListMgr& s); // All subentities in the list.
  void operator++();
  void operator--();
};


Class AltAtomIter


class AltAtomIter {  // Reference to i_atom.h for the implementation of 
                     // alternative atoms.
  ATom * _mainAtom;
  ATom * _atom;
  int _nthAlt;
 public:
  AltAtomIter(){_nthAlt=0; _mainAtom=_atom=NULL;}
  AltAtomIter(const ATom& a){_nthAlt=0;_mainAtom=_atom=(ATom*)&a;}
  operator const void * () const {return _atom ? this : 0;}
  ATom& operator() () const {return *_atom;}
  void operator++(){if (_atom) _atom=_atom->AltAtom();  _nthAlt++;}
  void operator--();
};


Class AtomIter


class AtomIter :public ListIter {
  SubEntityIter _rit;
  int _iterAltAtom;
  int _nthAlt;
 public:
  AtomIter();

  // ********************************************************************
  // The following group of constructors are used to create proper atom
  // set at different level of macromolecule components.  For example,
  // 
  // Compound p1;
  // AtomIter ait(p);
  // 
  // will enpower the iterator to navigate through all atoms of the compound 
  // object. The second parameter is optional, default to be 0. If it is set 
  // to be a non-zero value, all alterative atoms will be included in the Atom 
  // "set", otherwise the alterative atoms are excluded.
  //
  // ***********************************************************************

  AtomIter(const Compound&, int =0);
  AtomIter(const Entity&, int =0);
  AtomIter(const CompSubStruc&, int =0);
  AtomIter(const SubEntity&, int =0);
  AtomIter(const ListMgr&, int =0);
  AtomIter(const SubEntityFilt&, int =0);
  ATom& operator() () const {
    return _nthAlt?*(_element->NthAltAtom(_nthAlt)):*_element;
  }
  void operator++();
  void operator--();
};

Class CompdFilt


class CompdFilt {
  CompdIter _cit;
  Compound * _compound;
  char _id[5];
public:
  CompdFilt( const ListMgr&, char*);
  ~CompdFilt(){}
  operator const void * () const;
  Compound& operator() ();
  void operator++();
};


Class EntityFilt


class EntityFilt {
  EntityIter _cit;
  Entity * _entity;
  int _pos;
  char* _id;
public:
  EntityFilt();
  EntityFilt( const Compound&, char*);
  ~EntityFilt();
  operator const void * () const;
  Entity& operator() ();
  void operator++();
};


Class SStrucFilt


class SStrucFilt {
  SStruc * _secondary;
  SStrucIter _sit;
  char* _id;
public:
  SStrucFilt();
  SStrucFilt( const Compound&, SSTRUCTYPE);
  SStrucFilt( const SStruc&, char*);
  ~SStrucFilt(){}
  operator const void * () const;
  SStruc& operator() ()const ;
  void operator++();
};

Class SubEntityFilt



class SubEntityFilt {

friend class AtomIter;
 
  SubEntityIter _rit;
  SubEntity * _subEntity;
  int _seqNum;
  char* _name;
  char* _insertCode;
 public:
  SubEntityFilt();
  SubEntityFilt( const Entity&, int, char* ='\0');
  SubEntityFilt( const Entity& e, char* name);
  SubEntityFilt( const CompSubStruc& sstruc, char* name);
  ~SubEntityFilt();
  operator const void * () const;
  SubEntity& operator() () ;
  void operator++();
};


Class AtomFilt


class AtomFilt {
  ATom * _atom;
  AtomIter _ait;
  int _no;
  char *_name;
 public:
  AtomFilt();
  AtomFilt( const Compound& protein, int no);
  AtomFilt( const Compound& protein, char* name);
  AtomFilt( const Entity& chain, int no);
  AtomFilt( const Entity& chain, char* name);
  AtomFilt( const SubEntity& subentity, char* name);
  AtomFilt( const SubEntityFilt& subentityfilt, char* name);
  ~AtomFilt();
  operator const void * () const;
  ATom& operator() ();
  void operator++();
};


More on Iterators

Iterators are designed for application programmers who want to inspect different objects' elements at different abstraction levels. By using a proper constructor one can inspect, for example, all atom of a compound, entity, secondary structure, or subentity. Iterators provide 4 basic operators, check for end of the set (i.e. *), retrieve the current element (i.e. ()), advance to the next element (i.e. ++), and back to previous element (i.e. --).

USAGE
Use AtomIter, SubEntityIter, EntityIter, and SStrucSEIter to denote the level
of abstraction you want to inspect.

Use const & SubEntity, & Entity, & SStruc, and & Compound as arguments
to indicate the object you want to inspect.


Example:

// To browse all the atoms of a compound, we can:

Compound p1;
for (AtomIter it(p1); it; ++it) {
        // Atom Iter it(p1)     declare iterator it to look at all atoms in p1
        // ++it                 advance to next element
        // it                   null after reach the end of protein
        // it()                 const & ATom
        cout << it()._name;
}


More on Filters

Filters are designed for application programmer who wants to inspect different objects' elements at different abstraction levels of those element(s) that fit into the criteria as depicted in 2nd argument.

USAGE
Use AtomFilter, SubEntityFilter, EntityFilter, and SStrucFilter to
denote the level of abstraction you want to inspect.

Use const & SubEntity, & Entity, & SStruc, and & Compound as 1 st arguments
to indicate the object you want to inspect.

Use char * or int as 2nd arguments to indicate the criteria, such as name
or no.

Example:

// To browse all the subentitys of a compound that has name of "SYS", we can:

Compound p1;
for ( SubEntityFilter it(p1); it; ++it) {
  // SubEntityFilter it(p1, "SYS")  declare filter it to look at subentitys
  //                                in protein p1 that has name of "SYS"
  // ++it                           advance to next "SYS" element
  // it                             null when no "SYS" left
  // it()                           const & SubEntity



        cout << it()._name;

}


Back to The PDBLib