1 /******************************************************************************** 2 * * 3 * O b j e c t L i s t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2006 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.31.2.1 2007/01/29 20:22:29 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 **ptr; 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*)(ptr-1)); } 56 57 /// Set number of objects 58 void no(FXint num); 59 60 /// Indexing operator 61 FXObject*& operator[](FXint i){ return ptr[i]; } 62 FXObject* const& operator[](FXint i) const { return ptr[i]; } 63 64 /// Indexing operator at(FXint i)65 FXObject*& at(FXint i){ return ptr[i]; } at(FXint i)66 FXObject* const& at(FXint i) const { return ptr[i]; } 67 68 /// Access to content array data()69 FXObject** data() const { return ptr; } 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& erase(FXint pos); 118 119 /// Remove n objects at pos 120 FXObjectList& erase(FXint pos,FXint n); 121 122 /// Remove object 123 FXObjectList& remove(const FXObject* object); 124 125 /// Find object in list, searching forward; return position or -1 126 FXint find(const FXObject *object,FXint pos=0) const; 127 128 /// Find object in list, searching backward; return position or -1 129 FXint rfind(const FXObject *object,FXint pos=2147483647) const; 130 131 /// Remove all objects 132 FXObjectList& clear(); 133 134 /// Save to a stream 135 void save(FXStream& store) const; 136 137 /// Load from a stream 138 void load(FXStream& store); 139 140 /// Destructor 141 virtual ~FXObjectList(); 142 }; 143 144 145 /// Specialize list to pointers to TYPE 146 template<class TYPE> 147 class FXObjectListOf : public FXObjectList { 148 public: FXObjectListOf()149 FXObjectListOf(){} 150 151 /// Indexing operator 152 TYPE*& operator[](FXint i){ return (TYPE*&)ptr[i]; } 153 TYPE *const& operator[](FXint i) const { return (TYPE*const&)ptr[i]; } 154 155 /// Access to list at(FXint i)156 TYPE*& at(FXint i){ return (TYPE*&)ptr[i]; } at(FXint i)157 TYPE *const& at(FXint i) const { return (TYPE*const&)ptr[i]; } 158 159 /// Access to content array data()160 TYPE** data() const { return (TYPE**)ptr; } 161 }; 162 163 } 164 165 #endif 166