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

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

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

Go to the source code of this file.

Classes

struct  UserList
 Represents a list of users. Call UserList_Initialize() to start and UserList_Clear() to release all resources and restore to empty state. More...
 

Macros

#define __MEDIATOR_USERLIST_H__
 

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

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

Definition in file Mediator_UserList.h.

Macro Definition Documentation

◆ __MEDIATOR_USERLIST_H__

#define __MEDIATOR_USERLIST_H__

Definition at line 8 of file Mediator_UserList.h.

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().