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

FXPtrList.h
1 /********************************************************************************
2 * *
3 * P o i n t e r L i s t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2024 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 FXPTRLIST_H
22 #define FXPTRLIST_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXPtrList {
29 protected:
30  FXptr* ptr;
31 public:
32 
34  FXPtrList();
35 
37  FXPtrList(const FXPtrList& other);
38 
40  FXPtrList(FXptr object);
41 
43  FXPtrList(FXptr object,FXival n);
44 
46  FXPtrList(FXptr* objects,FXival n);
47 
49  FXPtrList& operator=(const FXPtrList& other);
50 
52  FXPtrList& adopt(FXPtrList& other);
53 
55  FXival no() const { return *((FXival*)(ptr-1)); }
56 
58  FXbool no(FXival num);
59 
61  FXptr& operator[](FXival i){ return ptr[i]; }
62  FXptr const& operator[](FXival i) const { return ptr[i]; }
63 
65  FXptr& at(FXival i){ return ptr[i]; }
66  FXptr const& at(FXival i) const { return ptr[i]; }
67 
69  FXptr& head(){ return ptr[0]; }
70  FXptr const& head() const { return ptr[0]; }
71 
73  FXptr& tail(){ return ptr[no()-1]; }
74  FXptr const& tail() const { return ptr[no()-1]; }
75 
77  FXptr* data(){ return ptr; }
78  const FXptr* data() const { return ptr; }
79 
81  FXival find(FXptr object,FXival pos=0) const;
82 
84  FXival rfind(FXptr object,FXival pos=2147483647) const;
85 
87  FXbool assign(FXptr object);
88 
90  FXbool assign(FXptr object,FXival n);
91 
93  FXbool assign(FXptr* objects,FXival n);
94 
96  FXbool assign(const FXPtrList& objects);
97 
99  FXbool insert(FXival pos,FXptr object);
100 
102  FXbool insert(FXival pos,FXptr object,FXival n);
103 
105  FXbool insert(FXival pos,FXptr* objects,FXival n);
106 
108  FXbool insert(FXival pos,const FXPtrList& objects);
109 
111  FXbool prepend(FXptr object);
112 
114  FXbool prepend(FXptr object,FXival n);
115 
117  FXbool prepend(FXptr* objects,FXival n);
118 
120  FXbool prepend(const FXPtrList& objects);
121 
123  FXbool append(FXptr object);
124 
126  FXbool append(FXptr object,FXival n);
127 
129  FXbool append(FXptr* objects,FXival n);
130 
132  FXbool append(const FXPtrList& objects);
133 
135  FXbool replace(FXival pos,FXptr object);
136 
138  FXbool replace(FXival pos,FXival m,FXptr object,FXival n);
139 
141  FXbool replace(FXival pos,FXival m,FXptr* objects,FXival n);
142 
144  FXbool replace(FXival pos,FXival m,const FXPtrList& objects);
145 
147  FXbool erase(FXival pos);
148 
150  FXbool erase(FXival pos,FXival n);
151 
153  FXbool remove(FXptr object);
154 
156  FXbool push(FXptr object);
157 
159  FXbool pop();
160 
162  FXbool clear();
163 
165  ~FXPtrList();
166  };
167 
168 
169 
171 template<typename TYPE>
172 class FXPtrListOf : public FXPtrList {
173 public:
174 
177 
180 
182  FXPtrListOf(TYPE* object):FXPtrList(object){ }
183 
185  FXPtrListOf(TYPE* object,FXival n):FXPtrList(object,n){ }
186 
188  FXPtrListOf(TYPE** objects,FXival n):FXPtrList(objects,n){ }
189 
191  FXPtrListOf<TYPE>& operator=(const FXPtrListOf<TYPE>& src){ return reinterpret_cast<FXPtrListOf<TYPE>&>(FXPtrList::operator=(src)); }
192 
195 
197  TYPE*& operator[](FXival i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
198  TYPE *const& operator[](FXival i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
199 
201  TYPE*& at(FXival i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
202  TYPE *const& at(FXival i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
203 
205  TYPE*& head(){ return reinterpret_cast<TYPE*&>(ptr[0]); }
206  TYPE* const& head() const { return reinterpret_cast<TYPE*const&>(ptr[0]); }
207 
209  TYPE*& tail(){ return reinterpret_cast<TYPE*&>(ptr[no()-1]); }
210  TYPE* const& tail() const { return reinterpret_cast<TYPE* const&>(ptr[no()-1]); }
211 
213  TYPE** data(){ return reinterpret_cast<TYPE**>(ptr); }
214  TYPE *const * data() const { return reinterpret_cast<TYPE*const*>(ptr); }
215 
217  FXival find(TYPE* object,FXival pos=0) const { return FXPtrList::find(object,pos); }
218 
220  FXival rfind(TYPE* object,FXival pos=2147483647) const { return FXPtrList::rfind(object,pos); }
221 
223  FXbool assign(TYPE* object){ return FXPtrList::assign(object); }
224 
226  FXbool assign(TYPE* object,FXival n){ return FXPtrList::assign(object,n); }
227 
229  FXbool assign(TYPE** objects,FXival n){ return FXPtrList::assign(objects,n); }
230 
232  FXbool assign(const FXPtrListOf<TYPE>& objects){ return FXPtrList::assign(objects); }
233 
235  FXbool insert(FXival pos,TYPE* object){ return FXPtrList::insert(pos,object); }
236 
238  FXbool insert(FXival pos,TYPE* object,FXival n){ return FXPtrList::insert(pos,object,n); }
239 
241  FXbool insert(FXival pos,TYPE** objects,FXival n){ return FXPtrList::insert(pos,objects,n); }
242 
244  FXbool insert(FXival pos,const FXPtrListOf<TYPE>& objects){ return FXPtrList::insert(pos,objects); }
245 
247  FXbool prepend(TYPE* object){ return FXPtrList::prepend(object); }
248 
250  FXbool prepend(TYPE* object,FXival n){ return FXPtrList::prepend(object,n); }
251 
253  FXbool prepend(TYPE** objects,FXival n){ return FXPtrList::prepend(objects,n); }
254 
256  FXbool prepend(const FXPtrListOf<TYPE>& objects){ return FXPtrList::prepend(objects); }
257 
259  FXbool append(TYPE* object){ return FXPtrList::append(object); }
260 
262  FXbool append(TYPE* object,FXival n){ return FXPtrList::append(object,n); }
263 
265  FXbool append(TYPE** objects,FXival n){ return FXPtrList::append(objects,n); }
266 
268  FXbool append(const FXPtrListOf<TYPE>& objects){ return FXPtrList::append(objects); }
269 
271  FXbool replace(FXival pos,TYPE* object){ return FXPtrList::replace(pos,object); }
272 
274  FXbool replace(FXival pos,FXival m,TYPE* object,FXival n){ return FXPtrList::replace(pos,m,object,n); }
275 
277  FXbool replace(FXival pos,FXival m,TYPE** objects,FXival n){ return FXPtrList::replace(pos,m,objects,n); }
278 
280  FXbool replace(FXival pos,FXival m,const FXPtrListOf<TYPE>& objects){ return FXPtrList::replace(pos,m,objects); }
281 
283  FXbool remove(TYPE* object){ return FXPtrList::remove(object); }
284 
286  FXbool push(TYPE* object){ return FXPtrList::push(object); }
287  };
288 
289 }
290 
291 #endif
FXPtrList & adopt(FXPtrList &other)
Adopt objects from other, leaving other empty.
FXbool replace(FXival pos, FXptr object)
Replace object at position by given object.
FXbool prepend(TYPE *object)
Prepend object.
Definition: FXPtrList.h:247
FXPtrListOf(TYPE *object)
Construct and init with single object.
Definition: FXPtrList.h:182
FXbool replace(FXival pos, FXival m, TYPE *object, FXival n)
Replaces the m objects at pos with n copies of object.
Definition: FXPtrList.h:274
FXbool prepend(TYPE *object, FXival n)
Prepend n copies of object.
Definition: FXPtrList.h:250
FXbool remove(FXptr object)
Remove object.
FXbool prepend(const FXPtrListOf< TYPE > &objects)
Prepend objects.
Definition: FXPtrList.h:256
FXbool insert(FXival pos, TYPE **objects, FXival n)
Insert n objects at specified position.
Definition: FXPtrList.h:241
List to pointers to TYPE.
Definition: FXPtrList.h:172
FXbool insert(FXival pos, const FXPtrListOf< TYPE > &objects)
Insert objects at specified position.
Definition: FXPtrList.h:244
FXbool assign(TYPE **objects, FXival n)
Assign n objects to list.
Definition: FXPtrList.h:229
FXbool append(TYPE *object, FXival n)
Append n copies of object.
Definition: FXPtrList.h:262
FXptr & at(FXival i)
Indexing operator.
Definition: FXPtrList.h:65
TYPE *& tail()
Last element in list.
Definition: FXPtrList.h:209
FXbool assign(FXptr object)
Assign object to list.
FXbool assign(TYPE *object)
Assign object to list.
Definition: FXPtrList.h:223
FXbool insert(FXival pos, FXptr object)
Insert object at certain position.
TYPE ** data()
Access to content array.
Definition: FXPtrList.h:213
FXptr & tail()
Last element in list.
Definition: FXPtrList.h:73
FXbool append(FXptr object)
Append object.
FXbool prepend(FXptr object)
Prepend object.
FXbool append(TYPE **objects, FXival n)
Append n objects.
Definition: FXPtrList.h:265
FXbool replace(FXival pos, FXival m, TYPE **objects, FXival n)
Replaces the m objects at pos with n objects.
Definition: FXPtrList.h:277
TYPE *& at(FXival i)
Indexing operator.
Definition: FXPtrList.h:201
FXbool push(FXptr object)
Push object to end.
FXPtrListOf(TYPE **objects, FXival n)
Construct and init with list of objects.
Definition: FXPtrList.h:188
FXbool assign(TYPE *object, FXival n)
Assign n copies of object to list.
Definition: FXPtrList.h:226
FXbool prepend(TYPE **objects, FXival n)
Prepend n objects.
Definition: FXPtrList.h:253
FXbool replace(FXival pos, FXival m, const FXPtrListOf< TYPE > &objects)
Replace the m objects at pos with objects.
Definition: FXPtrList.h:280
FXbool append(const FXPtrListOf< TYPE > &objects)
Append objects.
Definition: FXPtrList.h:268
FXptr & head()
First element in list.
Definition: FXPtrList.h:69
FXPtrListOf(TYPE *object, FXival n)
Construct and init with n copies of object.
Definition: FXPtrList.h:185
Definition: FX4Splitter.h:28
TYPE *& head()
First element in list.
Definition: FXPtrList.h:205
FXival no() const
Return number of objects.
Definition: FXPtrList.h:55
FXbool insert(FXival pos, TYPE *object, FXival n)
Insert n copies of object at specified position.
Definition: FXPtrList.h:238
FXival rfind(FXptr object, FXival pos=2147483647) const
Find object in list, searching backward; return position or -1.
FXPtrListOf()
Default constructor.
Definition: FXPtrList.h:176
FXptr & operator[](FXival i)
Indexing operator.
Definition: FXPtrList.h:61
FXival find(TYPE *object, FXival pos=0) const
Find object in list, searching forward; return position or -1.
Definition: FXPtrList.h:217
TYPE *& operator[](FXival i)
Indexing operator.
Definition: FXPtrList.h:197
FXPtrList & operator=(const FXPtrList &other)
Assignment operator.
FXbool append(TYPE *object)
Append object.
Definition: FXPtrList.h:259
FXptr * data()
Access to content array.
Definition: FXPtrList.h:77
FXival find(FXptr object, FXival pos=0) const
Find object in list, searching forward; return position or -1.
FXbool replace(FXival pos, TYPE *object)
Replace object at position by given object.
Definition: FXPtrList.h:271
FXPtrListOf(const FXPtrListOf< TYPE > &src)
Copy constructor.
Definition: FXPtrList.h:179
FXPtrListOf< TYPE > & operator=(const FXPtrListOf< TYPE > &src)
Assignment operator.
Definition: FXPtrList.h:191
List of void pointers.
Definition: FXPtrList.h:28
FXival rfind(TYPE *object, FXival pos=2147483647) const
Find object in list, searching backward; return position or -1.
Definition: FXPtrList.h:220
FXbool insert(FXival pos, TYPE *object)
Insert object at certain position.
Definition: FXPtrList.h:235
FXbool push(TYPE *object)
Push object to end.
Definition: FXPtrList.h:286
FXPtrListOf< TYPE > & adopt(FXPtrListOf< TYPE > &src)
Adopt objects from orig, leaving orig empty.
Definition: FXPtrList.h:194
FXbool assign(const FXPtrListOf< TYPE > &objects)
Assign objects to list.
Definition: FXPtrList.h:232

Copyright © 1997-2022 Jeroen van der Zijp