1 /******************************************************************************** 2 * * 3 * O b j e c t L i s t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2005 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or * 9 * modify it under the terms of the GNU Lesser General Public * 10 * License as published by the Free Software Foundation; either * 11 * version 2.1 of the License, or (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 16 * Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public * 19 * License along with this library; if not, write to the Free Software * 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 21 ********************************************************************************* 22 * $Id: FXObjectList.h,v 1.27.2.1 2005/02/11 01:02:47 fox Exp $ * 23 ********************************************************************************/ 24 #ifndef FXOBJECTLIST_H 25 #define FXOBJECTLIST_H 26 27 #ifndef FXOBJECT_H 28 #include "FXObject.h" 29 #endif 30 31 namespace FX { 32 33 /// List of pointers to objects 34 class FXAPI FXObjectList { 35 protected: 36 FXObject **data; 37 public: 38 39 /// Default constructor 40 FXObjectList(); 41 42 /// Copy constructor 43 FXObjectList(const FXObjectList& orig); 44 45 /// Construct and init with single object 46 FXObjectList(FXObject* object); 47 48 /// Construct and init with list of objects 49 FXObjectList(FXObject** objects,FXint n); 50 51 /// Assignment operator 52 FXObjectList& operator=(const FXObjectList& orig); 53 54 /// Return number of objects no()55 FXint no() const { return *((FXint*)(data-1)); } 56 57 /// Set number of objects 58 void no(FXint num); 59 60 /// Indexing operator 61 FXObject*& operator[](FXint i){ return data[i]; } 62 FXObject* const& operator[](FXint i) const { return data[i]; } 63 64 /// Access to list list(FXint i)65 FXObject*& list(FXint i){ return data[i]; } list(FXint i)66 FXObject* const& list(FXint i) const { return data[i]; } 67 68 /// Access to content array list()69 FXObject** list() const { return data; } 70 71 /// Assign object p to list 72 FXObjectList& assign(FXObject* object); 73 74 /// Assign n objects to list 75 FXObjectList& assign(FXObject** objects,FXint n); 76 77 /// Assign objects to list 78 FXObjectList& assign(FXObjectList& objects); 79 80 /// Insert object at certain position 81 FXObjectList& insert(FXint pos,FXObject* object); 82 83 /// Insert n objects at specified position 84 FXObjectList& insert(FXint pos,FXObject** objects,FXint n); 85 86 /// Insert objects at specified position 87 FXObjectList& insert(FXint pos,FXObjectList& objects); 88 89 /// Prepend object 90 FXObjectList& prepend(FXObject* object); 91 92 /// Prepend n objects 93 FXObjectList& prepend(FXObject** objects,FXint n); 94 95 /// Prepend objects 96 FXObjectList& prepend(FXObjectList& objects); 97 98 /// Append object 99 FXObjectList& append(FXObject* object); 100 101 /// Append n objects 102 FXObjectList& append(FXObject** objects,FXint n); 103 104 /// Append objects 105 FXObjectList& append(FXObjectList& objects); 106 107 /// Replace object at position by given object 108 FXObjectList& replace(FXint pos,FXObject* object); 109 110 /// Replaces the m objects at pos with n objects 111 FXObjectList& replace(FXint pos,FXint m,FXObject** objects,FXint n); 112 113 /// Replace the m objects at pos with objects 114 FXObjectList& replace(FXint pos,FXint m,FXObjectList& objects); 115 116 /// Remove object at pos 117 FXObjectList& remove(FXint pos,FXint n=1); 118 119 /// Remove object 120 FXObjectList& remove(const FXObject* object); 121 122 /// Find object in list, searching forward; return position or -1 123 FXint find(const FXObject *object,FXint pos=0) const; 124 125 /// Find object in list, searching backward; return position or -1 126 FXint rfind(const FXObject *object,FXint pos=2147483647) const; 127 128 /// Remove all objects 129 FXObjectList& clear(); 130 131 /// Save to a stream 132 void save(FXStream& store) const; 133 134 /// Load from a stream 135 void load(FXStream& store); 136 137 /// Destructor 138 virtual ~FXObjectList(); 139 }; 140 141 142 /// Specialize list to pointers to TYPE 143 template<class TYPE> 144 class FXAPI FXObjectListOf : public FXObjectList { 145 public: FXObjectListOf()146 FXObjectListOf(){} 147 148 /// Indexing operator 149 TYPE*& operator[](FXint i){ return (TYPE*&)data[i]; } 150 TYPE *const& operator[](FXint i) const { return (TYPE*const&)data[i]; } 151 152 /// Access to list list(FXint i)153 TYPE*& list(FXint i){ return (TYPE*&)data[i]; } list(FXint i)154 TYPE *const& list(FXint i) const { return (TYPE*const&)data[i]; } 155 156 /// Access to content array list()157 TYPE** list() const { return (TYPE**)data; } 158 }; 159 160 } 161 162 #endif 163