4 * Kern Sibbald, June MMIII
7 Copyright (C) 2003-2005 Kern Sibbald
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as amended with additional clauses defined in the
12 file LICENSE in the main source directory.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 the file LICENSE for additional details.
23 * There is a lot of extra casting here to work around the fact
24 * that some compilers (Sun and Visual C++) do not accept
25 * (void *) as an lvalue on the left side of an equal.
27 * Loop var through each member of list
29 #define foreach_alist(var, list) \
30 for((*((void **)&(var))=(void*)((list)->first())); \
32 (*((void **)&(var))=(void*)((list)->next())))
35 #define foreach_alist(var, list) \
36 for(((void*)(var))=(list)->first(); (var); ((void*)(var))=(list)->next(var)); )
40 /* Second arg of init */
42 owned_by_alist = true,
43 not_owned_by_alist = false
47 * Array list -- much like a simplified STL vector
48 * array of pointers to inserted items
50 class alist : public SMARTALLOC {
59 alist(int num = 1, bool own=true);
61 void init(int num = 1, bool own=true);
62 void append(void *item);
63 void prepend(void *item);
64 void *remove(int index);
71 void * operator [](int index) const;
76 /* Use it as a stack, pushing and poping from the end */
77 void push(void *item) { append(item); };
78 void pop() { num_items?NULL:remove(num_items-1); };
81 inline void * alist::operator [](int index) const {
82 if (index < 0 || index >= num_items) {
88 inline bool alist::empty() const
90 /* Check for null pointer */
91 return this ? num_items == 0 : true;
95 * This allows us to do explicit initialization,
96 * allowing us to mix C++ classes inside malloc'ed
97 * C structures. Define before called in constructor.
99 inline void alist::init(int num, bool own) {
108 inline alist::alist(int num, bool own) {
113 inline alist::~alist() {
119 /* Current size of list */
120 inline int alist::size() const
123 * Check for null pointer, which allows test
124 * on size to succeed even if nothing put in
127 return this ? num_items : 0;
130 /* How much to grow by each time */
131 inline void alist::grow(int num)