The Pedigree Project  0.1
Group.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "Group.h"
21 #include "pedigree/kernel/utilities/Iterator.h"
22 #include "pedigree/kernel/utilities/utility.h"
23 
24 Group::Group(size_t gid, String name) : m_Gid(gid), m_Name(name), m_Users()
25 {
26 }
27 
28 Group::~Group()
29 {
30 }
31 
32 void Group::join(User *pUser)
33 {
34  m_Users.pushBack(pUser);
35 }
36 
37 void Group::leave(User *pUser)
38 {
39  for (List<User *>::Iterator it = m_Users.begin(); it != m_Users.end(); it++)
40  {
41  if (*it == pUser)
42  {
43  m_Users.erase(it);
44  return;
45  }
46  }
47 }
48 
49 bool Group::isMember(User *pUser)
50 {
51  for (List<User *>::Iterator it = m_Users.begin(); it != m_Users.end(); it++)
52  {
53  if (*it == pUser)
54  return true;
55  }
56  return false;
57 }
void pushBack(const T &value)
Definition: List.h:232
Iterator erase(Iterator &Iter)
Definition: List.h:343
void leave(User *pUser)
Definition: Group.cc:37
void join(User *pUser)
Definition: Group.cc:32
Definition: String.h:49
Definition: User.h:32
Definition: List.h:64
bool isMember(User *pUser)
Definition: Group.cc:49
Iterator begin()
Definition: List.h:123
Iterator end()
Definition: List.h:135
List< User * > m_Users
Definition: Group.h:73