AEBankFile.c++
2.25 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
/*****************************************************************************
* File: AEBank.c++
*
* AEBank Class Implementations
*
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "Assets.h"
#include "Mgrs.h"
/*****************************************************************************
*
* Initialization Routines
*
****************************************************************************/
AEBankFile::AEBankFile()
{
bankList = new RefList;
assert(bankList);
revision = 0;
classType = AL_BNKFILE_CLASS;
assert(theU64Dev->AllocHdwr(this,AL_BNKFILE_CLASS) == 0);
}
AEBankFile::~AEBankFile()
{
Node *node, *next;
AEBank *bank;
node = bankList->head;
while(node)
{
bank = (AEBank*)node->data;
bank->RemoveReference(this);
next = node->next;
delete node;
node = next;
}
delete bankList;
theU64Dev->DeallocHdwr(this);
}
/*****************************************************************************
*
* Asset's Methods
*
****************************************************************************/
void AEBankFile::AddBank(AEBank *bank)
{
bankList->Append(bank);
bank->AddReference(this);
}
void AEBankFile::RemoveBank(AEBank *bank)
{
bankList->RemoveByData(bank);
bank->RemoveReference(this);
}
void AEBankFile::SetRevision(int rev)
{
revision = rev;
}
int AEBankFile::GetRevision(void)
{
return revision;
}
int AEBankFile::GetNumBanks(void)
{
return bankList->count;
}
AssetPair* AEBankFile::GetBanks(int *numBanks)
{
int c = 0;
AssetPair *assets;
Node *node;
AEBank *bank;
if(bankList->count == 0)
return 0;
assets = (AssetPair*)malloc(sizeof(AssetPair) * bankList->count);
if(!assets)
{
fprintf(stderr,"Failure allocating memory for bank list\n");
return 0;
}
node = bankList->head;
while(node)
{
bank = (AEBank*)node->data;
assets[c].asset = bank;
assets[c].name = bank->GetName();
c++;
node = node->next;
}
assert(c == bankList->count);
*numBanks = c;
return assets;
}