OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
UserList.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 * This program was prepared by PSI.
7 * All rights in the program are reserved by PSI.
8 * Neither PSI nor the author(s)
9 * makes any warranty, express or implied, or assumes any liability or
10 * responsibility for the use of this software
11 *
12 * Visit www.amas.web.psi for more details
13 *
14 ***************************************************************************/
15
16// -*- C++ -*-
17/***************************************************************************
18 *
19 * The IPPL Framework
20 *
21 *
22 * Visit http://people.web.psi.ch/adelmann/ for more details
23 *
24 ***************************************************************************/
25
26// include files
27#include "Utility/UserList.h"
28#include "Utility/PAssert.h"
29
30
31
33// constructor: just get unique ID for this object
34UserList::UserList() : userlistID(Unique::get()) { }
35
36
38// destructor: inform all users of our untimely demise
40 for (iterator_user a=begin_user(); a != end_user(); ++a)
41 (*a).second->notifyUserOfDelete(this);
42}
43
44
46 // return the number of users
48 return userlist.size();
49}
50
51
53// return the ID of this userlist
55 return userlistID;
56}
57
58
60// do we have a user with the given key? Return true if we do.
61bool UserList::haveUser(Key key) const {
62 return (userlist.count(key) == 1);
63}
64
65
67// return the user with the given key
69 iterator_user user = userlist.find(key);
70 PInsist(user != end_user(),"Failed to find key in UserList::getUser!!");
71 return *((*user).second);
72}
73
74
76// return begin/end iterators for the users
78 return userlist.begin();
79}
80
81
83// return begin/end iterators for the users
85 return userlist.end();
86}
87
88
89/*
91// return begin/end iterators for the users
92UserList::const_iterator_user UserList::begin_user() const {
93 return userlist.begin();
94}
95
96
98// return begin/end iterators for the users
99UserList::const_iterator_user UserList::end_user() const {
100 return userlist.end();
101}
102*/
103
105// Check in a new user with the given key. Check to make sure we do
106// not already have that key. Return our UserList ID number. Derived
107// classes can override this, but should call this base class version
108// to actually store the user.
110
111 Key key = user.get_Id();
112 if ( ! haveUser(key) )
113 userlist[key] = &user;
114 return userlistID;
115}
116
117
119// Check out a user, by removing them from our list. Check to make sure
120// a user with the given key is in our list. If the second argument is
121// true (by default it is not), the user is notified that they are
122// being checked out (this may be useful if the person calling checkoutUser
123// is not the user being checked out).
124void UserList::checkoutUser(Key key, bool informuser) {
125
126 iterator_user user = userlist.find(key);
127 if (user != end_user()) {
128 if (informuser)
129 (*user).second->notifyUserOfDelete(this);
130 userlist.erase(user);
131 }
132}
133
134
136// also checkout a user, by specifying the user to checkout instead of
137// the user key. The key is obtained from the user in this case.
138void UserList::checkoutUser(const User& user, bool informuser) {
139
140 checkoutUser(user.get_Id(), informuser);
141}
142
143
144/***************************************************************************
145 * $RCSfile: UserList.cpp,v $ $Author: adelmann $
146 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $
147 * IPPL_VERSION_ID: $Id: UserList.cpp,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $
148 ***************************************************************************/
std::complex< double > a
#define PInsist(c, m)
Definition: PAssert.h:120
Definition: Unique.h:29
Definition: User.h:31
ID_t get_Id() const
Definition: User.h:46
bool haveUser(Key key) const
Definition: UserList.cpp:61
ID_t userlistID
Definition: UserList.h:103
iterator_user begin_user()
Definition: UserList.cpp:77
ID_t getUserListID() const
Definition: UserList.cpp:54
User::ID_t Key
Definition: UserList.h:41
virtual void checkoutUser(Key key, bool informuser=false)
Definition: UserList.cpp:124
UserList()
Definition: UserList.cpp:34
UserList_t::iterator iterator_user
Definition: UserList.h:43
virtual ~UserList()
Definition: UserList.cpp:39
UserList_t userlist
Definition: UserList.h:100
iterator_user end_user()
Definition: UserList.cpp:84
User::ID_t ID_t
Definition: UserList.h:46
size_type_user getNumUsers() const
Definition: UserList.cpp:47
UserList_t::size_type size_type_user
Definition: UserList.h:45
User & getUser(Key key)
Definition: UserList.cpp:68
virtual ID_t checkinUser(User &user)
Definition: UserList.cpp:109
void erase(iterator position_i)
Definition: vmap.hpp:165
size_type size() const
Definition: vmap.h:120
iterator end()
Definition: vmap.h:108
iterator find(const key_type &x)
Definition: vmap.hpp:214
size_type count(const key_type &x) const
Definition: vmap.hpp:313
iterator begin()
Definition: vmap.h:107