![]() |
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,2009 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 * $Id: FXObjectList.h,v 1.42 2009/01/06 13:07:26 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXOBJECTLIST_H 00024 #define FXOBJECTLIST_H 00025 00026 #ifndef FXOBJECT_H 00027 #include "FXObject.h" 00028 #endif 00029 00030 namespace FX { 00031 00032 /// List of pointers to objects 00033 class FXAPI FXObjectList { 00034 protected: 00035 FXObject **ptr; 00036 public: 00037 00038 /// Default constructor 00039 FXObjectList(); 00040 00041 /// Copy constructor 00042 FXObjectList(const FXObjectList& src); 00043 00044 /// Construct and init with single object 00045 FXObjectList(FXObject* object); 00046 00047 /// Construct and init with n copies of object 00048 FXObjectList(FXObject* objects,FXint n); 00049 00050 /// Construct and init with list of objects 00051 FXObjectList(FXObject** objects,FXint n); 00052 00053 /// Assignment operator 00054 FXObjectList& operator=(const FXObjectList& orig); 00055 00056 /// Return number of objects 00057 FXint no() const { return *((FXint*)(ptr-1)); } 00058 00059 /// Set number of objects 00060 FXbool no(FXint num); 00061 00062 /// Indexing operator 00063 FXObject*& operator[](FXint i){ return ptr[i]; } 00064 FXObject* const& operator[](FXint i) const { return ptr[i]; } 00065 00066 /// Indexing operator 00067 FXObject*& at(FXint i){ return ptr[i]; } 00068 FXObject* const& at(FXint i) const { return ptr[i]; } 00069 00070 /// First element in list 00071 FXObject*& head(){ return ptr[0]; } 00072 FXObject* const& head() const { return ptr[0]; } 00073 00074 /// Last element in list 00075 FXObject*& tail(){ return ptr[no()-1]; } 00076 FXObject* const& tail() const { return ptr[no()-1]; } 00077 00078 /// Access to content array 00079 FXObject** data() const { return ptr; } 00080 00081 /// Adopt objects from orig, leaving orig empty 00082 FXObjectList& adopt(FXObjectList& orig); 00083 00084 /// Assign object to list 00085 FXObjectList& assign(FXObject* object); 00086 00087 /// Assign n copies of object to list 00088 FXObjectList& assign(FXObject* object,FXint n); 00089 00090 /// Assign n objects to list 00091 FXObjectList& assign(FXObject** objects,FXint n); 00092 00093 /// Assign objects to list 00094 FXObjectList& assign(FXObjectList& objects); 00095 00096 /// Insert object at certain position 00097 FXObjectList& insert(FXint pos,FXObject* object); 00098 00099 /// Insert n copies of object at specified position 00100 FXObjectList& insert(FXint pos,FXObject* object,FXint n); 00101 00102 /// Insert n objects at specified position 00103 FXObjectList& insert(FXint pos,FXObject** objects,FXint n); 00104 00105 /// Insert objects at specified position 00106 FXObjectList& insert(FXint pos,FXObjectList& objects); 00107 00108 /// Prepend object 00109 FXObjectList& prepend(FXObject* object); 00110 00111 /// Prepend n copies of object 00112 FXObjectList& prepend(FXObject* object,FXint n); 00113 00114 /// Prepend n objects 00115 FXObjectList& prepend(FXObject** objects,FXint n); 00116 00117 /// Prepend objects 00118 FXObjectList& prepend(FXObjectList& objects); 00119 00120 /// Append object 00121 FXObjectList& append(FXObject* object); 00122 00123 /// Append n copies of object 00124 FXObjectList& append(FXObject* object,FXint n); 00125 00126 /// Append n objects 00127 FXObjectList& append(FXObject** objects,FXint n); 00128 00129 /// Append objects 00130 FXObjectList& append(FXObjectList& objects); 00131 00132 /// Replace object at position by given object 00133 FXObjectList& replace(FXint pos,FXObject* object); 00134 00135 /// Replaces the m objects at pos with n objects 00136 FXObjectList& replace(FXint pos,FXint m,FXObject** objects,FXint n); 00137 00138 /// Replaces the m objects at pos with n copies of object 00139 FXObjectList& replace(FXint pos,FXint m,FXObject* object,FXint n); 00140 00141 /// Replace the m objects at pos with objects 00142 FXObjectList& replace(FXint pos,FXint m,FXObjectList& objects); 00143 00144 /// Remove object at pos 00145 FXObjectList& erase(FXint pos); 00146 00147 /// Remove n objects at pos 00148 FXObjectList& erase(FXint pos,FXint n); 00149 00150 /// Push object to end 00151 FXObjectList& push(FXObject* object); 00152 00153 /// Pop object from end 00154 FXObjectList& pop(); 00155 00156 /// Remove object 00157 FXObjectList& remove(const FXObject* object); 00158 00159 /// Find object in list, searching forward; return position or -1 00160 FXint find(const FXObject *object,FXint pos=0) const; 00161 00162 /// Find object in list, searching backward; return position or -1 00163 FXint rfind(const FXObject *object,FXint pos=2147483647) const; 00164 00165 /// Remove all objects 00166 FXObjectList& clear(); 00167 00168 /// Save to a stream 00169 void save(FXStream& store) const; 00170 00171 /// Load from a stream 00172 void load(FXStream& store); 00173 00174 /// Destructor 00175 virtual ~FXObjectList(); 00176 }; 00177 00178 00179 /// Specialize list to pointers to TYPE 00180 template<class TYPE> 00181 class FXObjectListOf : public FXObjectList { 00182 public: 00183 FXObjectListOf(){} 00184 00185 /// Indexing operator 00186 TYPE*& operator[](FXint i){ return (TYPE*&)ptr[i]; } 00187 TYPE *const& operator[](FXint i) const { return (TYPE*const&)ptr[i]; } 00188 00189 /// Access to list 00190 TYPE*& at(FXint i){ return (TYPE*&)ptr[i]; } 00191 TYPE *const& at(FXint i) const { return (TYPE*const&)ptr[i]; } 00192 00193 /// First element in list 00194 TYPE*& head(){ return (TYPE*&)ptr[0]; } 00195 TYPE* const& head() const { return (TYPE*const&)ptr[0]; } 00196 00197 /// Last element in list 00198 TYPE*& tail(){ return (TYPE*&)ptr[no()-1]; } 00199 TYPE* const& tail() const { return (TYPE*const&)ptr[no()-1]; } 00200 00201 /// Access to content array 00202 TYPE** data() const { return (TYPE**)ptr; } 00203 }; 00204 00205 } 00206 00207 #endif
![]() |