Simple permission sorting.

This commit is contained in:
Relintai 2021-11-02 12:26:26 +01:00
parent 9aa410c0cd
commit 7fcd38fff7
4 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,13 @@
#include "rbac_permission.h"
bool RBACPermission::is_smaller(const Ref<RBACPermission> &b) const {
if (!b.is_valid()) {
return true;
}
return sort_order < b->sort_order;
}
RBACPermission::RBACPermission() :
Resource() {

View File

@ -17,6 +17,8 @@ public:
int sort_order;
int permissions;
bool is_smaller(const Ref<RBACPermission> &b) const;
RBACPermission();
~RBACPermission();
};

View File

@ -1,5 +1,15 @@
#include "rbac_rank.h"
void RBACRank::sort_permissions() {
for (int i = 0; i < permissions.size(); ++i) {
for (int j = i + 1; j < permissions.size(); ++j) {
if (permissions[j]->is_smaller(permissions[i])) {
permissions.swap(i, j);
}
}
}
}
RBACRank::RBACRank() :
Resource() {

View File

@ -22,6 +22,8 @@ public:
Vector<Ref<RBACPermission> > permissions;
void sort_permissions();
RBACRank();
~RBACRank();
};