00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * 00007 * Visit http://people.web.psi.ch/adelmann/ for more details 00008 * 00009 ***************************************************************************/ 00010 00011 #ifndef USER_LIST_H 00012 #define USER_LIST_H 00013 00014 /*********************************************************************** 00015 * 00016 * UserList is a base class for classes which need to maintain a list 00017 * of users of that particular instance. It provides 'checkinUser' and 00018 * 'checkoutUser' methods which are called by the users of an instance 00019 * of this class. UserList is templated on a 'key' (used to uniquely 00020 * distinguish a particular user, provided in the checkin call) and on 00021 * the type of the user. It stores a list of pointers to the users. 00022 * 00023 * When an instance of this class is deleted, it informs all users of 00024 * its demise via a call to 'notifyUserOfDelete', specifying the unique 00025 * ID of the UserList. This ID is generated when the UserList instance 00026 * is created, and is returned to the user when they check in. 00027 * 00028 ***********************************************************************/ 00029 00030 // include files 00031 #include "Utility/vmap.h" 00032 #include "Utility/Unique.h" 00033 #include "Utility/User.h" 00034 00035 00036 // class definition 00037 class UserList { 00038 00039 public: 00040 // useful typedefs 00041 typedef User::ID_t Key; 00042 typedef vmap<Key, User *> UserList_t; 00043 typedef UserList_t::iterator iterator_user; 00044 // typedef UserList_t::const_iterator const_iterator_user; 00045 typedef UserList_t::size_type size_type_user; 00046 typedef User::ID_t ID_t; 00047 00048 public: 00049 // constructor: just get unique ID for this object 00050 UserList(); 00051 00052 // destructor: inform all users of our untimely demise 00053 virtual ~UserList(); 00054 00055 // 00056 // informative methods 00057 // 00058 00059 // return the number of users 00060 size_type_user getNumUsers() const; 00061 00062 // return the ID of this userlist 00063 ID_t getUserListID() const; 00064 00065 // do we have a user with the given key? Return true if we do. 00066 bool haveUser(Key key) const; 00067 00068 // return the user with the given key 00069 User& getUser(Key key); 00070 00071 // return begin/end iterators for the users 00072 iterator_user begin_user(); 00073 iterator_user end_user(); 00074 // const_iterator_user begin_user() const; 00075 // const_iterator_user end_user() const; 00076 00077 // 00078 // virtual checkin/checkout functions 00079 // 00080 00081 // Check in a new user with the given key. Check to make sure we do 00082 // not already have that key. Return our UserList ID number. Derived 00083 // classes can override this, but should call this base class version 00084 // to actually store the user. 00085 virtual ID_t checkinUser(User& user); 00086 00087 // Check out a user, by removing them from our list. Check to make sure 00088 // a user with the given key is in our list. If the second argument is 00089 // true (by default it is not), the user is notified that they are 00090 // being checked out (this may be useful if the person calling checkoutUser 00091 // is not the user being checked out). 00092 virtual void checkoutUser(Key key, bool informuser = false); 00093 00094 // also checkout a user, by specifying the user to checkout instead of 00095 // the user key. The key is obtained from the user in this case. 00096 virtual void checkoutUser(const User& user, bool informuser = false); 00097 00098 private: 00099 // the list of users 00100 UserList_t userlist; 00101 00102 // our unique ID 00103 ID_t userlistID; 00104 }; 00105 00106 #endif // USER_LIST_H 00107 00108 /*************************************************************************** 00109 * $RCSfile: UserList.h,v $ $Author: adelmann $ 00110 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $ 00111 * IPPL_VERSION_ID: $Id: UserList.h,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $ 00112 ***************************************************************************/