Skip to content

Commit

Permalink
alist: moving private members down
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri authored and pstorz committed Sep 19, 2022
1 parent 236d829 commit 726864b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions core/src/lib/alist.h
Expand Up @@ -95,27 +95,6 @@ enum
*/

template <typename T> class alist {
T* items = nullptr;
int num_items = 0;
int max_items = 0;
int num_grow = 0;
int cur_item = 0;
bool own_items = false;
/* Private grow list function. Used to insure that
* at least one more "slot" is available.
*/
void GrowList(void)
{
if (items == NULL) {
if (num_grow == 0) { num_grow = 1; /* default if not initialized */ }
items = (T*)malloc(num_grow * sizeof(T));
max_items = num_grow;
} else if (num_items == max_items) {
max_items += num_grow;
items = (T*)realloc(items, max_items * sizeof(T));
}
}

public:
// Ueb disable non pointer initialization
alist(int num = 1, bool own = true) { init(num, own); }
Expand Down Expand Up @@ -224,6 +203,29 @@ template <typename T> class alist {
// Use it as a stack, pushing and popping from the end
void push(T item) { append(item); }
T pop() { return remove(num_items - 1); }

private:
/* Private grow list function. Used to insure that
* at least one more "slot" is available.
*/
void GrowList(void)
{
if (items == NULL) {
if (num_grow == 0) { num_grow = 1; /* default if not initialized */ }
items = (T*)malloc(num_grow * sizeof(T));
max_items = num_grow;
} else if (num_items == max_items) {
max_items += num_grow;
items = (T*)realloc(items, max_items * sizeof(T));
}
}

T* items = nullptr;
int num_items = 0;
int max_items = 0;
int num_grow = 0;
int cur_item = 0;
bool own_items = false;
};

#endif // BAREOS_LIB_ALIST_H_

0 comments on commit 726864b

Please sign in to comment.