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,2013 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 
25 namespace FX {
26 
27 
29 class FXAPI FXPtrList {
30 protected:
31  FXptr* ptr;
32 public:
33 
35  FXPtrList();
36 
38  FXPtrList(const FXPtrList& src);
39 
41  FXPtrList(FXptr object);
42 
44  FXPtrList(FXptr object,FXint n);
45 
47  FXPtrList(FXptr* objects,FXint n);
48 
50  FXPtrList& operator=(const FXPtrList& orig);
51 
53  FXint no() const { return *((FXint*)(ptr-1)); }
54 
56  FXbool no(FXint num);
57 
59  FXptr& operator[](FXint i){ return ptr[i]; }
60  FXptr const& operator[](FXint i) const { return ptr[i]; }
61 
63  FXptr& at(FXint i){ return ptr[i]; }
64  FXptr const& at(FXint i) const { return ptr[i]; }
65 
67  FXptr& head(){ return ptr[0]; }
68  FXptr const& head() const { return ptr[0]; }
69 
71  FXptr& tail(){ return ptr[no()-1]; }
72  FXptr const& tail() const { return ptr[no()-1]; }
73 
75  FXptr* data(){ return ptr; }
76  const FXptr* data() const { return ptr; }
77 
79  void adopt(FXPtrList& orig);
80 
82  FXbool assign(FXptr object);
83 
85  FXbool assign(FXptr object,FXint n);
86 
88  FXbool assign(FXptr* objects,FXint n);
89 
91  FXbool assign(const FXPtrList& objects);
92 
94  FXbool insert(FXint pos,FXptr object);
95 
97  FXbool insert(FXint pos,FXptr object,FXint n);
98 
100  FXbool insert(FXint pos,FXptr* objects,FXint n);
101 
103  FXbool insert(FXint pos,const FXPtrList& objects);
104 
106  FXbool prepend(FXptr object);
107 
109  FXbool prepend(FXptr object,FXint n);
110 
112  FXbool prepend(FXptr* objects,FXint n);
113 
115  FXbool prepend(const FXPtrList& objects);
116 
118  FXbool append(FXptr object);
119 
121  FXbool append(FXptr object,FXint n);
122 
124  FXbool append(FXptr* objects,FXint n);
125 
127  FXbool append(const FXPtrList& objects);
128 
130  FXbool replace(FXint pos,FXptr object);
131 
133  FXbool replace(FXint pos,FXint m,FXptr object,FXint n);
134 
136  FXbool replace(FXint pos,FXint m,FXptr* objects,FXint n);
137 
139  FXbool replace(FXint pos,FXint m,const FXPtrList& objects);
140 
142  FXbool erase(FXint pos);
143 
145  FXbool erase(FXint pos,FXint n);
146 
148  FXbool push(FXptr object);
149 
151  FXbool pop();
152 
154  FXbool remove(FXptr object);
155 
157  FXint find(FXptr object,FXint pos=0) const;
158 
160  FXint rfind(FXptr object,FXint pos=2147483647) const;
161 
163  void clear();
164 
166  virtual ~FXPtrList();
167  };
168 
169 
170 
172 template<class TYPE>
173 class FXPtrListOf : public FXPtrList {
174 public:
177 
180 
182  FXPtrListOf(TYPE* object):FXPtrList(reinterpret_cast<FXptr>(object)){ }
183 
185  FXPtrListOf(TYPE* object,FXint n):FXPtrList(reinterpret_cast<FXptr>(object),n){ }
186 
188  FXPtrListOf(TYPE** objects,FXint n):FXPtrList(reinterpret_cast<FXptr*>(objects),n){ }
189 
191  TYPE*& operator[](FXint i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
192  TYPE *const& operator[](FXint i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
193 
195  TYPE*& at(FXint i){ return reinterpret_cast<TYPE*&>(ptr[i]); }
196  TYPE *const& at(FXint i) const { return reinterpret_cast<TYPE*const&>(ptr[i]); }
197 
199  TYPE*& head(){ return reinterpret_cast<TYPE*&>(ptr[0]); }
200  TYPE* const& head() const { return reinterpret_cast<TYPE*const&>(ptr[0]); }
201 
203  TYPE*& tail(){ return reinterpret_cast<TYPE*&>(ptr[no()-1]); }
204  TYPE* const& tail() const { return reinterpret_cast<TYPE* const&>(ptr[no()-1]); }
205 
207  TYPE** data(){ return reinterpret_cast<TYPE**>(ptr); }
208  TYPE *const * data() const { return reinterpret_cast<TYPE*const*>(ptr); }
209  };
210 
211 }
212 
213 #endif

Copyright © 1997-2013 Jeroen van der Zijp