Design Pattern Examples
Overview of object-oriented design patterns
Observer_NumberChangedFunctionList.c File Reference

Implementation of the NumberChangedFunctionList structure's support functions, NumberChangedFunctionList_Initialize(), NumberChangedFunctionList_Clear(), NumberChangedFunctionList_Add(), NumberChangedFunctionList_Find(), NumberChangedFunctionList_Remove(), and NumberChangedFunctionList_Copy(), as used in the Observer Pattern. More...

#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include "Observer_NumberChangedFunctionList.h"
Include dependency graph for Observer_NumberChangedFunctionList.c:

Go to the source code of this file.

Functions

void NumberChangedFunctionList_Initialize (NumberChangedFunctionList *functionList)
 Initialize the given function pointer list.
 
void NumberChangedFunctionList_Clear (NumberChangedFunctionList *functionList)
 Clear the given function pointer list, releasing all associated memory. The function list can then be used for new function pointers.
 
bool NumberChangedFunctionList_Add (NumberChangedFunctionList *functionList, NumberChangedFunction function)
 Add a function pointer to the given function pointer list.
 
int NumberChangedFunctionList_Find (NumberChangedFunctionList *functionList, NumberChangedFunction function)
 Search the function list for the specified function pointer.
 
void NumberChangedFunctionList_Remove (NumberChangedFunctionList *functionList, int functionIndex)
 Removed the function pointer at the given index from the function pointer list.
 
bool NumberChangedFunctionList_Copy (NumberChangedFunctionList *sourceList, NumberChangedFunctionList *destinationList)
 Duplicate the given source function pointer list into the destination function pointer list.
 

Detailed Description

Function Documentation

◆ NumberChangedFunctionList_Add()

bool NumberChangedFunctionList_Add ( NumberChangedFunctionList functionList,
NumberChangedFunction  function 
)

Add a function pointer to the given function pointer list.

Parameters
functionListThe NumberChangedFunctionList object to add to.
functionThe NumberChangedFunction pointer to add.
Returns
Returns true if the function pointer was successfully added; otherwise, returns false, indicating an out of memory condition (or a NULL argument was passed in).

Definition at line 43 of file Observer_NumberChangedFunctionList.c.

References NumberChangedFunctionList::allocation_count, NumberChangedFunctionList::functions, and NumberChangedFunctionList::functions_count.

Referenced by NumberProducer_SubscribeToNumberChanged().

◆ NumberChangedFunctionList_Clear()

void NumberChangedFunctionList_Clear ( NumberChangedFunctionList functionList)

Clear the given function pointer list, releasing all associated memory. The function list can then be used for new function pointers.

Parameters
functionListThe NumberChangedFunctionList object to clear.

Definition at line 31 of file Observer_NumberChangedFunctionList.c.

References NumberChangedFunctionList::functions, and NumberChangedFunctionList_Initialize().

Referenced by _NumberProducer_NotifyNumberChanged(), and NumberProducer_Destroy().

◆ NumberChangedFunctionList_Copy()

bool NumberChangedFunctionList_Copy ( NumberChangedFunctionList sourceList,
NumberChangedFunctionList destinationList 
)

Duplicate the given source function pointer list into the destination function pointer list.

Parameters
sourceListThe NumberChangedFunctionList object to copy from.
destinationListThe NumberChangedFunctionList object to copy to.
Returns
Returns true if the copy was successful; otherwise, returns false indicating an out of memory condition (or a NULL argument was passed in).

Definition at line 122 of file Observer_NumberChangedFunctionList.c.

References NumberChangedFunctionList::allocation_count, NumberChangedFunctionList::functions, and NumberChangedFunctionList::functions_count.

Referenced by _NumberProducer_NotifyNumberChanged().

◆ NumberChangedFunctionList_Find()

int NumberChangedFunctionList_Find ( NumberChangedFunctionList functionList,
NumberChangedFunction  function 
)

Search the function list for the specified function pointer.

Parameters
functionListThe NumberChangedFunctionList object to search.
functionThe NumberChangedFunction pointer to search for.
Returns
Returns the index of the function pointer if found; otherwise, returns -1, indicating the function pointer is not in the function pointer list.

Definition at line 85 of file Observer_NumberChangedFunctionList.c.

References NumberChangedFunctionList::functions, and NumberChangedFunctionList::functions_count.

Referenced by NumberProducer_SubscribeToNumberChanged(), and NumberProducer_UnsubscribeFromNumberChanged().

◆ NumberChangedFunctionList_Initialize()

void NumberChangedFunctionList_Initialize ( NumberChangedFunctionList functionList)

Initialize the given function pointer list.

Parameters
functionListThe NumberChangedFunctionList object to initialize.

Definition at line 18 of file Observer_NumberChangedFunctionList.c.

References NumberChangedFunctionList::allocation_count, NumberChangedFunctionList::functions, and NumberChangedFunctionList::functions_count.

Referenced by NumberChangedFunctionList_Clear().

◆ NumberChangedFunctionList_Remove()

void NumberChangedFunctionList_Remove ( NumberChangedFunctionList functionList,
int  functionIndex 
)

Removed the function pointer at the given index from the function pointer list.

Parameters
functionListThe NumberChangedFunctionList object to remove from.
functionIndexThe index of the function pointer to remove. Get this index by calling the NumberChangedFunctionList_Find() function.

Definition at line 107 of file Observer_NumberChangedFunctionList.c.

References NumberChangedFunctionList::allocation_count, and NumberChangedFunctionList::functions.

Referenced by NumberProducer_UnsubscribeFromNumberChanged().