KUDr@5189: /* $Id$ */ KUDr@5189: #include "stdafx.h" KUDr@5189: KUDr@5189: EXTERN_C_BEGIN KUDr@5189: #include "openttd.h" KUDr@5189: #include "engine.h" KUDr@5189: EXTERN_C_END KUDr@5189: KUDr@5189: #include KUDr@5189: #include "yapf/blob.hpp" KUDr@5189: KUDr@5189: /* Engine list manipulators - current implementation is only C wrapper around CBlobT (see yapf/blob.hpp) */ KUDr@5189: KUDr@5189: /* we cannot expose CBlobT directly to C so we must cast EngineList* to CBlobT* always when we are called from C */ KUDr@5189: #define B (*(CBlobT*)el) KUDr@5189: KUDr@5189: /** Create Engine List (and initialize it to empty) */ KUDr@5189: void EngList_Create(EngineList *el) KUDr@5189: { KUDr@5189: // call CBlobT constructor explicitly KUDr@5189: new (&B) CBlobT(); KUDr@5189: } KUDr@5189: KUDr@5189: /** Destroy Engine List (and free its contents) */ KUDr@5189: void EngList_Destroy(EngineList *el) KUDr@5189: { KUDr@5189: // call CBlobT destructor explicitly KUDr@5189: B.~CBlobT(); KUDr@5189: } KUDr@5189: KUDr@5189: /** Return number of items stored in the Engine List */ KUDr@5189: uint EngList_Count(const EngineList *el) KUDr@5189: { KUDr@5189: return B.Size(); KUDr@5189: } KUDr@5189: KUDr@5189: /** Add new item at the end of Engine List */ KUDr@5189: void EngList_Add(EngineList *el, EngineID eid) KUDr@5189: { KUDr@5189: B.Append(eid); KUDr@5189: } KUDr@5189: KUDr@5189: /** Return pointer to the items array held by Engine List */ KUDr@5189: EngineID* EngList_Items(EngineList *el) KUDr@5189: { KUDr@5189: return B.Data(); KUDr@5189: } KUDr@5189: KUDr@5189: /** Clear the Engine List (by invalidating all its items == reseting item count to zero) */ KUDr@5189: void EngList_RemoveAll(EngineList *el) KUDr@5189: { KUDr@5189: B.Clear(); KUDr@5189: } KUDr@5189: KUDr@5189: /** Sort all items using qsort() and given 'CompareItems' function */ KUDr@5189: void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare) KUDr@5189: { KUDr@5189: qsort(B.Data(), B.Size(), sizeof(**el), compare); KUDr@5189: } KUDr@5189: KUDr@5189: /** Sort selected range of items (on indices @ ) */ KUDr@5189: void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items) KUDr@5189: { KUDr@5189: assert(begin <= (uint)B.Size()); KUDr@5189: assert(begin + num_items <= (uint)B.Size()); KUDr@5189: qsort(B.Data() + begin, num_items, sizeof(**el), compare); KUDr@5189: } KUDr@5189: KUDr@5189: #undef B KUDr@5189: