~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/helpers.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: helpers.cpp 9662 2007-04-17 20:23:13Z belugas $ */
2
 
 
3
 
/** @file helpers.cpp */
4
 
 
5
 
#include "stdafx.h"
6
 
 
7
 
#include "openttd.h"
8
 
#include "engine.h"
9
 
 
10
 
#include <new>
11
 
#include "misc/blob.hpp"
12
 
 
13
 
/* Engine list manipulators - current implementation is only C wrapper around CBlobT<EngineID> (see yapf/blob.hpp) */
14
 
 
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)
17
 
 
18
 
/** Create Engine List (and initialize it to empty)
19
 
 * @param el list to be created
20
 
 */
21
 
void EngList_Create(EngineList *el)
22
 
{
23
 
        /* call CBlobT constructor explicitly */
24
 
        new (&B) CBlobT<EngineID>();
25
 
}
26
 
 
27
 
/** Destroy Engine List (and free its contents)
28
 
 * @param el list to be destroyed
29
 
 */
30
 
void EngList_Destroy(EngineList *el)
31
 
{
32
 
        /* call CBlobT destructor explicitly */
33
 
        B.~CBlobT<EngineID>();
34
 
}
35
 
 
36
 
/** Return number of items stored in the Engine List
37
 
 * @param el list for count inquiry
38
 
 * @return the desired count
39
 
 */
40
 
uint EngList_Count(const EngineList *el)
41
 
{
42
 
        return B.Size();
43
 
}
44
 
 
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
48
 
 */
49
 
void EngList_Add(EngineList *el, EngineID eid)
50
 
{
51
 
        B.Append(eid);
52
 
}
53
 
 
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
57
 
 */
58
 
EngineID* EngList_Items(EngineList *el)
59
 
{
60
 
        return B.Data();
61
 
}
62
 
 
63
 
/** Clear the Engine List (by invalidating all its items == reseting item count to zero)
64
 
 * @param el list to be cleared
65
 
 */
66
 
void EngList_RemoveAll(EngineList *el)
67
 
{
68
 
        B.Clear();
69
 
}
70
 
 
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
74
 
 */
75
 
void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare)
76
 
{
77
 
        qsort(B.Data(), B.Size(), sizeof(**el), compare);
78
 
}
79
 
 
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
85
 
 */
86
 
void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
87
 
{
88
 
        assert(begin <= (uint)B.Size());
89
 
        assert(begin + num_items <= (uint)B.Size());
90
 
        qsort(B.Data() + begin, num_items, sizeof(**el), compare);
91
 
}
92
 
 
93
 
#undef B
94