8#ifndef __MEDIATOR_GROUP_CLASSES_H__
9#define __MEDIATOR_GROUP_CLASSES_H__
17#include "helpers/stringlist.h"
45 return std::find(std::begin(
_users), std::end(
_users), name);
88 StringList::iterator foundIter = std::find(std::begin(
_users), std::end(
_users), name);
89 return foundIter != std::end(
_users);
103 "Must specify a user name to add it to the group.");
120 StringList::iterator foundIter = std::find(std::begin(
_users), std::end(
_users), name);
121 if (foundIter != std::end(
_users))
143 bool Equals(
const std::string& name)
const
175 [name](
const Group& g)
193 groupNames.push_back(group.Name());
195 std::sort(std::begin(groupNames), std::end(groupNames),
196 [](
const std::string& first,
const std::string& second)
213 Group* foundGroup =
nullptr;
215 if (foundIter != std::end(
_groups))
217 foundGroup = &(*foundIter);
234 "Must specify a group name to add it to the group list.");
251 if (foundIter != std::end(
_groups))
Implementation of the argumentnull_error exception.
Represents a single group. A group has a name and zero or more users. Users are tracked by name.
Group()
Default constructor.
bool Equals(const std::string &name) const
Determine if the given name matches this Group's 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.
std::string _groupName
Name of this group.
bool Equals(const Group &group) const
Determine if the name of the specified group matches this Group's name.
Group(std::string name)
Constructor.
bool ContainsUser(std::string name)
Determine if the specified user is in this group. This is a case- sensitive search.
StringList _users
The list of users in this group.
StringList::iterator _SearchForUser(const std::string &name)
Get an iterator pointing to the user with the specified name. Returns std::end(_users) if the user wa...
StringList Users() const
The names of users in this group (read-only).
std::string Name()
The name of the 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.
std::vector< Group > _groups
The list of groups.
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...
std::vector< Group >::iterator _SearchForGroup(const std::string &name)
Get an iterator pointing to the group with the specified name. Returns std::end(_groups) if the group...
Exception for arguments that are null.
std::vector< std::string > StringList
Typedef for a vector of std::string.
The namespace containing all Design Pattern Examples implemented in C++.
int stricmp(const char *first, const char *second)
Compare two strings in a case-insensitive manner to determine their alphabetical order relative to ea...
Declaration of the stricmp function, case-insensitive string comparison for narrow character strings.