#include <set>
#include <string>
#include <list>
#include <iostream>
#include <iterator>
using namespace std;
using std::set;
using std::string;
using std::list;
class AccessList
{
public:
AccessList() {}
void addUser(const string& user);
void removeUser(const string& user);
bool isAllowed(const string& user) const;
list<string> getAllUsers() const;
protected:
set<string> mAllowed;
};
void AccessList::addUser(const string& user)
{
mAllowed.insert(user);
}
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);
}
int main(int argc, char** argv)
{
AccessList fileX;
fileX.addUser("A");
fileX.addUser("B");
fileX.addUser("C");
fileX.removeUser("D");
if (fileX.isAllowed("A")) {
cout << "nsolter has permissions\n";
}
if (fileX.isAllowed("B")) {
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);
}
|