Design Pattern Examples
Overview of object-oriented design patterns
UserGroupMediator Class Reference

Represents the mediator between caller, users, and groups. All users and groups are identified by string name. The names are case-sensitive. More...

#include <Mediator_Class.h>

Collaboration diagram for UserGroupMediator:
Collaboration graph

Public Member Functions

void AddUser (std::string name)
 Add a user to the list of known users. If the name is already in the list of users, the request to add is ignored.
 
void RemoveUser (std::string name)
 Removes the specified user from the list of known users, if the user exists. Also removes the user from all groups.
 
void AddGroup (std::string name)
 Add a group to the list of known groups. If the group is already in the list, the request to add is ignored.
 
void RemoveGroup (std::string name)
 Remove the specified group from the list of known groups if the group exists.
 
void AddUserToGroup (std::string userName, std::string groupName)
 Add the specified user to the specified group. If the user is already in the group, do nothing. The user must exist.
 
void RemoveUserFromGroup (std::string userName, std::string groupName)
 Remove the specified user from the specified group.
 
void RemoveUserFromAllGroups (std::string userName)
 Remove the specified user from all existing groups.
 
bool IsUserInGroup (std::string userName, std::string groupName)
 Determine if the specified user is in the specified group.
 
StringList GetGroupsWithUser (std::string userName)
 Retrieve a list of all groups that contain the specified user.
 
StringList GetUsersInGroup (std::string groupName)
 Retrieve a list of users in the specified group.
 
StringList GetAllGroups ()
 Retrieve a list of all known groups.
 
StringList GetAllUsers ()
 Retrieve a list of all known users.
 

Private Attributes

UserGroupsContainer _userGroupsContainer
 

Detailed Description

Represents the mediator between caller, users, and groups. All users and groups are identified by string name. The names are case-sensitive.

Definition at line 45 of file Mediator_Class.h.

Member Function Documentation

◆ AddGroup()

void AddGroup ( std::string  name)
inline

Add a group to the list of known groups. If the group is already in the list, the request to add is ignored.

Exceptions
ArgumentNullExceptionThe 'name' parameter cannot be null or empty.
Parameters
nameName of the user to add. Must not be null or empty.

Definition at line 83 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, GroupList::AddGroup(), and UserGroupsContainer::Groups.

◆ AddUser()

void AddUser ( std::string  name)
inline

Add a user to the list of known users. If the name is already in the list of users, the request to add is ignored.

Parameters
nameName of the user to add. Must not be null or empty.
Exceptions
ArgumentNullExceptionThe 'name' parameter cannot be null or empty.

Definition at line 59 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, UserList::AddUser(), and UserGroupsContainer::Users.

◆ AddUserToGroup()

void AddUserToGroup ( std::string  userName,
std::string  groupName 
)
inline

Add the specified user to the specified group. If the user is already in the group, do nothing. The user must exist.

Parameters
userNameName of user to add. Must be an existing user.
groupNameName of group to add user to. Must be an existing group.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 107 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, Group::AddUser(), GroupList::FindGroup(), UserList::FindUser(), Helpers::formatstring(), UserGroupsContainer::Groups, and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ GetAllGroups()

StringList GetAllGroups ( )
inline

Retrieve a list of all known groups.

Returns
An array of group names.

Definition at line 280 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, GroupList::GroupNames(), and UserGroupsContainer::Groups.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ GetAllUsers()

StringList GetAllUsers ( )
inline

Retrieve a list of all known users.

Returns
An array of user names.

Definition at line 290 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, UserList::UserNames(), and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ GetGroupsWithUser()

StringList GetGroupsWithUser ( std::string  userName)
inline

Retrieve a list of all groups that contain the specified user.

Parameters
userNameName of the user to look for. Must be an existing user.
Returns
An array of group names containing the user. Array is empty if the user is not found in any group.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 231 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, Group::ContainsUser(), GroupList::FindGroup(), UserList::FindUser(), Helpers::formatstring(), GroupList::GroupNames(), UserGroupsContainer::Groups, and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ GetUsersInGroup()

StringList GetUsersInGroup ( std::string  groupName)
inline

Retrieve a list of users in the specified group.

Parameters
groupNameName of the group to examine. Must be an existing group.
Returns
Returns an array of user names. The array can be empty if no users are in the group.
Exceptions
ArgumentExceptionGroup does not exist.

Definition at line 263 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, GroupList::FindGroup(), Helpers::formatstring(), UserGroupsContainer::Groups, and Group::Users().

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ IsUserInGroup()

bool IsUserInGroup ( std::string  userName,
std::string  groupName 
)
inline

Determine if the specified user is in the specified group.

Parameters
userNameName of user to find. Must be an existing user.
groupNameName of group to look in. Must be an existing group.
Returns
Returns true if the user is in the group; otherwise, returns false.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 199 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, Group::ContainsUser(), GroupList::FindGroup(), UserList::FindUser(), Helpers::formatstring(), UserGroupsContainer::Groups, and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ RemoveGroup()

void RemoveGroup ( std::string  name)
inline

Remove the specified group from the list of known groups if the group exists.

Parameters
nameName of group to remove.

Definition at line 94 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, UserGroupsContainer::Groups, and GroupList::RemoveGroup().

◆ RemoveUser()

void RemoveUser ( std::string  name)
inline

Removes the specified user from the list of known users, if the user exists. Also removes the user from all groups.

Parameters
nameName of user to remove.

Definition at line 70 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, UserList::RemoveUser(), UserGroupMediator::RemoveUserFromAllGroups(), and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

◆ RemoveUserFromAllGroups()

void RemoveUserFromAllGroups ( std::string  userName)
inline

Remove the specified user from all existing groups.

Parameters
userNameName of user to remove. Must be an existing user.
Exceptions
ArgumentExceptionUser does not exist.

Definition at line 166 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, Group::ContainsUser(), GroupList::FindGroup(), UserList::FindUser(), Helpers::formatstring(), GroupList::GroupNames(), UserGroupsContainer::Groups, Group::RemoveUser(), and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise(), and UserGroupMediator::RemoveUser().

◆ RemoveUserFromGroup()

void RemoveUserFromGroup ( std::string  userName,
std::string  groupName 
)
inline

Remove the specified user from the specified group.

Parameters
userNameName of user to remove. Must be an existing user.
groupNameName of group to remove user from. Must be an existing group.
Exceptions
ArgumentExceptionUser or group does not exist.

Definition at line 137 of file Mediator_Class.h.

References UserGroupMediator::_userGroupsContainer, GroupList::FindGroup(), UserList::FindUser(), Helpers::formatstring(), UserGroupsContainer::Groups, Group::RemoveUser(), and UserGroupsContainer::Users.

Referenced by DesignPatternExamples_cpp::Mediator_Exercise().

Member Data Documentation

◆ _userGroupsContainer


The documentation for this class was generated from the following file: