AeAssetBin.c++ 1.52 KB
#include <string.h>
#include <assert.h>

#include "GList.h"
#include "AeAssetBin.h"
#include "AeAsset.h"


AeAssetBin::AeAssetBin (TAssetType type, AeAssetBin * childBin)
{
    fType = type;
    fAssetList = new GList<AeAsset *>;
    fChildBin = childBin;
}


AeAssetBin::~AeAssetBin (void)
{
    if (fAssetList)
	delete fAssetList;
}


//
// If the asset is not already in the bin,
// append the asset and return true.
// Else return false to indicate that the
// asset already exists.
//
Boolean
AeAssetBin::AppendAsset (AeAsset * asset)
{
    assert (fAssetList);
    assert (asset);

    int		i;
    Boolean	found;

    if (!(found = fAssetList->Find (asset, i)))
	fAssetList->Append (asset);

    return !found;
}


void
AeAssetBin::DeleteAsset (AeAsset * asset)
{
    assert (fAssetList);
    assert (asset);

    if (asset)
    {
	fAssetList->Remove (asset);
	delete asset;
    }
}

    
Boolean
AeAssetBin::FindNamedAsset (const char * name, AeAsset* & asset)
{
    int i;

    assert (fAssetList);
    fAssetList->Start (i);

    while (fAssetList->Next (i, asset))
    {
	if (strcmp (name, asset->GetName()) == 0)
	    return True;
    }

    return False;
}


Boolean
AeAssetBin::IsBankType (void)
{
    switch (fType)
    {
	case kBankFileType:
	case kBankType:
	case kInstType:
	case kSoundType:
	case kEnvType:
	case kKeymapType:
	case kWaveType:
	case kLoopType:
	case kADPCMLoopType:
	case kADPCMBookType:
	    return True;
    }

    return False;
}


int
AeAssetBin::GetNumAssets (void)
{
    return fAssetList->GetNum ();
}