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

FXObjectList.h

00001 /******************************************************************************** 00002 * * 00003 * O b j e c t L i s t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2004 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.24 2004/02/08 17:17:34 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; 00037 public: 00038 00039 /// Default constructor 00040 FXObjectList(); 00041 00042 /// Copy constructor 00043 FXObjectList(const FXObjectList& orig); 00044 00045 /// Construct and init with single object 00046 FXObjectList(FXObject* object); 00047 00048 /// Construct and init with list of objects 00049 FXObjectList(FXObject** objects,FXint n); 00050 00051 /// Assignment operator 00052 FXObjectList& operator=(const FXObjectList& orig); 00053 00054 /// Return number of objects 00055 FXint no() const { return *((FXint*)(data-1)); } 00056 00057 /// Set number of objects 00058 void no(FXint num); 00059 00060 /// Indexing operator 00061 FXObject*& operator[](FXint i){ return data[i]; } 00062 FXObject* const& operator[](FXint i) const { return data[i]; } 00063 00064 /// Access to list 00065 FXObject*& list(FXint i){ return data[i]; } 00066 FXObject* const& list(FXint i) const { return data[i]; } 00067 00068 /// Access to content array 00069 FXObject** list() const { return data; } 00070 00071 /// Assign object p to list 00072 FXObjectList& assign(FXObject* object); 00073 00074 /// Assign n objects to list 00075 FXObjectList& assign(FXObject** objects,FXint n); 00076 00077 /// Assign objects to list 00078 FXObjectList& assign(FXObjectList& objects); 00079 00080 /// Insert object at certain position 00081 FXObjectList& insert(FXint pos,FXObject* object); 00082 00083 /// Insert n objects at specified position 00084 FXObjectList& insert(FXint pos,FXObject** objects,FXint n); 00085 00086 /// Insert objects at specified position 00087 FXObjectList& insert(FXint pos,FXObjectList& objects); 00088 00089 /// Prepend object 00090 FXObjectList& prepend(FXObject* object); 00091 00092 /// Prepend n objects 00093 FXObjectList& prepend(FXObject** objects,FXint n); 00094 00095 /// Prepend objects 00096 FXObjectList& prepend(FXObjectList& objects); 00097 00098 /// Append object 00099 FXObjectList& append(FXObject* object); 00100 00101 /// Append n objects 00102 FXObjectList& append(FXObject** objects,FXint n); 00103 00104 /// Append objects 00105 FXObjectList& append(FXObjectList& objects); 00106 00107 /// Replace object at position by given object 00108 FXObjectList& replace(FXint pos,FXObject* object); 00109 00110 /// Replaces the m objects at pos with n objects 00111 FXObjectList& replace(FXint pos,FXint m,FXObject** objects,FXint n); 00112 00113 /// Replace the m objects at pos with objects 00114 FXObjectList& replace(FXint pos,FXint m,FXObjectList& objects); 00115 00116 /// Remove object at pos 00117 FXObjectList& remove(FXint pos,FXint n=1); 00118 00119 /// Remove object 00120 FXObjectList& remove(const FXObject* object); 00121 00122 /// Find object in list, searching forward; return position or -1 00123 FXint find(const FXObject *object,FXint pos=0) const; 00124 00125 /// Find object in list, searching backward; return position or -1 00126 FXint rfind(const FXObject *object,FXint pos=2147483647) const; 00127 00128 /// Remove all objects 00129 FXObjectList& clear(); 00130 00131 /// Save to a stream 00132 void save(FXStream& store) const; 00133 00134 /// Load from a stream 00135 void load(FXStream& store); 00136 00137 /// Destructor 00138 virtual ~FXObjectList(); 00139 }; 00140 00141 00142 /// Specialize list to pointers to TYPE 00143 template<class TYPE> 00144 class FXObjectListOf : public FXObjectList { 00145 public: 00146 FXObjectListOf(){} 00147 00148 /// Indexing operator 00149 TYPE*& operator[](FXint i){ return (TYPE*&)data[i]; } 00150 TYPE *const& operator[](FXint i) const { return (TYPE*const&)data[i]; } 00151 00152 /// Access to list 00153 TYPE*& list(FXint i){ return (TYPE*&)data[i]; } 00154 TYPE *const& list(FXint i) const { return (TYPE*const&)data[i]; } 00155 00156 /// Access to content array 00157 TYPE** list() const { return (TYPE**)data; } 00158 }; 00159 00160 } 00161 00162 #endif

Copyright © 1997-2004 Jeroen van der Zijp