2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2003-2012 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 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 Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula(R) is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Kern Sibbald, June MMIII
34 * There is a lot of extra casting here to work around the fact
35 * that some compilers (Sun and Visual C++) do not accept
36 * (void *) as an lvalue on the left side of an equal.
38 * Loop var through each member of list
41 #define foreach_alist(var, list) \
42 for((var)=(typeof(var))(list)->first(); (var); (var)=(typeof(var))(list)->next() )
44 #define foreach_alist(var, list) \
45 for((*((void **)&(var))=(void*)((list)->first())); \
47 (*((void **)&(var))=(void*)((list)->next())))
51 #define foreach_alist_index(inx, var, list) \
52 for(inx=0; ((var)=(typeof(var))(list)->get(inx)); inx++ )
54 #define foreach_alist_index(inx, var, list) \
55 for(inx=0; ((*((void **)&(var))=(void*)((list)->get(inx)))); inx++ )
61 /* Second arg of init */
63 owned_by_alist = true,
64 not_owned_by_alist = false
68 * Array list -- much like a simplified STL vector
69 * array of pointers to inserted items
71 class alist : public SMARTALLOC {
80 alist(int num = 1, bool own=true);
82 void init(int num = 1, bool own=true);
83 void append(void *item);
84 void prepend(void *item);
85 void *remove(int index);
92 void * operator [](int index) const;
93 int current() const { return cur_item; };
98 /* Use it as a stack, pushing and poping from the end */
99 void push(void *item) { append(item); };
100 void *pop() { return remove(num_items-1); };
104 * Define index operator []
106 inline void * alist::operator [](int index) const {
107 if (index < 0 || index >= num_items) {
113 inline bool alist::empty() const
115 /* Check for null pointer */
116 return this ? num_items == 0 : true;
120 * This allows us to do explicit initialization,
121 * allowing us to mix C++ classes inside malloc'ed
122 * C structures. Define before called in constructor.
124 inline void alist::init(int num, bool own)
134 inline alist::alist(int num, bool own)
140 inline alist::~alist()
147 /* Current size of list */
148 inline int alist::size() const
151 * Check for null pointer, which allows test
152 * on size to succeed even if nothing put in
155 return this ? num_items : 0;
158 /* How much to grow by each time */
159 inline void alist::grow(int num)