AEBankFile.c++ 2.25 KB
/*****************************************************************************
 *  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;
    
}