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

IMplementation of the UserList support functions as used in the Mediator Pattern. More...

#include <memory.h>
#include <string.h>
#include "Mediator_UserList.h"
Include dependency graph for Mediator_UserList.c:

Go to the source code of this file.

Functions

void UserList_Initialize (UserList *userList)
 Initialize the given UserList object for initial use.
 
void UserList_Clear (UserList *userList)
 Clear the given UserList object to release all associated resources.
 
bool UserList_AddUser (UserList *userList, User *user)
 Add the specified User object to the specified UserList object. The list takes ownership of the User object and is responsible for releasing the memory associated with the User object.
 
int UserList_FindUser (UserList *userList, const char *userName)
 Search the given UserList object for the specified user by name and return the index of the user if found.
 
void UserList_RemoveUser (UserList *userList, int removeIndex)
 Remove the user at the specified index in the given UserList object.
 

Detailed Description

IMplementation of the UserList support functions as used in the Mediator Pattern.

Definition in file Mediator_UserList.c.

Function Documentation

◆ UserList_AddUser()

bool UserList_AddUser ( UserList userList,
User user 
)

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

Parameters
userListThe UserList object to which to add the user.
userThe User object to add to the list.

Definition at line 43 of file Mediator_UserList.c.

References UserList::allocated_count, UserList::users, and UserList::users_count.

Referenced by Users_AddUser().

◆ UserList_Clear()

void UserList_Clear ( UserList userList)

Clear the given UserList object to release all associated resources.

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

Parameters
userListThe UserList object to clear.

Definition at line 27 of file Mediator_UserList.c.

References User_Destroy(), UserList_Initialize(), UserList::users, and UserList::users_count.

Referenced by Users_Clear().

◆ UserList_FindUser()

int UserList_FindUser ( UserList userList,
const char *  userName 
)

Search the given UserList object for the specified user by name and return the index of the user if found.

Parameters
userListThe UserList object to search.
userNameThe name of the user to look for. This is a case- sensitive search.
Returns
Returns the index of the user in the user list if found; otherwise returns -1, indicating the user does not exist.

Definition at line 79 of file Mediator_UserList.c.

References User::Name, UserList::users, and UserList::users_count.

Referenced by Users_FindUser(), and Users_RemoveUser().

◆ UserList_Initialize()

void UserList_Initialize ( UserList userList)

Initialize the given UserList object for initial use.

Parameters
userListThe UserList object to initialize.

Definition at line 14 of file Mediator_UserList.c.

References UserList::allocated_count, UserList::users, and UserList::users_count.

Referenced by UserList_Clear().

◆ UserList_RemoveUser()

void UserList_RemoveUser ( UserList userList,
int  removeIndex 
)

Remove the user at the specified index in the given UserList object.

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

Parameters
userListThe UserList object to remove from.
removeIndexIndex of the user to remove. Use UserList_FindUser() to get this index.

Definition at line 101 of file Mediator_UserList.c.

References UserList::allocated_count, User_Destroy(), UserList::users, and UserList::users_count.

Referenced by Users_RemoveUser().