//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "cellList.h" //--------------------------------------------------------------------------- #pragma package(smart_init) // TNode pCell TNode::content() { return pCellContent; }; pNode TNode::getNext() { return pNodeNext; }; void TNode::setNext(pNode pa) { pNodeNext=pa; }; TNode::TNode (pCell pa) { pCellContent=pa; pNodeNext=NULL; }; TNode::~TNode() { if (pNodeNext!=NULL) delete pNodeNext; pNodeNext=NULL; }; void TNode::destroyContent() { if (pCellContent!=NULL) delete pCellContent; pCellContent=NULL; }; // TCellList void TCellList::setFirst() { pNodeActual=pNodeFirst; }; bool TCellList::goNext() // 0-end of list,set to 1.; 1-succes { if (pNodeActual==NULL) return 0; if (pNodeActual->getNext()==NULL) { setFirst(); return 0; }; pNodeActual=pNodeActual->getNext(); return 1; }; pCell TCellList::actual() { assert(pNodeActual!=NULL); return pNodeActual->content(); }; void TCellList::Add(pCell pa) { assert(pa!=NULL); if (pNodeFirst == NULL) { pNodeFirst=new TNode(pa); pNodeLast=pNodeActual=pNodeFirst; } else { assert (pNodeLast!=NULL); pNodeLast->setNext (new TNode (pa)); pNodeLast=pNodeLast->getNext(); }; count++; }; TCellList::TCellList() { pNodeActual=pNodeFirst=pNodeLast=NULL; count=0; }; TCellList::~TCellList() { if (pNodeFirst!=NULL) delete pNodeFirst; pNodeActual=pNodeFirst=pNodeLast=NULL; count=0; }; void TCellList::destroyContent() { if (pNodeFirst==NULL) return; pNode pa=pNodeFirst; while (pa!=NULL) { pa->destroyContent(); pa=pa->getNext(); }; }; void TCellList::destroyList() { if (pNodeFirst!=NULL) delete pNodeFirst; pNodeFirst=pNodeLast=pNodeActual=NULL; count=0; }; bool TCellList::isEmpty() { return (pNodeFirst==NULL); }; void * TCellList::forEach(cellMem1par f, void* p) { if (isEmpty()) return NULL; assert(pNodeFirst!=NULL); setFirst(); do { assert(pNodeActual!=NULL); assert(pNodeActual->content()!=NULL); (pNodeActual->content()->*f)(p); } while(goNext()); setFirst(); return p; };