helpers.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006
00007 #include "openttd.h"
00008 #include "engine.h"
00009
00010 #include <new>
00011 #include "misc/blob.hpp"
00012
00013
00014
00015
00016 #define B (*(CBlobT<EngineID>*)el)
00017
00021 void EngList_Create(EngineList *el)
00022 {
00023
00024 new (&B) CBlobT<EngineID>();
00025 }
00026
00030 void EngList_Destroy(EngineList *el)
00031 {
00032
00033 B.~CBlobT<EngineID>();
00034 }
00035
00040 uint EngList_Count(const EngineList *el)
00041 {
00042 return B.Size();
00043 }
00044
00049 void EngList_Add(EngineList *el, EngineID eid)
00050 {
00051 B.Append(eid);
00052 }
00053
00058 EngineID* EngList_Items(EngineList *el)
00059 {
00060 return B.Data();
00061 }
00062
00066 void EngList_RemoveAll(EngineList *el)
00067 {
00068 B.Clear();
00069 }
00070
00075 void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
00076 {
00077 qsort(B.Data(), B.Size(), sizeof(**el), compare);
00078 }
00079
00086 void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
00087 {
00088 assert(begin <= (uint)B.Size());
00089 assert(begin + num_items <= (uint)B.Size());
00090 qsort(B.Data() + begin, num_items, sizeof(**el), compare);
00091 }
00092
00093 #undef B
00094