OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
UserList.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef USER_LIST_H
12 #define USER_LIST_H
13 
14 /***********************************************************************
15  *
16  * UserList is a base class for classes which need to maintain a list
17  * of users of that particular instance. It provides 'checkinUser' and
18  * 'checkoutUser' methods which are called by the users of an instance
19  * of this class. UserList is templated on a 'key' (used to uniquely
20  * distinguish a particular user, provided in the checkin call) and on
21  * the type of the user. It stores a list of pointers to the users.
22  *
23  * When an instance of this class is deleted, it informs all users of
24  * its demise via a call to 'notifyUserOfDelete', specifying the unique
25  * ID of the UserList. This ID is generated when the UserList instance
26  * is created, and is returned to the user when they check in.
27  *
28  ***********************************************************************/
29 
30 // include files
31 #include "Utility/vmap.h"
32 #include "Utility/Unique.h"
33 #include "Utility/User.h"
34 
35 
36 // class definition
37 class UserList {
38 
39 public:
40  // useful typedefs
41  typedef User::ID_t Key;
44  // typedef UserList_t::const_iterator const_iterator_user;
46  typedef User::ID_t ID_t;
47 
48 public:
49  // constructor: just get unique ID for this object
50  UserList();
51 
52  // destructor: inform all users of our untimely demise
53  virtual ~UserList();
54 
55  //
56  // informative methods
57  //
58 
59  // return the number of users
61 
62  // return the ID of this userlist
63  ID_t getUserListID() const;
64 
65  // do we have a user with the given key? Return true if we do.
66  bool haveUser(Key key) const;
67 
68  // return the user with the given key
69  User& getUser(Key key);
70 
71  // return begin/end iterators for the users
74  // const_iterator_user begin_user() const;
75  // const_iterator_user end_user() const;
76 
77  //
78  // virtual checkin/checkout functions
79  //
80 
81  // Check in a new user with the given key. Check to make sure we do
82  // not already have that key. Return our UserList ID number. Derived
83  // classes can override this, but should call this base class version
84  // to actually store the user.
85  virtual ID_t checkinUser(User& user);
86 
87  // Check out a user, by removing them from our list. Check to make sure
88  // a user with the given key is in our list. If the second argument is
89  // true (by default it is not), the user is notified that they are
90  // being checked out (this may be useful if the person calling checkoutUser
91  // is not the user being checked out).
92  virtual void checkoutUser(Key key, bool informuser = false);
93 
94  // also checkout a user, by specifying the user to checkout instead of
95  // the user key. The key is obtained from the user in this case.
96  virtual void checkoutUser(const User& user, bool informuser = false);
97 
98 private:
99  // the list of users
101 
102  // our unique ID
104 };
105 
106 #endif // USER_LIST_H
107 
108 /***************************************************************************
109  * $RCSfile: UserList.h,v $ $Author: adelmann $
110  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $
111  * IPPL_VERSION_ID: $Id: UserList.h,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $
112  ***************************************************************************/
rep_type::size_type size_type
Definition: vmap.h:120
virtual ~UserList()
Definition: UserList.cpp:39
iterator_user end_user()
Definition: UserList.cpp:84
ID_t userlistID
Definition: UserList.h:103
ID_t getUserListID() const
Definition: UserList.cpp:54
UserList()
Definition: UserList.cpp:34
UserList_t::size_type size_type_user
Definition: UserList.h:45
UserList_t userlist
Definition: UserList.h:100
User & getUser(Key key)
Definition: UserList.cpp:68
Unique::type ID_t
Definition: User.h:35
size_type_user getNumUsers() const
Definition: UserList.cpp:47
User::ID_t Key
Definition: UserList.h:41
vmap< Key, User * > UserList_t
Definition: UserList.h:42
bool haveUser(Key key) const
Definition: UserList.cpp:61
virtual void checkoutUser(Key key, bool informuser=false)
Definition: UserList.cpp:124
Definition: User.h:31
UserList_t::iterator iterator_user
Definition: UserList.h:43
rep_type::iterator iterator
Definition: vmap.h:116
virtual ID_t checkinUser(User &user)
Definition: UserList.cpp:109
iterator_user begin_user()
Definition: UserList.cpp:77
User::ID_t ID_t
Definition: UserList.h:46