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

Represents a single group. A group has a name and zero or more users. Users are tracked by name. More...

#include <Mediator_Group_Classes.h>

Collaboration diagram for Group:
Collaboration graph

Public Member Functions

 Group ()
 Default constructor.
 
 Group (std::string name)
 Constructor.
 
std::string Name ()
 The name of the group (read-only).
 
StringList Users () const
 The names of users in this group (read-only).
 
bool ContainsUser (std::string name)
 Determine if the specified user is in this group. This is a case- sensitive search.
 
void AddUser (std::string name)
 Add the specified user to this group. If the user is already in the group, the operation is ignored.
 
void RemoveUser (std::string name)
 Remove a user from this group. If the user is not in the group then the operation is ignored.
 
bool Equals (const Group &group) const
 Determine if the name of the specified group matches this Group's name.
 
bool Equals (const std::string &name) const
 Determine if the given name matches this Group's name.
 

Private Member Functions

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 was not found with that name.
 

Private Attributes

std::string _groupName
 Name of this group.
 
StringList _users
 The list of users in this group.
 

Detailed Description

Represents a single group. A group has a name and zero or more users. Users are tracked by name.

Definition at line 26 of file Mediator_Group_Classes.h.

Constructor & Destructor Documentation

◆ Group() [1/2]

Group ( )
inline

Default constructor.

Definition at line 52 of file Mediator_Group_Classes.h.

◆ Group() [2/2]

Group ( std::string  name)
inline

Constructor.

Parameters
nameName of the group to use.

Definition at line 59 of file Mediator_Group_Classes.h.

Member Function Documentation

◆ _SearchForUser()

StringList::iterator _SearchForUser ( const std::string &  name)
inlineprivate

Get an iterator pointing to the user with the specified name. Returns std::end(_users) if the user was not found with that name.

Definition at line 43 of file Mediator_Group_Classes.h.

References Group::_users.

Referenced by UserList::FindUser(), and UserList::RemoveUser().

◆ AddUser()

void AddUser ( std::string  name)
inline

Add the specified user to this group. If the user is already in the group, the operation is ignored.

Parameters
nameName of the user to add. Cannot be null or empty.
Exceptions
ArgumentNullExceptionThe 'name' parameter must specify a user name.

Definition at line 98 of file Mediator_Group_Classes.h.

References Group::_users, and Group::ContainsUser().

Referenced by UserGroupMediator::AddUserToGroup().

◆ ContainsUser()

bool ContainsUser ( std::string  name)
inline

Determine if the specified user is in this group. This is a case- sensitive search.

Parameters
nameName of the user to look for.
Returns
Return true if the user is in this group; otherwise false.

Definition at line 86 of file Mediator_Group_Classes.h.

References Group::_users.

Referenced by Group::AddUser(), UserGroupMediator::GetGroupsWithUser(), UserGroupMediator::IsUserInGroup(), Group::RemoveUser(), and UserGroupMediator::RemoveUserFromAllGroups().

◆ Equals() [1/2]

bool Equals ( const Group group) const
inline

Determine if the name of the specified group matches this Group's name.

Parameters
groupA Group with which to compare names.
Returns
Return true if the names are equal (case-sensitive).

Definition at line 133 of file Mediator_Group_Classes.h.

References Group::_groupName.

Referenced by GroupList::_SearchForGroup().

◆ Equals() [2/2]

bool Equals ( const std::string &  name) const
inline

Determine if the given name matches this Group's name.

Parameters
nameA string containing the name of the Group.
Returns
Return true if the names are equal (case-sensitive).

Definition at line 143 of file Mediator_Group_Classes.h.

References Group::_groupName.

◆ Name()

std::string Name ( )
inline

The name of the group (read-only).

Definition at line 67 of file Mediator_Group_Classes.h.

References Group::_groupName.

Referenced by Visitor_Shop::PickupOrder(), Visitor_Shop::PlaceOrder(), and EntryInformation::ToString().

◆ RemoveUser()

void RemoveUser ( std::string  name)
inline

Remove a user from this group. If the user is not in the group then the operation is ignored.

Parameters
nameThe name of the user to remove.

Definition at line 118 of file Mediator_Group_Classes.h.

References Group::_users.

Referenced by UserGroupMediator::RemoveUserFromAllGroups(), and UserGroupMediator::RemoveUserFromGroup().

◆ Users()

StringList Users ( ) const
inline

The names of users in this group (read-only).

Definition at line 75 of file Mediator_Group_Classes.h.

References Group::_users.

Referenced by UserGroupMediator::GetUsersInGroup().

Member Data Documentation

◆ _groupName

std::string _groupName
private

Name of this group.

Definition at line 32 of file Mediator_Group_Classes.h.

Referenced by Group::__eq__(), Group::Equals(), and Group::Name().

◆ _users


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