00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * This program was prepared by PSI. 00007 * All rights in the program are reserved by PSI. 00008 * Neither PSI nor the author(s) 00009 * makes any warranty, express or implied, or assumes any liability or 00010 * responsibility for the use of this software 00011 * 00012 * Visit http://www.acl.lanl.gov/POOMS for more details 00013 * 00014 ***************************************************************************/ 00015 00016 // -*- C++ -*- 00017 /*************************************************************************** 00018 * 00019 * The IPPL Framework 00020 * 00021 * 00022 * Visit http://people.web.psi.ch/adelmann/ for more details 00023 * 00024 ***************************************************************************/ 00025 00026 // include files 00027 #include "Utility/UserList.h" 00028 #include "Utility/PAssert.h" 00029 #include "Profile/Profiler.h" 00030 00031 00033 // constructor: just get unique ID for this object 00034 UserList::UserList() : userlistID(Unique::get()) { } 00035 00036 00038 // destructor: inform all users of our untimely demise 00039 UserList::~UserList() { 00040 for (iterator_user a=begin_user(); a != end_user(); ++a) 00041 (*a).second->notifyUserOfDelete(this); 00042 } 00043 00044 00046 // return the number of users 00047 UserList::size_type_user UserList::getNumUsers() const { 00048 return userlist.size(); 00049 } 00050 00051 00053 // return the ID of this userlist 00054 UserList::ID_t UserList::getUserListID() const { 00055 return userlistID; 00056 } 00057 00058 00060 // do we have a user with the given key? Return true if we do. 00061 bool UserList::haveUser(Key key) const { 00062 return (userlist.count(key) == 1); 00063 } 00064 00065 00067 // return the user with the given key 00068 User& UserList::getUser(Key key) { 00069 iterator_user user = userlist.find(key); 00070 PInsist(user != end_user(),"Failed to find key in UserList::getUser!!"); 00071 return *((*user).second); 00072 } 00073 00074 00076 // return begin/end iterators for the users 00077 UserList::iterator_user UserList::begin_user() { 00078 return userlist.begin(); 00079 } 00080 00081 00083 // return begin/end iterators for the users 00084 UserList::iterator_user UserList::end_user() { 00085 return userlist.end(); 00086 } 00087 00088 00089 /* 00091 // return begin/end iterators for the users 00092 UserList::const_iterator_user UserList::begin_user() const { 00093 return userlist.begin(); 00094 } 00095 00096 00098 // return begin/end iterators for the users 00099 UserList::const_iterator_user UserList::end_user() const { 00100 return userlist.end(); 00101 } 00102 */ 00103 00105 // Check in a new user with the given key. Check to make sure we do 00106 // not already have that key. Return our UserList ID number. Derived 00107 // classes can override this, but should call this base class version 00108 // to actually store the user. 00109 UserList::ID_t UserList::checkinUser(User& user) { 00110 TAU_PROFILE("UserList::checkinUser()", "UserList::ID_t (User )", TAU_UTILITY); 00111 Key key = user.get_Id(); 00112 if ( ! haveUser(key) ) 00113 userlist[key] = &user; 00114 return userlistID; 00115 } 00116 00117 00119 // Check out a user, by removing them from our list. Check to make sure 00120 // a user with the given key is in our list. If the second argument is 00121 // true (by default it is not), the user is notified that they are 00122 // being checked out (this may be useful if the person calling checkoutUser 00123 // is not the user being checked out). 00124 void UserList::checkoutUser(Key key, bool informuser) { 00125 TAU_PROFILE("UserList::checkoutUser()", "void (Key, bool )", TAU_UTILITY); 00126 iterator_user user = userlist.find(key); 00127 if (user != end_user()) { 00128 if (informuser) 00129 (*user).second->notifyUserOfDelete(this); 00130 userlist.erase(user); 00131 } 00132 } 00133 00134 00136 // also checkout a user, by specifying the user to checkout instead of 00137 // the user key. The key is obtained from the user in this case. 00138 void UserList::checkoutUser(const User& user, bool informuser) { 00139 TAU_PROFILE("UserList::checkoutUser()", "void (User, bool )", TAU_UTILITY ); 00140 checkoutUser(user.get_Id(), informuser); 00141 } 00142 00143 00144 /*************************************************************************** 00145 * $RCSfile: UserList.cpp,v $ $Author: adelmann $ 00146 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $ 00147 * IPPL_VERSION_ID: $Id: UserList.cpp,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $ 00148 ***************************************************************************/