qswiki/permissions.h

107 satır
2.0 KiB
C
Ham Normal Görünüm Geçmiş

2018-11-03 17:12:20 +01:00
#ifndef PERMISSIONS_H
#define PERMISSIONS_H
#define PERM_CAN_READ 1 << 0
#define PERM_CAN_EDIT 1 << 1
#define PERM_CAN_PAGE_HISTORY 1 << 2
#define PERM_CAN_GLOBAL_HISTORY 1 << 3
#define PERM_CAN_DELETE 1 << 4
#define PERM_CAN_SEE_PAGE_LIST 1 << 5
#define PERM_CAN_CREATE 1 << 6
#define PERM_CAN_SEE_CATEGORY_LIST 1 << 7
#define PERM_CAN_SEE_LINKS_HERE 1 << 8
#define PERM_CAN_SEARCH 1 << 9
#include <string>
#include <map>
2018-11-03 17:12:20 +01:00
class Permissions
2018-11-03 17:12:20 +01:00
{
private:
int permissions = 0;
2018-11-03 17:12:20 +01:00
public:
Permissions()
{
this->permissions = 0;
}
Permissions(int permissions);
Permissions(const std::string &str);
Permissions(Permissions &&o)
{
this->permissions = o.permissions;
}
Permissions(const Permissions &o)
{
this->permissions = o.permissions;
}
Permissions &operator=(const Permissions &o)
{
this->permissions = o.permissions;
return *this;
}
Permissions &operator=(Permissions &&o)
{
this->permissions = o.permissions;
return *this;
}
int getPermissions() const
{
return this->permissions;
}
bool canRead() const
{
return this->permissions & PERM_CAN_READ;
}
bool canEdit() const
{
return this->permissions & PERM_CAN_EDIT;
}
bool canSeePageHistory() const
{
return this->permissions & PERM_CAN_PAGE_HISTORY;
}
bool canSeeGlobalHistory() const
{
return this->permissions & PERM_CAN_GLOBAL_HISTORY;
}
bool canCreate() const
{
return this->permissions & PERM_CAN_CREATE;
}
bool canSeeCategoryList() const
{
return this->permissions & PERM_CAN_SEE_CATEGORY_LIST;
}
bool canSeeLinksHere() const
{
return this->permissions & PERM_CAN_SEE_LINKS_HERE;
}
bool canSearch() const
{
return this->permissions & PERM_CAN_SEARCH;
}
bool canDelete() const
{
return this->permissions & PERM_CAN_DELETE;
}
bool canSeePageList() const
{
return this->permissions & PERM_CAN_SEE_PAGE_LIST;
}
std::string toString() const
{
return Permissions::toString(this->permissions);
}
static std::string toString(int perms);
2018-11-03 17:12:20 +01:00
};
#endif // PERMISSIONS_H