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

/home/jeroen/FOX/fox/fox-1.7.33/include/FXPtrList.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *                            P o i n t e r   L i s t                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXPTRLIST_H
00022 #define FXPTRLIST_H
00023 
00024 namespace FX {
00025 
00027 class FXAPI FXPtrList {
00028 protected:
00029   void **ptr;
00030 public:
00031 
00033   FXPtrList();
00034 
00036   FXPtrList(const FXPtrList& src);
00037 
00039   FXPtrList(void* object);
00040 
00042   FXPtrList(void* object,FXint n);
00043 
00045   FXPtrList(void** objects,FXint n);
00046 
00048   FXPtrList& operator=(const FXPtrList& orig);
00049 
00051   FXint no() const { return *((FXint*)(ptr-1)); }
00052 
00054   FXbool no(FXint num);
00055 
00057   void*& operator[](FXint i){ return ptr[i]; }
00058   void* const& operator[](FXint i) const { return ptr[i]; }
00059 
00061   void*& at(FXint i){ return ptr[i]; }
00062   void* const& at(FXint i) const { return ptr[i]; }
00063 
00065   void*& head(){ return ptr[0]; }
00066   void* const& head() const { return ptr[0]; }
00067 
00069   void*& tail(){ return ptr[no()-1]; }
00070   void* const& tail() const { return ptr[no()-1]; }
00071 
00073   void** data(){ return ptr; }
00074   void *const * data() const { return ptr; }
00075 
00077   void adopt(FXPtrList& orig);
00078 
00080   FXbool assign(void* object);
00081 
00083   FXbool assign(void* object,FXint n);
00084 
00086   FXbool assign(void** objects,FXint n);
00087 
00089   FXbool assign(const FXPtrList& objects);
00090 
00092   FXbool insert(FXint pos,void* object);
00093 
00095   FXbool insert(FXint pos,void* object,FXint n);
00096 
00098   FXbool insert(FXint pos,void** objects,FXint n);
00099 
00101   FXbool insert(FXint pos,const FXPtrList& objects);
00102 
00104   FXbool prepend(void* object);
00105 
00107   FXbool prepend(void* object,FXint n);
00108 
00110   FXbool prepend(void** objects,FXint n);
00111 
00113   FXbool prepend(const FXPtrList& objects);
00114 
00116   FXbool append(void* object);
00117 
00119   FXbool append(void* object,FXint n);
00120 
00122   FXbool append(void** objects,FXint n);
00123 
00125   FXbool append(const FXPtrList& objects);
00126 
00128   FXbool replace(FXint pos,void* object);
00129 
00131   FXbool replace(FXint pos,FXint m,void* object,FXint n);
00132 
00134   FXbool replace(FXint pos,FXint m,void** objects,FXint n);
00135 
00137   FXbool replace(FXint pos,FXint m,const FXPtrList& objects);
00138 
00140   FXbool erase(FXint pos);
00141 
00143   FXbool erase(FXint pos,FXint n);
00144 
00146   FXbool push(void* object);
00147 
00149   FXbool pop();
00150 
00152   FXbool remove(const void* object);
00153 
00155   FXint find(const void *object,FXint pos=0) const;
00156 
00158   FXint rfind(const void *object,FXint pos=2147483647) const;
00159 
00161   void clear();
00162 
00164   virtual ~FXPtrList();
00165   };
00166 
00167 
00168 
00170 template<class TYPE>
00171 class FXPtrListOf : public FXPtrList {
00172 public:
00174   FXPtrListOf(){}
00175 
00177   FXPtrListOf(const FXPtrListOf<TYPE>& src):FXPtrList(src){ }
00178 
00180   FXPtrListOf(TYPE* object):FXPtrList(reinterpret_cast<void*>(object)){ }
00181 
00183   FXPtrListOf(TYPE* object,FXint n):FXPtrList(reinterpret_cast<void*>(object),n){ }
00184 
00186   FXPtrListOf(TYPE** objects,FXint n):FXPtrList(reinterpret_cast<void**>(objects),n){ }
00187 
00189   TYPE*& operator[](FXint i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
00190   TYPE *const& operator[](FXint i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
00191 
00193   TYPE*& at(FXint i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
00194   TYPE *const& at(FXint i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
00195 
00197   TYPE*& head(){ return reinterpret_cast<TYPE*&>(ptr[0]); }
00198   TYPE* const& head() const { return reinterpret_cast<TYPE*const&>(ptr[0]); }
00199 
00201   TYPE*& tail(){ return reinterpret_cast<TYPE*&>(ptr[no()-1]); }
00202   TYPE* const& tail() const { return reinterpret_cast<TYPE* const&>(ptr[no()-1]); }
00203 
00205   TYPE** data(){ return reinterpret_cast<TYPE**>(ptr); }
00206   TYPE *const * data() const { return reinterpret_cast<TYPE*const*>(ptr); }
00207   };
00208 
00209 }
00210 
00211 #endif

Copyright © 1997-2011 Jeroen van der Zijp