The List Classes


The List Classes are:


Click here to see List Class documentation

Class LinkListElement

template class LinkListElement {
public:
  T *_element;
  LinkListElement * _next;
  LinkListElement(){_element=0; _next=0;}
  LinkListElement(const LinkListElement& e){
    _element=e._element;
    _next=0;
  }
  LinkListElement * Next(){return _next;}
  virtual ~LinkListElement(){};
  // default is not to delete any element. It may be pointed by other list.

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif

};



Class DoubleLinkListElement

template class DoubleLinkListElement :public LinkListElement {
public:
  DoubleLinkListElement * _previous;
  DoubleLinkListElement(){_previous=0;}
  DoubleLinkListElement(DoubleLinkListElement& e):LinkListElement(e){
    _previous=0;
  }
  DoubleLinkListElement * Previous(){return _previous;}
  DoubleLinkListElement * Next(){return (DoubleLinkListElement*)_next;}

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif


};



Class ListMgr

template class ListMgr {
  // friend class MultiLinearListMgr;
  // the following friend need to be change when iterator change to templates.
  
friend class ListIter;

protected:
  T * _element;
  ListMgr(){_element=0;}
  ListMgr(const ListMgr & m){_element=m._element;}
  operator const void * () const { return _element?this:0;}
  T & operator()(){return *_element;}
  virtual void operator++()=0;
  virtual void operator--()=0;
  virtual void ResetToTop()=0;
  virtual void ResetToEnd()=0;
public:

  virtual ListMgr *CopyOfSelf(int =0) const =0;
  virtual ~ListMgr(){};
  virtual void AddElement(T*){}
  virtual T* FindElement(char*){return 0;}
  virtual void DeleteElement(T*){}
  int Exist(T*);

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif


};



Class ArrayListMgr

template class ArrayListMgr : public ListMgr {


protected:
  T ** _array;
  int _numOfElements;
  int _index;
  int _myOwnArray;   // this need futher work.
  void operator++(){
    _element=_index<_numOfElements?_array[++_index]:0;
  }
  void operator--(){
    _element=_index?_array[--_index]:0;
  }
  void ResetToTop(){_element=_array[_index=0];}
  void ResetToEnd(){_element=_array[_index=_numOfElements-1];}
  ArrayListMgr(const ArrayListMgr*);
public:
   ListMgr *CopyOfSelf(int =0) const {return new ArrayListMgr(this);}
  ArrayListMgr(){_array=0; _numOfElements=_index=0; _myOwnArray=0;}
  ArrayListMgr(int i);
  ~ArrayListMgr(){if (_myOwnArray) delete [] _array;}
  void AddElement(T*)=0;
  T* FindElement(char*)=0;
  void DeleteElement(T*)=0;



};




Class LinearListMgr

template class LinearListMgr : public ListMgr{

friend class MultiLinearListMgr;

protected:
  int i;
  T *_head;
  T *_tail;
  void operator++(){
    if (_element && ((_element!=_tail) || (_element=0)))
      _element=(T*)_element->Next();
  }
  void operator--(){
    if (_element && ((_element!=_head) || (_element=0)))
      _element=(T*)_element->Previous();
  }
  void ResetToTop(){_element=_head;}
  void ResetToEnd();
public:

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif

  ListMgr *CopyOfSelf(int =0) const { return new LinearListMgr(this);}
  LinearListMgr(){_head=_tail=0;}
  LinearListMgr(T * a1, T * a2 =0){
    _head=a1;_tail=a2;
  }
  LinearListMgr(const LinearListMgr * l);
  void SetHead(const T& t){_head=(T*)&t;}
  void SetTail(const T& t){_tail=(T*)&t;}
  T* MyHead(){return _head;}
  T* MyTail(){return _tail;}

};



Class NonLinearListMgr

