Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Professional C++ [eng].pdf
Скачиваний:
1715
Добавлен:
16.08.2013
Размер:
11.09 Mб
Скачать

Chapter 21

void AccessList::removeUser(const string& user)

{

mAllowed.erase(user);

}

bool AccessList::isAllowed(const string& user) const

{

return (mAllowed.count(user) == 1);

}

list<string> AccessList::getAllUsers() const

{

list<string> users;

users.insert(users.end(), mAllowed.begin(), mAllowed.end()); return (users);

}

Finally, here is a simple test program:

#include “AccessList.h” #include <iostream> #include <iterator> using namespace std;

int main(int argc, char** argv)

{

AccessList fileX;

fileX.addUser(“nsolter”);

fileX.addUser(“klep”);

fileX.addUser(“baduser”);

fileX.removeUser(“baduser”);

if (fileX.isAllowed(“nsolter”)) {

cout << “nsolter has permissions\n”;

}

if (fileX.isAllowed(“baduser”)) {

cout << “baduser has permissions\n”;

}

list<string> users = fileX.getAllUsers();

for (list<string>::const_iterator it = users.begin(); it != users.end(); ++it) {

cout << *it << “ “;

}

cout << endl;

return (0);

}

multiset

The multiset is to the set what the multimap is to the map. The multiset supports all the operations of the set, but it allows multiple elements that are equal to each other to be stored in the container

610