Design Pattern Examples
Overview of object-oriented design patterns
Mediator_GroupList.h File Reference

Declaration of the GroupList structure and the associated support functions as used in the Mediator Pattern. More...

#include <stdlib.h>
#include "Mediator_Group.h"
Include dependency graph for Mediator_GroupList.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GroupList
 Represents a list of groups. Call GroupList_Initialize() to start and GroupList_Clear() to release all resources and restore to empty state. More...
 

Macros

#define __MEDIATOR_GROUPLIST_H__
 

Functions

void GroupList_Initialize (GroupList *groupList)
 Initialize the given GroupList object for initial use.
 
void GroupList_Clear (GroupList *groupList)
 Clear the given GroupList object to release all associated resources.
 
bool GroupList_AddGroup (GroupList *groupList, Group *group)
 Add the specified Group object to the specified GroupList object. The list takes ownership of the Group object and is responsible for releasing the memory associated with the Group object.
 
int GroupList_FindGroup (GroupList *groupList, const char *groupName)
 Search the given GroupList object for the specified group by name and return the index of the group if found.
 
void GroupList_RemoveGroup (GroupList *groupList, int removeIndex)
 Remove the group at the specified index in the given GroupList object.
 

Detailed Description

Declaration of the GroupList structure and the associated support functions as used in the Mediator Pattern.

Definition in file Mediator_GroupList.h.

Macro Definition Documentation

◆ __MEDIATOR_GROUPLIST_H__

#define __MEDIATOR_GROUPLIST_H__

Definition at line 8 of file Mediator_GroupList.h.

Function Documentation

◆ GroupList_AddGroup()

bool GroupList_AddGroup ( GroupList groupList,
Group group 
)

Add the specified Group object to the specified GroupList object. The list takes ownership of the Group object and is responsible for releasing the memory associated with the Group object.

Parameters
groupListThe GroupList object to which to add the group.
groupThe Group object to add to the list.

Definition at line 42 of file Mediator_GroupList.c.

References GroupList::allocated_count, GroupList::groups, and GroupList::groups_count.

Referenced by Groups_AddGroup().

◆ GroupList_Clear()

void GroupList_Clear ( GroupList groupList)

Clear the given GroupList object to release all associated resources.

After this function returns, the object is an empty list ready to be used again.

Parameters
groupListThe GroupList object to clear.

Definition at line 26 of file Mediator_GroupList.c.

References Group_Destroy(), GroupList_Initialize(), GroupList::groups, and GroupList::groups_count.

Referenced by Groups_Clear().

◆ GroupList_FindGroup()

int GroupList_FindGroup ( GroupList groupList,
const char *  groupName 
)

Search the given GroupList object for the specified group by name and return the index of the group if found.

Parameters
groupListThe GroupList object to search.
groupNameThe name of the group to look for. This is a case- sensitive search.
Returns
Returns the index of the group in the group list if found; otherwise returns -1, indicating the group does not exist.

Definition at line 78 of file Mediator_GroupList.c.

References GroupList::groups, GroupList::groups_count, and Group::Name.

Referenced by Groups_AddGroup(), Groups_AddUserGroup(), Groups_FindGroup(), Groups_GetAllUsersInGroup(), Groups_RemoveGroup(), Groups_RemoveUserFromGroup(), and Groups_UserInGroup().

◆ GroupList_Initialize()

void GroupList_Initialize ( GroupList groupList)

Initialize the given GroupList object for initial use.

Parameters
groupListThe GroupList object to initialize.

Definition at line 13 of file Mediator_GroupList.c.

References GroupList::allocated_count, GroupList::groups, and GroupList::groups_count.

Referenced by GroupList_Clear().

◆ GroupList_RemoveGroup()

void GroupList_RemoveGroup ( GroupList groupList,
int  removeIndex 
)

Remove the group at the specified index in the given GroupList object.

Since this changes the list of groups, all index values after the given index are no longer valid.

Parameters
groupListThe GroupList object to remove from.
removeIndexIndex of the group to remove. Use GroupList_FindGroup() to get this index.

Definition at line 100 of file Mediator_GroupList.c.

References GroupList::allocated_count, Group_Destroy(), GroupList::groups, and GroupList::groups_count.

Referenced by Groups_RemoveGroup().