6 Copyright (C) 2003-2004 Kern Sibbald and John Walker
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program 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 GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public
19 License along with this program; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 Kern Sibbald, June MMIII
28 * There is a lot of extra casting here to work around the fact
29 * that some compilers (Sun and Visual C++) do not accept
30 * (void *) as an lvalue on the left side of an equal.
32 * Loop var through each member of list
34 #define foreach_alist(var, list) \
35 for((*((void **)&(var))=(void*)((list)->first())); (var); (*((void **)&(var))=(void*)((list)->next())))
38 #define foreach_dlist(var, list) \
39 for((void*(var))=(list)->first(); (var); (void *(var))=(list)->next(var)); )
43 /* Second arg of init */
45 owned_by_alist = true,
46 not_owned_by_alist = false
50 * Array list -- much like a simplified STL vector
51 * array of pointers to inserted items
62 alist(int num = 1, bool own=true);
63 void init(int num = 1, bool own=true);
64 void append(void *item);
65 void prepend(void *item);
66 void *remove(int index);
73 void * operator [](int index) const;
77 void * operator new(size_t);
78 void operator delete(void *);
81 inline void * alist::operator [](int index) const {
82 if (index < 0 || index >= num_items) {
88 inline bool alist::empty() const
90 return num_items == 0;
94 * This allows us to do explicit initialization,
95 * allowing us to mix C++ classes inside malloc'ed
96 * C structures. Define before called in constructor.
98 inline void alist::init(int num, bool own) {
107 inline alist::alist(int num, bool own) {
108 this->init(num, own);
113 /* Current size of list */
114 inline int alist::size() const
119 /* How much to grow by each time */
120 inline void alist::grow(int num)
125 inline void * alist::operator new(size_t)
127 return malloc(sizeof(alist));
130 inline void alist::operator delete(void *item)
132 ((alist *)item)->destroy();