Use a Delete method for deletable objects

This commit is contained in:
Chris Robinson 2013-05-25 21:04:00 -07:00
parent 2da6caeaa6
commit 6571d80540
11 changed files with 28 additions and 96 deletions

View File

@ -243,9 +243,9 @@ static ALvoid ALchorusState_Process(ALchorusState *state, ALuint SamplesToDo, co
ProcessSinusoid(state, SamplesToDo, SamplesIn, SamplesOut);
}
static ALeffectStateFactory *ALchorusState_getCreator(void)
static void ALchorusState_Delete(ALchorusState *state)
{
return STATIC_CAST(ALeffectStateFactory, &ChorusFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState);
@ -267,13 +267,6 @@ static ALeffectState *ALchorusStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALchorusStateFactory_destroy(ALeffectState *effect)
{
ALchorusState *state = STATIC_UPCAST(ALchorusState, ALeffectState, effect);
ALchorusState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALchorusStateFactory);

View File

@ -85,9 +85,9 @@ static ALvoid ALdedicatedState_Process(ALdedicatedState *state, ALuint SamplesTo
}
}
static ALeffectStateFactory *ALdedicatedState_getCreator(void)
static void ALdedicatedState_Delete(ALdedicatedState *state)
{
return STATIC_CAST(ALeffectStateFactory, &DedicatedFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState);
@ -108,13 +108,6 @@ ALeffectState *ALdedicatedStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALdedicatedStateFactory_destroy(ALeffectState *effect)
{
ALdedicatedState *state = STATIC_UPCAST(ALdedicatedState, ALeffectState, effect);
ALdedicatedState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdedicatedStateFactory);

View File

@ -234,9 +234,9 @@ static ALvoid ALdistortionState_Process(ALdistortionState *state, ALuint Samples
}
}
static ALeffectStateFactory *ALdistortionState_getCreator(void)
static void ALdistortionState_Delete(ALdistortionState *state)
{
return STATIC_CAST(ALeffectStateFactory, &DistortionFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALdistortionState);
@ -263,13 +263,6 @@ static ALeffectState *ALdistortionStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALdistortionStateFactory_destroy(ALeffectState *effect)
{
ALdistortionState *state = STATIC_UPCAST(ALdistortionState, ALeffectState, effect);
ALdistortionState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdistortionStateFactory);

View File

@ -175,9 +175,9 @@ static ALvoid ALechoState_Process(ALechoState *state, ALuint SamplesToDo, const
state->Offset = offset;
}
static ALeffectStateFactory *ALechoState_getCreator(void)
static void ALechoState_Delete(ALechoState *state)
{
return STATIC_CAST(ALeffectStateFactory, &EchoFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALechoState);
@ -205,13 +205,6 @@ ALeffectState *ALechoStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALechoStateFactory_destroy(ALeffectState *effect)
{
ALechoState *state = STATIC_UPCAST(ALechoState, ALeffectState, effect);
ALechoState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALechoStateFactory);

View File

@ -270,9 +270,9 @@ static ALvoid ALequalizerState_Process(ALequalizerState *state, ALuint SamplesTo
}
}
static ALeffectStateFactory *ALequalizerState_getCreator(void)
static void ALequalizerState_Delete(ALequalizerState *state)
{
return STATIC_CAST(ALeffectStateFactory, &EqualizerFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALequalizerState);
@ -305,13 +305,6 @@ ALeffectState *ALequalizerStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALequalizerStateFactory_destroy(ALeffectState *effect)
{
ALequalizerState *state = STATIC_UPCAST(ALequalizerState, ALeffectState, effect);
ALequalizerState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALequalizerStateFactory);

View File

@ -243,9 +243,9 @@ static ALvoid ALflangerState_Process(ALflangerState *state, ALuint SamplesToDo,
ProcessSinusoid(state, SamplesToDo, SamplesIn, SamplesOut);
}
static ALeffectStateFactory *ALflangerState_getCreator(void)
static void ALflangerState_Delete(ALflangerState *state)
{
return STATIC_CAST(ALeffectStateFactory, &FlangerFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALflangerState);
@ -267,13 +267,6 @@ ALeffectState *ALflangerStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALflangerStateFactory_destroy(ALeffectState *effect)
{
ALflangerState *state = STATIC_UPCAST(ALflangerState, ALeffectState, effect);
ALflangerState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALflangerStateFactory);

View File

@ -197,9 +197,9 @@ static ALvoid ALmodulatorState_Process(ALmodulatorState *state, ALuint SamplesTo
}
}
static ALeffectStateFactory *ALmodulatorState_getCreator(void)
static void ALmodulatorState_Delete(ALmodulatorState *state)
{
return STATIC_CAST(ALeffectStateFactory, &ModulatorFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALmodulatorState);
@ -222,13 +222,6 @@ static ALeffectState *ALmodulatorStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALmodulatorStateFactory_destroy(ALeffectState *effect)
{
ALmodulatorState *state = STATIC_UPCAST(ALmodulatorState, ALeffectState, effect);
ALmodulatorState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALmodulatorStateFactory);

View File

@ -60,12 +60,10 @@ static ALvoid ALnullState_Process(ALnullState *state, ALuint samplesToDo, const
(void)samplesOut;
}
/* This returns the ALeffectStateFactory that creates these ALeffectState
* object types.
*/
static ALeffectStateFactory *ALnullState_getCreator(void)
/* This frees the memory used by the object, after it has been destructed. */
static void ALnullState_Delete(ALnullState *state)
{
return STATIC_CAST(ALeffectStateFactory, &NullFactory);
free(state);
}
/* Define the forwards and the ALeffectState vtable for this type. */
@ -85,14 +83,6 @@ ALeffectState *ALnullStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
/* Destroys (destructs and frees) the ALeffectState. */
static ALvoid ALnullStateFactory_destroy(ALeffectState *effect)
{
ALnullState *state = STATIC_UPCAST(ALnullState, ALeffectState, effect);
ALnullState_Destruct(state);
free(state);
}
/* Define the ALeffectStateFactory vtable for this type. */
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALnullStateFactory);

View File

@ -1174,9 +1174,9 @@ static ALvoid ALreverbState_Destruct(ALreverbState *State)
State->SampleBuffer = NULL;
}
static ALeffectStateFactory *ALreverbState_getCreator(void)
static void ALreverbState_Delete(ALreverbState *state)
{
return STATIC_CAST(ALeffectStateFactory, &ReverbFactory);
free(state);
}
DEFINE_ALEFFECTSTATE_VTABLE(ALreverbState);
@ -1274,13 +1274,6 @@ static ALeffectState *ALreverbStateFactory_create(void)
return STATIC_CAST(ALeffectState, state);
}
static ALvoid ALreverbStateFactory_destroy(ALeffectState *effect)
{
ALreverbState *state = STATIC_UPCAST(ALreverbState, ALeffectState, effect);
ALreverbState_Destruct(state);
free(state);
}
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALreverbStateFactory);

