Create and implemented userManager class

This commit is contained in:
2025-05-22 19:33:56 +02:00
parent 6ad501ec50
commit 40d58ab011
6 changed files with 135 additions and 4 deletions

94
src/usermanager.h Normal file
View File

@@ -0,0 +1,94 @@
#ifndef _USERMAN_H
#define _USERMAN_H
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include "locations.h"
std::vector<std::string> splitLogFile(const std::string& input, char delimiter);
class userManager
{
private:
std::map<std::string, bool> users;
public:
void addUserFromLogLine(std::string &line)
{
addUser(splitLogFile(line, '|').at(USER_LOG_LOCATION));
}
void addUser(std::string &user)
{
if (users.count(user) == 0)
{
users[user] = false;
}
}
void removeUser(std::string &user)
{
users.erase(user);
}
bool isContains(std::string &user)
{
return users.count(user) == 1;
}
void setUserFlagged(std::string &user)
{
if (users.count(user) == 1)
{
users[user] = true;
}
}
void setUserUnflagged(std::string &user)
{
if (users.count(user) == 1)
{
users[user] = false;
}
}
void unflagAllUsers()
{
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
it->second = false;
}
}
std::vector<std::string> getUsers()
{
std::vector<std::string> ret;
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
ret.push_back(it->first);
}
return ret;
}
std::vector<std::string> getFlaggedUsers()
{
std::vector<std::string> ret;
for (std::map<std::string, bool>::iterator it = users.begin(); it != users.end(); ++it)
{
if (it->second)
{
ret.push_back(it->first);
}
}
return ret;
}
};
#endif // _USERMAN_H