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

FXObjectList.h
1 /********************************************************************************
2 * *
3 * O b j e c t L i s t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXOBJECTLIST_H
22 #define FXOBJECTLIST_H
23 
24 #ifndef FXOBJECT_H
25 #include "FXObject.h"
26 #endif
27 
28 namespace FX {
29 
30 
32 class FXAPI FXObjectList {
33 protected:
34  FXObject **ptr;
35 public:
36 
38  FXObjectList();
39 
41  FXObjectList(const FXObjectList& other);
42 
44  FXObjectList(FXObject* object);
45 
47  FXObjectList(FXObject* object,FXival n);
48 
50  FXObjectList(FXObject** objects,FXival n);
51 
53  FXObjectList& operator=(const FXObjectList& other);
54 
56  FXObjectList& adopt(FXObjectList& other);
57 
59  FXival no() const { return *((FXival*)(ptr-1)); }
60 
62  FXbool no(FXival num);
63 
65  FXObject*& operator[](FXival i){ return ptr[i]; }
66  FXObject* const& operator[](FXival i) const { return ptr[i]; }
67 
69  FXObject*& at(FXival i){ return ptr[i]; }
70  FXObject* const& at(FXival i) const { return ptr[i]; }
71 
73  FXObject*& head(){ return ptr[0]; }
74  FXObject* const& head() const { return ptr[0]; }
75 
77  FXObject*& tail(){ return ptr[no()-1]; }
78  FXObject* const& tail() const { return ptr[no()-1]; }
79 
81  FXObject** data(){ return ptr; }
82  FXObject *const * data() const { return ptr; }
83 
85  FXival find(const FXObject *object,FXival pos=0) const;
86 
88  FXival rfind(const FXObject *object,FXival pos=2147483647) const;
89 
91  FXbool assign(FXObject* object);
92 
94  FXbool assign(FXObject* object,FXival n);
95 
97  FXbool assign(FXObject** objects,FXival n);
98 
100  FXbool assign(const FXObjectList& objects);
101 
103  FXbool insert(FXival pos,FXObject* object);
104 
106  FXbool insert(FXival pos,FXObject* object,FXival n);
107 
109  FXbool insert(FXival pos,FXObject** objects,FXival n);
110 
112  FXbool insert(FXival pos,const FXObjectList& objects);
113 
115  FXbool prepend(FXObject* object);
116 
118  FXbool prepend(FXObject* object,FXival n);
119 
121  FXbool prepend(FXObject** objects,FXival n);
122 
124  FXbool prepend(const FXObjectList& objects);
125 
127  FXbool append(FXObject* object);
128 
130  FXbool append(FXObject* object,FXival n);
131 
133  FXbool append(FXObject** objects,FXival n);
134 
136  FXbool append(const FXObjectList& objects);
137 
139  FXbool replace(FXival pos,FXObject* object);
140 
142  FXbool replace(FXival pos,FXival m,FXObject* object,FXival n);
143 
145  FXbool replace(FXival pos,FXival m,FXObject** objects,FXival n);
146 
148  FXbool replace(FXival pos,FXival m,const FXObjectList& objects);
149 
151  FXbool erase(FXival pos);
152 
154  FXbool erase(FXival pos,FXival n);
155 
157  FXbool remove(const FXObject* object);
158 
160  FXbool push(FXObject* object);
161 
163  FXbool pop();
164 
166  FXbool clear();
167 
169  void save(FXStream& store) const;
170 
172  void load(FXStream& store);
173 
175  ~FXObjectList();
176  };
177 
178 
180 template<typename TYPE>
181 class FXObjectListOf : public FXObjectList {
182 public:
183 
186 
189 
191  FXObjectListOf(TYPE* object):FXObjectList(object){ }
192 
194  FXObjectListOf(TYPE* object,FXival n):FXObjectList(object,n){ }
195 
197  FXObjectListOf(TYPE** objects,FXival n):FXObjectList(objects,n){ }
198 
201 
204 
206  TYPE*& operator[](FXival i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
207  TYPE *const& operator[](FXival i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
208 
210  TYPE*& at(FXival i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
211  TYPE *const& at(FXival i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
212 
214  TYPE*& head(){ return reinterpret_cast<TYPE*&>(ptr[0]); }
215  TYPE* const& head() const { return reinterpret_cast<TYPE*const&>(ptr[0]); }
216 
218  TYPE*& tail(){ return reinterpret_cast<TYPE*&>(ptr[no()-1]); }
219  TYPE* const& tail() const { return reinterpret_cast<TYPE* const&>(ptr[no()-1]); }
220 
222  TYPE** data(){ return reinterpret_cast<TYPE**>(ptr); }
223  TYPE *const * data() const { return reinterpret_cast<TYPE*const*>(ptr); }
224 
226  FXival find(TYPE* object,FXival pos=0) const { return FXObjectList::find(object,pos); }
227 
229  FXival rfind(TYPE* object,FXival pos=2147483647) const { return FXObjectList::rfind(object,pos); }
230 
232  FXbool assign(TYPE* object){ return FXObjectList::assign(object); }
233 
235  FXbool assign(TYPE* object,FXival n){ return FXObjectList::assign(object,n); }
236 
238  FXbool assign(TYPE** objects,FXival n){ return FXObjectList::assign(objects,n); }
239 
241  FXbool assign(const FXObjectListOf<TYPE>& objects){ return FXObjectList::assign(objects); }
242 
244  FXbool insert(FXival pos,TYPE* object){ return FXObjectList::insert(pos,object); }
245 
247  FXbool insert(FXival pos,TYPE* object,FXival n){ return FXObjectList::insert(pos,object,n); }
248 
250  FXbool insert(FXival pos,TYPE** objects,FXival n){ return FXObjectList::insert(pos,objects,n); }
251 
253  FXbool insert(FXival pos,const FXObjectListOf<TYPE>& objects){ return FXObjectList::insert(pos,objects); }
254 
256  FXbool prepend(TYPE* object){ return FXObjectList::prepend(object); }
257 
259  FXbool prepend(TYPE* object,FXival n){ return FXObjectList::prepend(object,n); }
260 
262  FXbool prepend(TYPE** objects,FXival n){ return FXObjectList::prepend(objects,n); }
263 
265  FXbool prepend(const FXObjectListOf<TYPE>& objects){ return FXObjectList::prepend(objects); }
266 
268  FXbool append(TYPE* object){ return FXObjectList::append(object); }
269 
271  FXbool append(TYPE* object,FXival n){ return FXObjectList::append(object,n); }
272 
274  FXbool append(TYPE** objects,FXival n){ return FXObjectList::append(objects,n); }
275 
277  FXbool append(const FXObjectListOf<TYPE>& objects){ return FXObjectList::append(objects); }
278 
280  FXbool replace(FXival pos,TYPE* object){ return FXObjectList::replace(pos,object); }
281 
283  FXbool replace(FXival pos,FXival m,TYPE* object,FXival n){ return FXObjectList::replace(pos,m,object,n); }
284 
286  FXbool replace(FXival pos,FXival m,TYPE** objects,FXival n){ return FXObjectList::replace(pos,m,objects,n); }
287 
289  FXbool replace(FXival pos,FXival m,const FXObjectListOf<TYPE>& objects){ return FXObjectList::replace(pos,m,objects); }
290 
292  FXbool remove(TYPE* object){ return FXObjectList::remove(object); }
293 
295  FXbool push(TYPE* object){ return FXObjectList::push(object); }
296  };
297 
298 }
299 
300 #endif
FXObjectListOf(TYPE *object)
Construct and init with single object.
Definition: FXObjectList.h:191
FXbool remove(const FXObject *object)
Remove object.
TYPE *& operator[](FXival i)
Indexing operator.
Definition: FXObjectList.h:206
FXbool prepend(TYPE *object, FXival n)
Prepend n copies of object.
Definition: FXObjectList.h:259
FXbool replace(FXival pos, TYPE *object)
Replace object at position by given object.
Definition: FXObjectList.h:280
FXbool append(FXObject *object)
Append object.
FXObject *& at(FXival i)
Indexing operator.
Definition: FXObjectList.h:69
FXival find(TYPE *object, FXival pos=0) const
Find object in list, searching forward; return position or -1.
Definition: FXObjectList.h:226
FXival rfind(const FXObject *object, FXival pos=2147483647) const
Find object in list, searching backward; return position or -1.
FXObject *& operator[](FXival i)
Indexing operator.
Definition: FXObjectList.h:65
FXival find(const FXObject *object, FXival pos=0) const
Find object in list, searching forward; return position or -1.
FXObjectList & adopt(FXObjectList &other)
Adopt objects from other, leaving other empty.
TYPE *& at(FXival i)
Indexing operator.
Definition: FXObjectList.h:210
FXival rfind(TYPE *object, FXival pos=2147483647) const
Find object in list, searching backward; return position or -1.
Definition: FXObjectList.h:229
TYPE ** data()
Access to content array.
Definition: FXObjectList.h:222
FXbool append(TYPE *object, FXival n)
Append n copies of object.
Definition: FXObjectList.h:271
List of pointers to objects.
Definition: FXObjectList.h:32
FXbool insert(FXival pos, TYPE *object)
Insert object at certain position.
Definition: FXObjectList.h:244
FXbool prepend(TYPE *object)
Prepend object.
Definition: FXObjectList.h:256
FXObjectListOf< TYPE > & adopt(FXObjectListOf< TYPE > &src)
Adopt objects from src, leaving src empty.
Definition: FXObjectList.h:203
FXbool insert(FXival pos, TYPE **objects, FXival n)
Insert n objects at specified position.
Definition: FXObjectList.h:250
FXObjectListOf(TYPE **objects, FXival n)
Construct and init with list of objects.
Definition: FXObjectList.h:197
FXbool insert(FXival pos, FXObject *object)
Insert object at certain position.
FXbool prepend(TYPE **objects, FXival n)
Prepend n objects.
Definition: FXObjectList.h:262
FXbool replace(FXival pos, FXival m, TYPE **objects, FXival n)
Replaces the m objects at pos with n objects.
Definition: FXObjectList.h:286
FXbool assign(const FXObjectListOf< TYPE > &objects)
Assign objects to list.
Definition: FXObjectList.h:241
FXbool replace(FXival pos, FXival m, const FXObjectListOf< TYPE > &objects)
Replace the m objects at pos with objects.
Definition: FXObjectList.h:289
FXbool assign(TYPE *object)
Assign object to list.
Definition: FXObjectList.h:232
Definition: FX4Splitter.h:28
FXbool prepend(FXObject *object)
Prepend object.
FXival no() const
Return number of objects.
Definition: FXObjectList.h:59
FXObject *& head()
First element in list.
Definition: FXObjectList.h:73
TYPE *& head()
First element in list.
Definition: FXObjectList.h:214
FXbool insert(FXival pos, TYPE *object, FXival n)
Insert n copies of object at specified position.
Definition: FXObjectList.h:247
FXObject ** data()
Access to content array.
Definition: FXObjectList.h:81
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134
FXbool insert(FXival pos, const FXObjectListOf< TYPE > &objects)
Insert objects at specified position.
Definition: FXObjectList.h:253
FXbool assign(TYPE **objects, FXival n)
Assign n objects to list.
Definition: FXObjectList.h:238
FXbool append(TYPE **objects, FXival n)
Append n objects.
Definition: FXObjectList.h:274
FXbool append(const FXObjectListOf< TYPE > &objects)
Append objects.
Definition: FXObjectList.h:277
FXbool replace(FXival pos, FXival m, TYPE *object, FXival n)
Replaces the m objects at pos with n copies of object.
Definition: FXObjectList.h:283
FXbool push(TYPE *object)
Push object to end.
Definition: FXObjectList.h:295
FXbool replace(FXival pos, FXObject *object)
Replace object at position by given object.
FXbool push(FXObject *object)
Push object to end.
FXObjectListOf< TYPE > & operator=(const FXObjectListOf< TYPE > &orig)
Assignment operator.
Definition: FXObjectList.h:200
FXObjectListOf()
Default constructor.
Definition: FXObjectList.h:185
FXObject *& tail()
Last element in list.
Definition: FXObjectList.h:77
FXbool append(TYPE *object)
Append object.
Definition: FXObjectList.h:268
FXObjectList & operator=(const FXObjectList &other)
Assignment operator.
List to pointers to objects of TYPE.
Definition: FXObjectList.h:181
TYPE *& tail()
Last element in list.
Definition: FXObjectList.h:218
FXObjectListOf(TYPE *object, FXival n)
Construct and init with n copies of object.
Definition: FXObjectList.h:194
FXbool prepend(const FXObjectListOf< TYPE > &objects)
Prepend objects.
Definition: FXObjectList.h:265
FXbool assign(FXObject *object)
Assign object to list.
FXbool assign(TYPE *object, FXival n)
Assign n copies of object to list.
Definition: FXObjectList.h:235
FXObjectListOf(const FXObjectListOf< TYPE > &src)
Copy constructor.
Definition: FXObjectList.h:188

Copyright © 1997-2022 Jeroen van der Zijp