2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Kern Sibbald, June MMIII
25 * There is a lot of extra casting here to work around the fact
26 * that some compilers (Sun and Visual C++) do not accept
27 * (void *) as an lvalue on the left side of an equal.
29 * Loop var through each member of list
32 #define foreach_alist(var, list) \
33 for((var)=(typeof(var))(list)->first(); (var); (var)=(typeof(var))(list)->next() )
35 #define foreach_alist(var, list) \
36 for((*((void **)&(var))=(void*)((list)->first())); \
38 (*((void **)&(var))=(void*)((list)->next())))
42 #define foreach_alist_index(inx, var, list) \
43 for(inx=0; ((var)=(typeof(var))(list)->get(inx)); inx++ )
45 #define foreach_alist_index(inx, var, list) \
46 for(inx=0; ((*((void **)&(var))=(void*)((list)->get(inx)))); inx++ )
52 /* Second arg of init */
54 owned_by_alist = true,
55 not_owned_by_alist = false
59 * Array list -- much like a simplified STL vector
60 * array of pointers to inserted items
62 class alist : public SMARTALLOC {
71 alist(int num = 10, bool own=true);
73 void init(int num = 10, bool own=true);
74 void append(void *item);
75 void prepend(void *item);
76 void *remove(int index);
83 void * operator [](int index) const;
84 int current() const { return cur_item; };
89 /* Use it as a stack, pushing and poping from the end */
90 void push(void *item) { append(item); };
91 void *pop() { return remove(num_items-1); };
95 * Define index operator []
97 inline void * alist::operator [](int index) const {
98 if (index < 0 || index >= num_items) {
104 inline bool alist::empty() const
106 /* Check for null pointer */
107 return this ? num_items == 0 : true;
111 * This allows us to do explicit initialization,
112 * allowing us to mix C++ classes inside malloc'ed
113 * C structures. Define before called in constructor.
115 inline void alist::init(int num, bool own)
125 inline alist::alist(int num, bool own)
131 inline alist::~alist()
138 /* Current size of list */
139 inline int alist::size() const
142 * Check for null pointer, which allows test
143 * on size to succeed even if nothing put in
146 return this ? num_items : 0;
149 /* How much to grow by each time */
150 inline void alist::grow(int num)