2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2003-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Kern Sibbald, June MMIII
26 * There is a lot of extra casting here to work around the fact
27 * that some compilers (Sun and Visual C++) do not accept
28 * (void *) as an lvalue on the left side of an equal.
30 * Loop var through each member of list
33 #define foreach_alist(var, list) \
34 for((var)=(typeof(var))(list)->first(); (var); (var)=(typeof(var))(list)->next() )
36 #define foreach_alist(var, list) \
37 for((*((void **)&(var))=(void*)((list)->first())); \
39 (*((void **)&(var))=(void*)((list)->next())))
43 #define foreach_alist_index(inx, var, list) \
44 for(inx=0; ((var)=(typeof(var))(list)->get(inx)); inx++ )
46 #define foreach_alist_index(inx, var, list) \
47 for(inx=0; ((*((void **)&(var))=(void*)((list)->get(inx)))); inx++ )
53 /* Second arg of init */
55 owned_by_alist = true,
56 not_owned_by_alist = false
60 * Array list -- much like a simplified STL vector
61 * array of pointers to inserted items
63 class alist : public SMARTALLOC {
72 alist(int num = 10, bool own=true);
74 void init(int num = 10, bool own=true);
75 void append(void *item);
76 void prepend(void *item);
77 void *remove(int index);
84 void * operator [](int index) const;
85 int current() const { return cur_item; };
90 /* Use it as a stack, pushing and poping from the end */
91 void push(void *item) { append(item); };
92 void *pop() { return remove(num_items-1); };
96 * Define index operator []
98 inline void * alist::operator [](int index) const {
99 if (index < 0 || index >= num_items) {
105 inline bool alist::empty() const
107 /* Check for null pointer */
108 return this ? num_items == 0 : true;
112 * This allows us to do explicit initialization,
113 * allowing us to mix C++ classes inside malloc'ed
114 * C structures. Define before called in constructor.
116 inline void alist::init(int num, bool own)
126 inline alist::alist(int num, bool own)
132 inline alist::~alist()
139 /* Current size of list */
140 inline int alist::size() const
143 * Check for null pointer, which allows test
144 * on size to succeed even if nothing put in
147 return this ? num_items : 0;
150 /* How much to grow by each time */
151 inline void alist::grow(int num)