NumOfLogs()

This commit is contained in:
EntireTwix 2021-07-07 16:13:31 -07:00
parent d649613d2e
commit 85e3dc038c
2 changed files with 21 additions and 6 deletions

View file

@ -40,7 +40,8 @@ public:
std::string admin_account; std::string admin_account;
size_t NumOfUsers() const noexcept; size_t NumOfUsers() const noexcept;
uint64_t NumOfLogs() const noexcept; size_t NumOfLogs() const noexcept;
size_t SumBal() const noexcept;
#if CONSERVATIVE_DISK_SAVE #if CONSERVATIVE_DISK_SAVE
bool GetChangeState() const noexcept; bool GetChangeState() const noexcept;

View file

@ -2,7 +2,9 @@
using namespace drogon; using namespace drogon;
__attribute__((always_inline)) inline bool ValidUsrname(const std::string &name) noexcept #define INLINE __attribute__((always_inline)) inline
INLINE bool ValidUsrname(const std::string &name) noexcept
{ {
if (name.size() < min_name_size || name.size() > max_name_size) if (name.size() < min_name_size || name.size() > max_name_size)
{ {
@ -22,9 +24,9 @@ __attribute__((always_inline)) inline bool ValidUsrname(const std::string &name)
size_t Bank::NumOfUsers() const noexcept { return users.size(); } size_t Bank::NumOfUsers() const noexcept { return users.size(); }
//NOT THREAD SAFE //NOT THREAD SAFE
uint64_t Bank::NumOfLogs() const noexcept size_t Bank::NumOfLogs() const noexcept
{ {
uint64_t res = 0; size_t res = 0;
#if MAX_LOG_SIZE > 0 #if MAX_LOG_SIZE > 0
for (const auto &u : users) for (const auto &u : users)
{ {
@ -41,6 +43,17 @@ uint64_t Bank::NumOfLogs() const noexcept
return res; return res;
} }
//NOT THREAD SAFE
size_t Bank::SumBal() const noexcept
{
size_t res = 0;
for (const auto &u : users)
{
res += u.second.balance;
}
return res;
}
#if CONSERVATIVE_DISK_SAVE #if CONSERVATIVE_DISK_SAVE
bool Bank::GetChangeState() const noexcept bool Bank::GetChangeState() const noexcept
{ {
@ -233,7 +246,8 @@ BankResponse Bank::DelUser(const std::string &name) noexcept
uint32_t bal; uint32_t bal;
if (users.if_contains(name, [this, &bal](const User &u) { if (users.if_contains(name, [this, &bal](const User &u) {
bal = u.balance; bal = u.balance;
}) && bal) }) &&
bal)
{ {
users.modify_if(return_account, [ this, bal ](User & u)) users.modify_if(return_account, [ this, bal ](User & u))
{ {