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,2017 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& src);
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& orig);
54 
56  FXObjectList& adopt(FXObjectList& orig);
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  void 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(reinterpret_cast<FXObject*>(object)){ }
192 
194  FXObjectListOf(TYPE* object,FXival n):FXObjectList(reinterpret_cast<FXObject*>(object),n){ }
195 
197  FXObjectListOf(TYPE** objects,FXival n):FXObjectList(reinterpret_cast<FXObject**>(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

Copyright © 1997-2016 Jeroen van der Zijp