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

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

Include dependency graph for Mediator_Group.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Group
 Represents a single group. A group has a name and zero or more users. Users are tracked by name. More...
 

Macros

#define __MEDIATOR_GROUP_H__
 

Functions

GroupGroup_Create (const char *groupName)
 Create a new Group object with the specified name.
 
void Group_Destroy (Group *group)
 Release the memory of the specified Group object. After this function returns, the pointer to the Group object is no longer valid.
 
bool Group_AddUser (Group *group, const char *userName)
 Add a user to the specified group. Does nothing if the user is already in the group.
 
int Group_FindUser (Group *group, const char *userName)
 Search the specified group for the specified user.
 
void Group_RemoveUser (Group *group, int removeIndex)
 Remove a user from the specified group. Does nothing if the user is not in the group.
 
bool Group_GetAllUsers (Group *group, StringList *users)
 Retrieve the names of all users in the group.
 

Detailed Description

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

Definition in file Mediator_Group.h.

Macro Definition Documentation

◆ __MEDIATOR_GROUP_H__

#define __MEDIATOR_GROUP_H__

Definition at line 8 of file Mediator_Group.h.

Function Documentation

◆ Group_AddUser()

bool Group_AddUser ( Group group,
const char *  userName 
)

Add a user to the specified group. Does nothing if the user is already in the group.

Parameters
groupThe Group object to add to.
userNameName of the user to add.
Returns
Returns true if the user was added (or already present); otherwise, returns false, indicating an out of memory error condition.

Definition at line 46 of file Mediator_Group.c.

References StringList_AddString(), and Group::Users.

Referenced by Groups_AddUserGroup().

◆ Group_Create()

Group * Group_Create ( const char *  groupName)

Create a new Group object with the specified name.

Parameters
groupNameName of the group.
Returns
Returns a pointer to a new Group object if successful; otherwise, returns NULL (out of memory condition). Call Group_Destroy() to free the memory of the object when done with it.

Definition at line 14 of file Mediator_Group.c.

References Group::Name, StringList_Initialize(), and Group::Users.

Referenced by Groups_AddGroup().

◆ Group_Destroy()

void Group_Destroy ( Group group)

Release the memory of the specified Group object. After this function returns, the pointer to the Group object is no longer valid.

Parameters
groupThe Group object to free.

Definition at line 34 of file Mediator_Group.c.

References StringList_Clear(), and Group::Users.

Referenced by GroupList_Clear(), GroupList_RemoveGroup(), and Groups_AddGroup().

◆ Group_FindUser()

int Group_FindUser ( Group group,
const char *  userName 
)

Search the specified group for the specified user.

Parameters
groupThe Group object to search.
userNameThe name of the user to find.
Returns
Returns an index of the user in the group if found; otherwise, returns -1, indicating the user is not in the group.

Definition at line 60 of file Mediator_Group.c.

References StringList_Find(), and Group::Users.

Referenced by Groups_GetGroupsWithUser(), Groups_RemoveUserFromAllGroups(), Groups_RemoveUserFromGroup(), and Groups_UserInGroup().

◆ Group_GetAllUsers()

bool Group_GetAllUsers ( Group group,
StringList users 
)

Retrieve the names of all users in the group.

Parameters
groupThe Group object to examine.
usersA StringList object to fill in with the names of the users in the list.
Returns
Returns true if the users where gathered; otherwise, returns false, indicating an out of memory error condition.

Definition at line 87 of file Mediator_Group.c.

References StringList_AddString(), and Group::Users.

Referenced by Groups_GetAllUsersInGroup().

◆ Group_RemoveUser()

void Group_RemoveUser ( Group group,
int  removeIndex 
)

Remove a user from the specified group. Does nothing if the user is not in the group.

Parameters
groupThe Group object to remove from.
removeIndexIndex of the user to remove. Call Group_FindUser() to get the index.

Definition at line 75 of file Mediator_Group.c.

References StringList_Remove(), and Group::Users.

Referenced by Groups_RemoveUserFromAllGroups(), and Groups_RemoveUserFromGroup().