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

CList.h

Go to the documentation of this file.
00001 /*
00002  * CList.h
00003  * $Id: CList.h,v 1.5 2003/06/24 14:50:02 anxo 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 #if _MSC_VER >= 1300
00045 #include <iostream>
00046 #else
00047 #include <iostream.h>
00048 #endif
00049 
00050 
00051 // Forward
00052 template <class ObjectType>
00053 class CList;
00054 
00055 
00057 template <class ObjectType> 
00058 class CListContainer
00059 /*************************/
00060 {
00061 public:
00062 
00063   //constructor
00064   CListContainer(ObjectType* pTmp)
00065         : m_pNext(NULL), m_pPrev(NULL), m_pObject(pTmp) {};
00066   
00067   //destructor
00068   ~CListContainer() {};
00069   
00070   //methods
00071   CListContainer* getNext() { return m_pNext; };
00072   CListContainer* getPrev() { return m_pPrev; };
00073 
00074   ObjectType* getObject() { return m_pObject; };
00075 
00076   friend class CList<ObjectType>;
00077 
00078 protected:
00079   //data
00080   CListContainer* m_pNext; 
00081   CListContainer* m_pPrev;
00082 
00083   ObjectType* const m_pObject;
00084 
00085   //methods
00086   void setNext(CListContainer* pTmp) { m_pNext = pTmp; };
00087   void setPrev(CListContainer* pTmp) { m_pPrev = pTmp; };
00088 };
00089 
00090 
00092 
00103 template <class ObjectType>
00104 class CList
00105 /*************************/
00106 {
00107 public:
00108 
00110   CList();
00111 
00113   CList(const CList &cSource);
00114   
00116   ~CList();
00117 
00118   
00121   CListContainer<ObjectType>* getFirst()  const { return m_pFirst; };
00122   
00125   CListContainer<ObjectType>* getLast()  const { return m_pLast; };
00126 
00128   int getNumObjects() const { return m_nNumObjects; };
00129 
00131   int insertAsFirst(ObjectType *pObj);
00132 
00134   int insertAsLast(ObjectType *pObj);
00135 
00138   int insertAfter(CListContainer<ObjectType> *pThere, ObjectType *pObject);
00139 
00143   CListContainer<ObjectType>* find(ObjectType *pObj) const;
00144 
00146   int remove(CListContainer<ObjectType> *pRemove);
00147 
00150   int remove(ObjectType *pObj);
00151 
00155   CList<ObjectType>* getFullDuplicate() const;
00156 
00159   void clear(int nFlag=0);
00160 
00161   /* returns a reference of the object of the i-th container.
00162    * \parNOTE: 'nIndex' starts at 0.*/
00163   ObjectType &operator [](int nIndex) const;
00164 
00165 
00166   /* returns pointer to the i-th container in the list */
00167   CListContainer<ObjectType> *operator()(int nIndex) const;
00168 
00170   const CList &operator+(const CList &cSource);
00171 
00174   CList &operator=(const CList &cSource);
00175 
00176 
00177 
00178 protected:
00179   //data
00180   int m_nNumObjects;
00181 
00182   CListContainer<ObjectType>* m_pFirst; 
00183   CListContainer<ObjectType>* m_pLast;
00184 
00185 
00186     //methods
00187   void init() {
00188     setFirst(NULL);
00189     setLast(NULL);
00190     setNumObjects(0);
00191   };
00192   void setFirst(CListContainer<ObjectType>* pTmp)
00193   { m_pFirst = pTmp; };
00194   void setLast(CListContainer<ObjectType>* pTmp) 
00195   { m_pLast = pTmp; };
00196   void setNumObjects(int nTmp)
00197   { m_nNumObjects = nTmp; };
00198 
00199   void increaseNumObjects()
00200   {
00201     setNumObjects(getNumObjects() + 1);
00202     return;
00203   }
00204   void decreaseNumObjects()
00205   {
00206     setNumObjects(getNumObjects() - 1);
00207     return;
00208   }
00209 };
00210 
00211 
00212 #if defined(__GNUC__)
00213   #include "CList.cpp"
00214 #endif
00215 
00216 #endif

Generated on Tue Oct 21 02:54:53 2003 for QGLViewer by doxygen 1.3.4