Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CList.h

Go to the documentation of this file.
00001 /*
00002  * CList.h
00003  * $Id: CList.h,v 1.4 2001/11/15 16:54:51 guenth Exp $
00004  *
00005  * Copyright (C) 1999-2001 Michael Meissner, Markus Janich
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * As a special exception to the GPL, the QGLViewer authors (Markus
00022  * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas
00023  * Woerner) give permission to link this program with Qt (non-)commercial
00024  * edition, and distribute the resulting executable, without including
00025  * the source code for the Qt (non-)commercial edition in the source
00026  * distribution.
00027  *
00028  */
00029 
00030 //  Description : Definition of the CList class 
00031 //  Purpose     : Managment of class providing the interface to a linked
00032 //                list of objects.
00033 //
00034 //  Updates     :      who       |    date    | what
00035 //                ---------------+------------+-----------------------------
00036 //                               |            |
00037 
00038 #ifndef __CLIST_H
00039 #define __CLIST_H
00040 
00041 
00042 // System
00044 #include <iostream.h>
00045 
00046 // Forward
00047 template <class ObjectType>
00048 class CList;
00049 
00050 
00052 template <class ObjectType> 
00053 class CListContainer
00054 /*************************/
00055 {
00056 public:
00057 
00058   //constructor
00059   CListContainer(ObjectType* pTmp)
00060         : m_pNext(NULL), m_pPrev(NULL), m_pObject(pTmp) {};
00061   
00062   //destructor
00063   ~CListContainer() {};
00064   
00065   //methods
00066   CListContainer* getNext() { return m_pNext; };
00067   CListContainer* getPrev() { return m_pPrev; };
00068 
00069   ObjectType* getObject() { return m_pObject; };
00070 
00071   friend class CList<ObjectType>;
00072 
00073 protected:
00074   //data
00075   CListContainer* m_pNext; 
00076   CListContainer* m_pPrev;
00077 
00078   ObjectType* const m_pObject;
00079 
00080   //methods
00081   void setNext(CListContainer* pTmp) { m_pNext = pTmp; };
00082   void setPrev(CListContainer* pTmp) { m_pPrev = pTmp; };
00083 };
00084 
00085 
00087 
00098 template <class ObjectType>
00099 class CList
00100 /*************************/
00101 {
00102 public:
00103 
00105   CList();
00106 
00108   CList(const CList &cSource);
00109   
00111   ~CList();
00112 
00113   
00116   CListContainer<ObjectType>* getFirst()  const { return m_pFirst; };
00117   
00120   CListContainer<ObjectType>* getLast()  const { return m_pLast; };
00121 
00123   int getNumObjects() const { return m_nNumObjects; };
00124 
00126   int insertAsFirst(ObjectType *pObj);
00127 
00129   int insertAsLast(ObjectType *pObj);
00130 
00133   int insertAfter(CListContainer<ObjectType> *pThere, ObjectType *pObject);
00134 
00138   CListContainer<ObjectType>* find(ObjectType *pObj) const;
00139 
00141   int remove(CListContainer<ObjectType> *pRemove);
00142 
00145   int remove(ObjectType *pObj);
00146 
00150   CList<ObjectType>* getFullDuplicate() const;
00151 
00154   void clear(int nFlag=0);
00155 
00156   /* returns a reference of the object of the i-th container.
00157    * \parNOTE: 'nIndex' starts at 0.*/
00158   ObjectType &operator [](int nIndex) const;
00159 
00160 
00161   /* returns pointer to the i-th container in the list */
00162   CListContainer<ObjectType> *operator()(int nIndex) const;
00163 
00165   const CList &operator+(const CList &cSource);
00166 
00169   CList &operator=(const CList &cSource);
00170 
00171 
00172 
00173 protected:
00174   //data
00175   int m_nNumObjects;
00176 
00177   CListContainer<ObjectType>* m_pFirst; 
00178   CListContainer<ObjectType>* m_pLast;
00179 
00180 
00181     //methods
00182   void init() {
00183     setFirst(NULL);
00184     setLast(NULL);
00185     setNumObjects(0);
00186   };
00187   void setFirst(CListContainer<ObjectType>* pTmp)
00188   { m_pFirst = pTmp; };
00189   void setLast(CListContainer<ObjectType>* pTmp) 
00190   { m_pLast = pTmp; };
00191   void setNumObjects(int nTmp)
00192   { m_nNumObjects = nTmp; };
00193 
00194   void increaseNumObjects()
00195   {
00196     setNumObjects(getNumObjects() + 1);
00197     return;
00198   }
00199   void decreaseNumObjects()
00200   {
00201     setNumObjects(getNumObjects() - 1);
00202     return;
00203   }
00204 };
00205 
00206 
00207 #if defined(__GNUC__) || defined(__WIN32)
00208   #include "CList.cpp"
00209 #endif
00210 
00211 #endif

Generated on Wed Mar 5 18:23:25 2003 for QGLViewer by doxygen1.3-rc3