![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * O b j e c t L i s t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2002 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (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 GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXObjectList.h,v 1.20 2002/09/19 18:23:10 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXOBJECTLIST_H 00025 #define FXOBJECTLIST_H 00026 00027 #ifndef FXOBJECT_H 00028 #include "FXObject.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 /// List of pointers to objects 00034 class FXAPI FXObjectList { 00035 protected: 00036 FXObject **data; /// List of items 00037 FXint num; /// Used slots 00038 FXint max; /// Total slots 00039 public: 00040 00041 /// Default constructor 00042 FXObjectList(); 00043 00044 /// Copy constructor 00045 FXObjectList(const FXObjectList& orig); 00046 00047 /// Assignment operator 00048 FXObjectList& operator=(const FXObjectList& orig); 00049 00050 /// Return number of elements 00051 FXint no() const { return num; } 00052 00053 /// Set number of elements 00054 void no(FXint n); 00055 00056 /// Return size of list 00057 FXint size() const { return max; } 00058 00059 /// Set max number of elements 00060 void size(FXint m); 00061 00062 /// Indexing operator 00063 FXObject*& operator[](FXint i){ return data[i]; } 00064 FXObject* const& operator[](FXint i) const { return data[i]; } 00065 00066 /// Access to list 00067 FXObject*& list(FXint i){ return data[i]; } 00068 FXObject* const& list(FXint i) const { return data[i]; } 00069 00070 /// Access to content array 00071 FXObject** list() const { return data; } 00072 00073 /// Insert element at certain position 00074 void insert(FXint pos,FXObject* p); 00075 00076 /// Prepend element 00077 void prepend(FXObject* p); 00078 00079 /// Append element 00080 void append(FXObject* p); 00081 00082 /// Replace element 00083 void replace(FXint pos,FXObject* p); 00084 00085 /// Remove element at pos 00086 void remove(FXint pos); 00087 00088 /// Remove element p 00089 void remove(const FXObject* p); 00090 00091 /// Find object in list, searching forward; return position or -1 00092 FXint find(const FXObject *p,FXint pos=0) const; 00093 00094 /// Find object in list, searching backward; return position or -1 00095 FXint rfind(const FXObject *p,FXint pos=2147483647) const; 00096 00097 /// Remove all elements 00098 void clear(); 00099 00100 /// Save to a stream 00101 void save(FXStream& store) const; 00102 00103 /// Load from a stream 00104 void load(FXStream& store); 00105 00106 /// Destructor 00107 virtual ~FXObjectList(); 00108 }; 00109 00110 00111 /// Specialize list to pointers to TYPE 00112 template<class TYPE> 00113 class FXObjectListOf : public FXObjectList { 00114 public: 00115 FXObjectListOf(){} 00116 00117 /// Indexing operator 00118 TYPE*& operator[](FXint i){ return (TYPE*&)data[i]; } 00119 TYPE *const& operator[](FXint i) const { return (TYPE*const&)data[i]; } 00120 00121 /// Access to list 00122 TYPE*& list(FXint i){ return (TYPE*&)data[i]; } 00123 TYPE *const& list(FXint i) const { return (TYPE*const&)data[i]; } 00124 00125 /// Access to content array 00126 TYPE** list() const { return (TYPE**)data; } 00127 }; 00128 00129 } 00130 00131 #endif