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,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 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& src);
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& src);
50 
52  FXival no() const { return *((FXival*)(ptr-1)); }
53 
55  FXbool no(FXival num);
56 
58  FXptr& operator[](FXival i){ return ptr[i]; }
59  FXptr const& operator[](FXival i) const { return ptr[i]; }
60 
62  FXptr& at(FXival i){ return ptr[i]; }
63  FXptr const& at(FXival i) const { return ptr[i]; }
64 
66  FXptr& head(){ return ptr[0]; }
67  FXptr const& head() const { return ptr[0]; }
68 
70  FXptr& tail(){ return ptr[no()-1]; }
71  FXptr const& tail() const { return ptr[no()-1]; }
72 
74  FXptr* data(){ return ptr; }
75  const FXptr* data() const { return ptr; }
76 
78  FXPtrList& adopt(FXPtrList& src);
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  void 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(reinterpret_cast<FXptr>(object)){ }
183 
185  FXPtrListOf(TYPE* object,FXival n):FXPtrList(reinterpret_cast<FXptr>(object),n){ }
186 
188  FXPtrListOf(TYPE** objects,FXival n):FXPtrList(reinterpret_cast<FXptr*>(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

Copyright © 1997-2016 Jeroen van der Zijp