template class NonLinearListMgr :public ListMgr{

protected:
  DoubleLinkListElement *_head, *_current;
  int _myOwnList; // set to 1 if the double link list should
                  // be destroyed by the current manager.
  void operator++(){
    if (_current){
      _current=(DoubleLinkListElement*)_current->Next();
      if (_current) _element=_current->_element;
      else _element=0;
    }
  }
  void operator--(){
    if (_current && _current!=_head){
      _current=_current->_previous;
      _element=_current->_element;
    }
  }
  void ResetToTop(){
    if (_head) {
      _current=_head;
      _element=_current->_element;
    }
  }
  void ResetToEnd();
  
public:

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif

  ListMgr *CopyOfSelf(int =0) const { return new NonLinearListMgr(this);}
  NonLinearListMgr(){_head=_current=0; _myOwnList=1; }
  NonLinearListMgr(const NonLinearListMgr *lp);
  ~NonLinearListMgr();
  void AddElement(T* t); 
  T* FindElement(char* name);
  void DeleteElement(T* t);
  LinkListElement * MyList(){return _head;}
};





Class DLlistElementOfLinearListMgr

template class DLlistElementOfLinearListMgr {

// Element of double link list of LinearListMgr.

public:
  LinearListMgr *_elements;
  DLlistElementOfLinearListMgr *revious;
  DLlistElementOfLinearListMgr *_next;
  DLlistElementOfLinearListMgr(){revious=_next=0;}

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif

};


Class MultiLinearListMgr

template class MultiLinearListMgr : public ListMgr {


protected:

  DLlistElementOfLinearListMgr *_lists, *_currentList;
  void operator++(){
    if (_currentList){
      ++(*(_currentList->_elements));
      _element=&(*(_currentList->_elements))();
      if ((!_element) && (_currentList=_currentList->_next)){
	_currentList->_elements->ResetToTop();
	_element=&(*(_currentList->_elements))();
      }
    }
    else ResetToTop();
  }
  void operator--(){
    if (_currentList){
      --(*(_currentList->_elements));
      _element=&(*(_currentList->_elements))();
      if ((!_element) && 
	  (_currentList=_currentList->revious)){
	_currentList->_elements->ResetToEnd();
	_element=&(*(_currentList->_elements))();
      }
    }
    else ResetToEnd();
  }
  void ResetToTop(){
    if (_lists){
      _currentList=_lists;
      _currentList->_elements->ResetToTop();
      _element=&(*(_currentList->_elements))();
    }
  }
  void ResetToEnd();
public:

#if NEED_OBJECTSTORE
  static os_typespec *get_os_typespec();
#endif

  ListMgr * CopyOfSelf(int =0) const {return new MultiLinearListMgr(this);}
  MultiLinearListMgr(){_lists=_currentList=0;}
  MultiLinearListMgr(const MultiLinearListMgr *l);
  ~MultiLinearListMgr();
  virtual void AddLinearListMgr(LinearListMgr* l);
  void Merge(MultiLinearListMgr*);
  void AddElement(T*){}
  T* FindElement(char*){return 0;}
  void DeleteElement(T*){}


};


Class CollectionListMgr

#if NEED_OBJECTSTORE

class DbsMgr;
enum c_sz { COLL_SIZE=2100 };

template class CollectionListMgr : public ListMgr{

protected:
  os_Collection *_coll;
  os_Cursor *_cursor;

  void operator++();
  void operator--();

  void ResetToTop();
  void ResetToEnd();

  CollectionListMgr(os_Collection *coll);

public:

  static os_typespec *get_os_typespec();

  ListMgr *CopyOfSelf(int order=0) const  { return new CollectionListMgr(this,order);}
  ListMgr *DeepCopyOfSelf();

  CollectionListMgr(int behavior=0,int expected_size=COLL_SIZE);
  CollectionListMgr(const CollectionListMgr *lp,int order=0);
  ~CollectionListMgr();

  void AddElement(T* t); 
  T* FindElement(char* name);
  int MyCardinality() const { if (_coll) return _coll->cardinality(); 
			      else return 0;
			    }
  void AddIndex(char *ix_path, int opt=os_index_path::ordered);
  CollectionListMgr *Query(char *query_str);
  T *QueryPick(char *query_str);
  T *QueryPick(const os_bound_query &bnd_qry);
  CollectionListMgr *Query(const os_bound_query &bnd_qry);
  void DeleteElement(T* t);
};

#endif


Back to The PDBLib