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,2006 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.31 2006/02/07 01:17:26 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 **ptr; 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*)(ptr-1)); } 00056 00057 /// Set number of objects 00058 void no(FXint num); 00059 00060 /// Indexing operator 00061 FXObject*& operator[](FXint i){ return ptr[i]; } 00062 FXObject* const& operator[](FXint i) const { return ptr[i]; } 00063 00064 /// Indexing operator 00065 FXObject*& at(FXint i){ return ptr[i]; } 00066 FXObject* const& at(FXint i) const { return ptr[i]; } 00067 00068 /// Access to content array 00069 FXObject** data() const { return ptr; } 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& erase(FXint pos); 00118 00119 /// Remove n objects at pos 00120 FXObjectList& erase(FXint pos,FXint n); 00121 00122 /// Remove object 00123 FXObjectList& remove(const FXObject* object); 00124 00125 /// Find object in list, searching forward; return position or -1 00126 FXint find(const FXObject *object,FXint pos=0) const; 00127 00128 /// Find object in list, searching backward; return position or -1 00129 FXint rfind(const FXObject *object,FXint pos=2147483647) const; 00130 00131 /// Remove all objects 00132 FXObjectList& clear(); 00133 00134 /// Save to a stream 00135 void save(FXStream& store) const; 00136 00137 /// Load from a stream 00138 void load(FXStream& store); 00139 00140 /// Destructor 00141 virtual ~FXObjectList(); 00142 }; 00143 00144 00145 /// Specialize list to pointers to TYPE 00146 template<class TYPE> 00147 class FXAPI FXObjectListOf : public FXObjectList { 00148 public: 00149 FXObjectListOf(){} 00150 00151 /// Indexing operator 00152 TYPE*& operator[](FXint i){ return (TYPE*&)ptr[i]; } 00153 TYPE *const& operator[](FXint i) const { return (TYPE*const&)ptr[i]; } 00154 00155 /// Access to list 00156 TYPE*& at(FXint i){ return (TYPE*&)ptr[i]; } 00157 TYPE *const& at(FXint i) const { return (TYPE*const&)ptr[i]; } 00158 00159 /// Access to content array 00160 TYPE** data() const { return (TYPE**)ptr; } 00161 }; 00162 00163 } 00164 00165 #endif
Copyright © 1997-2005 Jeroen van der Zijp |