8#ifndef __MEDIATOR_CLASS_H__
9#define __MEDIATOR_CLASS_H__
14#include "helpers/formatstring.h"
115 userName.c_str(), groupName.c_str());
120 if (foundGroup ==
nullptr)
122 std::string message =
Helpers::formatstring(
"Cannot add user '%s' to group '%s' as that group does not exist!",
123 userName.c_str(), groupName.c_str());
144 std::string message =
Helpers::formatstring(
"User '%s' does not exist. Cannot remove from group '%s'!",
145 userName.c_str(), groupName.c_str());
150 if (foundGroup ==
nullptr)
152 std::string message =
Helpers::formatstring(
"Cannot remove user '%s' from group '%s' as that group does not exist!",
153 userName.c_str(), groupName.c_str());
173 std::string message =
Helpers::formatstring(
"User '%s' does not exist. Cannot remove from all groups'!",
181 if (group !=
nullptr)
201 bool userInGroup =
false;
205 std::string message =
Helpers::formatstring(
"User '%s' does not exist. Cannot determine if user is in group '%s'!",
206 userName.c_str(), groupName.c_str());
211 if (foundGroup ==
nullptr)
213 std::string message =
Helpers::formatstring(
"Cannot determine if user '%s' is in group '%s' as that group does not exist!",
214 userName.c_str(), groupName.c_str());
235 std::string message =
Helpers::formatstring(
"User '%s' does not exist. Cannot get groups containing user!",
244 if (group !=
nullptr)
248 groupNames.push_back(groupName);
266 if (foundGroup ==
nullptr)
268 std::string message =
Helpers::formatstring(
"Cannot determine get users in group '%s' as that group does not exist!",
272 return foundGroup->
Users();
Implementation of the argumentinvalid_error exception.
Represents a single group. A group has a name and zero or more users. Users are tracked by name.
void RemoveUser(std::string name)
Remove a user from this group. If the user is not in the group then the operation is ignored.
void AddUser(std::string name)
Add the specified user to this group. If the user is already in the group, the operation is ignored.
bool ContainsUser(std::string name)
Determine if the specified user is in this group. This is a case- sensitive search.
StringList Users() const
The names of users in this group (read-only).
Represents a list of Groups.
void AddGroup(std::string name)
Add a group to the list using the given group name. Operation ignored if the group is already in the ...
StringList GroupNames()
The names of all groups contained in this list (read-only). The list is always sorted.
void RemoveGroup(std::string name)
Remove the specified group from the list. Operation ignored if the group is not in the list.
Group * FindGroup(std::string name)
Retrieve the Group instance for the specified group name. The found group may be altered so it must p...
A simple container for the user and group lists. This represents some entity external to the mediator...
Represents a list of users.
void RemoveUser(std::string name)
Remove the specified user name as a user. Operation ignored if user is not in the list.
User * FindUser(std::string name)
Retrieve the User instance for the specified user name. The found user may be altered so it must poin...
void AddUser(std::string name)
Add the specified user name as a user. Operation ignored if user is already in the list.
StringList UserNames()
The user names contained in this list (read-only). The list is always sorted.
Exception for arguments that are invalid.
std::vector< std::string > StringList
Typedef for a vector of std::string.
The namespace containing all Design Pattern Examples implemented in C++.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....