1
/* $Id: helpers.cpp 9662 2007-04-17 20:23:13Z belugas $ */
3
/** @file helpers.cpp */
11
#include "misc/blob.hpp"
13
/* Engine list manipulators - current implementation is only C wrapper around CBlobT<EngineID> (see yapf/blob.hpp) */
15
/* we cannot expose CBlobT directly to C so we must cast EngineList* to CBlobT<EngineID>* always when we are called from C */
16
#define B (*(CBlobT<EngineID>*)el)
18
/** Create Engine List (and initialize it to empty)
19
* @param el list to be created
21
void EngList_Create(EngineList *el)
23
/* call CBlobT constructor explicitly */
24
new (&B) CBlobT<EngineID>();
27
/** Destroy Engine List (and free its contents)
28
* @param el list to be destroyed
30
void EngList_Destroy(EngineList *el)
32
/* call CBlobT destructor explicitly */
33
B.~CBlobT<EngineID>();
36
/** Return number of items stored in the Engine List
37
* @param el list for count inquiry
38
* @return the desired count
40
uint EngList_Count(const EngineList *el)
45
/** Add new item at the end of Engine List
46
* @param el list o which to add an engine
47
* @param eid engine to add to the list
49
void EngList_Add(EngineList *el, EngineID eid)
54
/** Return pointer to the items array held by Engine List
55
* @param el list from which the array pointer has to be returned
56
* @return the pointer required
58
EngineID* EngList_Items(EngineList *el)
63
/** Clear the Engine List (by invalidating all its items == reseting item count to zero)
64
* @param el list to be cleared
66
void EngList_RemoveAll(EngineList *el)
71
/** Sort all items using qsort() and given 'CompareItems' function
72
* @param el list to be sorted
73
* @param compare function for evaluation of the quicksort
75
void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
77
qsort(B.Data(), B.Size(), sizeof(**el), compare);
80
/** Sort selected range of items (on indices @ <begin, begin+num_items-1>)
81
* @param el list to be sorted
82
* @param compare function for evaluation of the quicksort
83
* @param begin start of sorting
84
* @param num_items count of items to be sorted
86
void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
88
assert(begin <= (uint)B.Size());
89
assert(begin + num_items <= (uint)B.Size());
90
qsort(B.Data() + begin, num_items, sizeof(**el), compare);