View File

@ -18,7 +18,8 @@ struct ALeffectStateVtable {
ALboolean (*const DeviceUpdate)(ALeffectState *state, ALCdevice *device);
ALvoid (*const Update)(ALeffectState *state, ALCdevice *device, const ALeffectslot *slot);
ALvoid (*const Process)(ALeffectState *state, ALuint samplesToDo, const ALfloat *restrict samplesIn, ALfloat (*restrict samplesOut)[BUFFERSIZE]);
ALeffectStateFactory *(*const getCreator)(void);
void (*const Delete)(ALeffectState *state);
};
struct ALeffectState {
@ -29,7 +30,6 @@ struct ALeffectState {
#define ALeffectState_DeviceUpdate(a,b) ((a)->vtbl->DeviceUpdate((a),(b)))
#define ALeffectState_Update(a,b,c) ((a)->vtbl->Update((a),(b),(c)))
#define ALeffectState_Process(a,b,c,d) ((a)->vtbl->Process((a),(b),(c),(d)))
#define ALeffectState_getCreator(a) ((a)->vtbl->getCreator())
#define DEFINE_ALEFFECTSTATE_VTABLE(T) \
static ALvoid T##_ALeffectState_Destruct(ALeffectState *state) \
@ -40,21 +40,20 @@ static ALvoid T##_ALeffectState_Update(ALeffectState *state, ALCdevice *device,
{ T##_Update(STATIC_UPCAST(T, ALeffectState, state), device, slot); } \
static ALvoid T##_ALeffectState_Process(ALeffectState *state, ALuint samplesToDo, const ALfloat *restrict samplesIn, ALfloat (*restrict samplesOut)[BUFFERSIZE]) \
{ T##_Process(STATIC_UPCAST(T, ALeffectState, state), samplesToDo, samplesIn, samplesOut); } \
static ALeffectStateFactory* T##_ALeffectState_getCreator(void) \
{ return T##_getCreator(); } \
static ALvoid T##_ALeffectState_Delete(ALeffectState *state) \
{ T##_Delete(STATIC_UPCAST(T, ALeffectState, state)); } \
\
static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
T##_ALeffectState_Destruct, \
T##_ALeffectState_DeviceUpdate, \
T##_ALeffectState_Update, \
T##_ALeffectState_Process, \
T##_ALeffectState_getCreator, \
T##_ALeffectState_Delete, \
}
struct ALeffectStateFactoryVtable {
ALeffectState *(*const create)(void);
ALvoid (*const destroy)(ALeffectState *state);
};
struct ALeffectStateFactory {
@ -62,17 +61,13 @@ struct ALeffectStateFactory {
};
#define ALeffectStateFactory_create(p) ((p)->vtbl->create())
#define ALeffectStateFactory_destroy(p,a) ((p)->vtbl->destroy((a)))
#define DEFINE_ALEFFECTSTATEFACTORY_VTABLE(T) \
static ALeffectState* T##_ALeffectStateFactory_create(void) \
{ return T##_create(); } \
static ALvoid T##_ALeffectStateFactory_destroy(ALeffectState *state) \
{ T##_destroy(state); } \
\
static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable = { \
T##_ALeffectStateFactory_create, \
T##_ALeffectStateFactory_destroy \
}

View File

@ -70,7 +70,10 @@ static const union {
#define SET_VTABLE1(T1, obj) ((obj)->vtbl = &(T1##_vtable))
#define SET_VTABLE2(T1, T2, obj) SET_VTABLE1(T1##_##T2, STATIC_CAST(T2, (obj)))
#define DELETE_OBJ(obj) ((obj)->vtbl->getCreator()->vtbl->destroy((obj)))
#define DELETE_OBJ(obj) do { \
(obj)->vtbl->Destruct((obj)); \
(obj)->vtbl->Delete((obj)); \
} while(0)
#ifdef _WIN32