Repository navigation
Expand file tree
/
Copy pathMikModContnrs.h
More file actions
277 lines (248 loc) · 10.4 KB
/
Copy pathMikModContnrs.h
File metadata and controls
277 lines (248 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//---------------------------------------------------------------------------
#ifndef MikModContnrsH
#define MikModContnrsH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include "MikMod.h"
//---------------------------------------------------------------------------
namespace Mikmod
{
/**
* A template for storing a list of generic elements.
*/
template <class T>class TObjectList : public System::Classes::TList
{
typedef System::Classes::TList inherited;
private:
bool FOwnsObjects;
protected:
/**
* Responds when items are added, removed, or extracted from the list.
* Notify is called automatically when the items in the collection change.
* @param Ptr Points to item affected by the change.
* @param Action Indicates the change.
*/
virtual void __fastcall Notify(void * Ptr, System::Classes::TListNotification Action)
{
if(Action == TListNotification::lnDeleted && OwnsObjects == true)
{
delete static_cast<T>(Ptr);
}
inherited::Notify(Ptr, Action);
}
/**
* Returns a specified item in the collection.
* GetItem is the protected read implementation of the Items property.
* @param Index Position of an item.
* @return A pointer to the item at Index.
*/
T __fastcall GetItem(int Index)
{
return static_cast<T>(inherited::Items[Index]);
}
/**
* Represents the abstract setter method for the Item property.
* SetItem is the setter method for the Item property.
* @param Index Position of an item.
* @param AObject The object to set.
*/
void __fastcall SetItem(int Index, T AObject)
{
inherited::Items[Index] = AObject;
}
public:
/**
* Constructor.
* @param AOwnsObjects Value to initialize OwnsObjects.
* When no value is specified, TObjectList is initialized with OwnsObjects set to true.
*/
__fastcall TObjectList(bool AOwnsObjects = true) :
System::Classes::TList(),
FOwnsObjects(AOwnsObjects)
{
}
/**
* Destructor.
*/
inline __fastcall virtual ~TObjectList(void)
{
}
/**
* Add adds a given item to the end of the list. You can add NULL.
* An OnNotify event occurs indicating an entry was added to the list.
* @param AObject The item to add.
* @return The index of the item added to the list.
*/
int __fastcall Add(T AObject)
{
return inherited::Add(AObject);
}
/**
* Remove removes the first instance of AObject in the list, returning its zero-based index.
* If AObject is not in the list, this function returns -1.
* An OnNotify event occurs indicating an entry was removed from the list.
* @param AObject The item to remove.
* @return The index of the item removed from the list or -1 if AObject is not found.
*/
int __fastcall Remove(T AObject)
{
return inherited::Remove(AObject);
}
/**
* Extract removes the entry Item from the list, returning this value. If Item is not in the list, it returns the default value of its type T.
* An OnNotify event occurs indicating an entry was removed from the list.
* Extract is similar to Remove except for the event code indicating an element was extracted rather than removed and is provided so items may be removed without freeing.
* @param Item The item to extract.
* @return A pointer to the extracted value.
*/
T __fastcall Extract(T Item)
{
return static_cast<T>(inherited::Extract(Item));
}
/**
* ExtractItem removes an item from a list. After the item is removed, the index positions of all the objects that follow it are moved up and Count is decremented.
* In descendent classes, ExtractItem also calls the notify method specifying the value of the removed item. This allows descendent classes to perform a proper cleanup with stored values.
* @param Item The item to extract.
* @param ADirection The direction to start the search.
* @return A pointer to the extracted value.
*/
T __fastcall ExtractItem(T Item, System::Classes::TList::TDirection ADirection)
{
return static_cast<T>(inherited::ExtractItem(Item, ADirection));
}
/**
* The RemoveItem method removes a specified item from the list.
* If the item is not found, -1 is returned.
* @param AObject The item to search for.
* @param ADirection The direction to start the search.
* @return The index of the removed item in the list or -1 if AObject is not found.
*/
int __fastcall RemoveItem(T AObject, System::Classes::TList::TDirection ADirection)
{
return inherited::RemoveItem(AObject, ADirection);
}
/**
* IndexOf searches for the list element AObject using a linear search.
* The method returns the zero-based index of the first entry equal to AObject.
* If not found, it returns -1.
* @param AObject The item to search for.
* @return The index of the item found in the list or -1 if AObject is not found.
*/
int __fastcall IndexOf(T AObject)
{
return inherited::IndexOf(AObject);
}
/**
* IndexOfItem searches for the list element AObject using a linear search.
* The method returns the zero-based index of the first entry equal to AObject.
* If not found, it returns -1.
* @param AObject The item to search for.
* @param ADirection The direction to start the search.
* @return The index of the item found in the list or -1 if AObject is not found.
*/
int __fastcall IndexOfItem(T AObject, System::Classes::TList::TDirection ADirection)
{
return inherited::IndexOfItem(AObject, ADirection);
}
/**
* Finds the first instance of a specified class in the list.
* FindInstanceOf returns the index of the first instance of AClass appearing after AStartAt in the Items array.
* If no instance of the specified class is found, FindInstanceOf returns -1.
* @param AClass The class to find.
* @param AExact If AExact is true, FindInstanceOf returns instances only of AClass itself, ignoring instances of descendant classes.
* @param AStartAt The start position for searching.
* @return The index of the item found in the list or -1 if not found.
*/
int __fastcall FindInstanceOf(System::TClass AClass, bool AExact, int AStartAt)
{
int Result = -1;
for(int i = AStartAt; i < Count; ++i)
{
if( (AExact == true && (Items[i]->ClassType() == AClass)) ||
(AExact == false && Items[i]->InheritsFrom(AClass)))
{
Result = i;
break;
}
}
return Result;
}
/**
* Adds an object to the Items array at the position specified by Index.
* Call Insert to add Item to the middle of the Items array.
* The Index parameter is a zero-based index, so the first position in the array has an index of 0.
* Insert adds the item at the indicated position, shifting the item that previously occupied that position, and all subsequent items, up.
* Insert increments Count and, if necessary, allocates memory by increasing the value of Capacity.
* To replace a NULL pointer in the array with a new item, without growing the Items array, set the Items property.
* @param Index Position where to add the item.
* @param AObject The item to insert.
*/
void __fastcall Insert(int Index, T AObject)
{
inherited::Insert(Index, AObject);
}
/**
* Call First to retrieve the first pointer in the Items array.
* @return A pointer to the first item.
*/
T __fastcall First(void)
{
return static_cast<T>(inherited::First());
}
/**
* Call Last to retrieve the last pointer in the Items array.
* @return A pointer to the last item.
*/
T __fastcall Last(void)
{
return static_cast<T>(inherited::Last());
}
/**
* Indexer operator for the Items in the List.
* @return A pointer to the corresponding Item.
*/
T operator[](int Index)
{
return static_cast<T>(Items[Index]);
}
/**
* Allows TObjectList to free objects when they are deleted from the list or the list is destroyed.
* OwnsObjects allows TObjectList to control the memory of its objects.
* If OwnsObjects is true (the default),
* calling Delete or Remove frees the deleted object in addition to removing it from the list.
* calling Clear frees all the objects in the list in addition to emptying the list.
* calling the destructor frees all the objects in the list in addition to destroying the TObjectList itself.
* assigning a new value to an index in Items frees the object that previously occupied that position in the list.
* Even if OwnsObjects is true, the Extract method can be used to remove objects from the list without freeing them.
*/
__property bool OwnsObjects = {read=FOwnsObjects, write=FOwnsObjects, nodefault};
/**
* Use Items to obtain a pointer to a specific object in the array.
* The Index parameter indicates the index of the object, where 0 is the index of the first object, 1 is the index of the second object, and so on.
* Set Items to change the reference at a specific location.
* Use Items with the Count property to iterate through all of the objects in the list.
*/
__property T Items[int Index] = {read=GetItem, write=SetItem};
};
/**
* A class for storing a list of TVoice.
*/
class TVoiceList : public TObjectList<TVoice*>
{
typedef TObjectList<TVoice*> inherited;
public:
/**
* Constructor.
* @param AOwnsObjects Value to initialize OwnsObjects.
* When no value is specified, TVoiceList is initialized with OwnsObjects set to true.
*/
__fastcall TVoiceList(bool AOwnsObjects = true) : inherited(AOwnsObjects) { }
/**
* Destructor.
*/
inline __fastcall virtual ~TVoiceList(void) { }
};
} /* namespace Mikmod */
using namespace Mikmod;
//---------------------------------------------------------------------------
#endif