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

CList.h

Go to the documentation of this file.
00001 /*
00002  * CList.h
00003  * $Id: CList.h,v 1.3 2001/09/28 11:06:08 mjanich 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  */
00022 
00023 //  Description : Definition of the CList class 
00024 //  Purpose     : Managment of class providing the interface to a linked
00025 //                list of objects.
00026 //
00027 //  Updates     :      who       |    date    | what
00028 //                ---------------+------------+-----------------------------
00029 //                               |            |
00030 
00031 #ifndef __CLIST_H
00032 #define __CLIST_H
00033 
00034 
00035 // System
00037 #include <iostream.h>
00038 
00039 // Forward
00040 template <class ObjectType>
00041 class CList;
00042 
00043 
00045 template <class ObjectType> 
00046 class CListContainer
00047 /*************************/
00048 {
00049 public:
00050 
00051   //constructor
00052   CListContainer(ObjectType* pTmp)
00053         : m_pNext(NULL), m_pPrev(NULL), m_pObject(pTmp) {};
00054   
00055   //destructor
00056   ~CListContainer() {};
00057   
00058   //methods
00059   CListContainer* getNext() { return m_pNext; };
00060   CListContainer* getPrev() { return m_pPrev; };
00061 
00062   ObjectType* getObject() { return m_pObject; };
00063 
00064   friend class CList<ObjectType>;
00065 
00066 protected:
00067   //data
00068   CListContainer* m_pNext; 
00069   CListContainer* m_pPrev;
00070 
00071   ObjectType* const m_pObject;
00072 
00073   //methods
00074   void setNext(CListContainer* pTmp) { m_pNext = pTmp; };
00075   void setPrev(CListContainer* pTmp) { m_pPrev = pTmp; };
00076 };
00077 
00078 
00080 
00091 template <class ObjectType>
00092 class CList
00093 /*************************/
00094 {
00095 public:
00096 
00098   CList();
00099 
00101   CList(const CList &cSource);
00102   
00104   ~CList();
00105 
00106   
00109   CListContainer<ObjectType>* getFirst()  const { return m_pFirst; };
00110   
00113   CListContainer<ObjectType>* getLast()  const { return m_pLast; };
00114 
00116   int getNumObjects() const { return m_nNumObjects; };
00117 
00119   int insertAsFirst(ObjectType *pObj);
00120 
00122   int insertAsLast(ObjectType *pObj);
00123 
00126   int insertAfter(CListContainer<ObjectType> *pThere, ObjectType *pObject);
00127 
00131   CListContainer<ObjectType>* find(ObjectType *pObj) const;
00132 
00134   int remove(CListContainer<ObjectType> *pRemove);
00135 
00138   int remove(ObjectType *pObj);
00139 
00143   CList<ObjectType>* getFullDuplicate() const;
00144 
00147   void clear(int nFlag=0);
00148 
00149   /* returns a reference of the object of the i-th container.
00150    * \parNOTE: 'nIndex' starts at 0.*/
00151   ObjectType &operator [](int nIndex) const;
00152 
00153 
00154   /* returns pointer to the i-th container in the list */
00155   CListContainer<ObjectType> *operator()(int nIndex) const;
00156 
00158   const CList &operator+(const CList &cSource);
00159 
00162   CList &operator=(const CList &cSource);
00163 
00164 
00165 
00166 protected:
00167   //data
00168   int m_nNumObjects;
00169 
00170   CListContainer<ObjectType>* m_pFirst; 
00171   CListContainer<ObjectType>* m_pLast;
00172 
00173 
00174     //methods
00175   void init() {
00176     setFirst(NULL);
00177     setLast(NULL);
00178     setNumObjects(0);
00179   };
00180   void setFirst(CListContainer<ObjectType>* pTmp)
00181   { m_pFirst = pTmp; };
00182   void setLast(CListContainer<ObjectType>* pTmp) 
00183   { m_pLast = pTmp; };
00184   void setNumObjects(int nTmp)
00185   { m_nNumObjects = nTmp; };
00186 
00187   void increaseNumObjects()
00188   {
00189     setNumObjects(getNumObjects() + 1);
00190     return;
00191   }
00192   void decreaseNumObjects()
00193   {
00194     setNumObjects(getNumObjects() - 1);
00195     return;
00196   }
00197 };
00198 
00199 
00200 #if defined(__GNUC__) || defined(__WIN32)
00201   #include "CList.cpp"
00202 #endif
00203 
00204 #endif

Generated at Thu Oct 4 17:17:25 2001 for QGLViewer by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001