mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-23 04:57:09 +11:00
✨ NumOfLogs()
This commit is contained in:
parent
d649613d2e
commit
85e3dc038c
2 changed files with 21 additions and 6 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
24
src/bank.cpp
24
src/bank.cpp
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
@ -177,7 +190,7 @@ BankResponse Bank::ImpactBal(const std::string &name, int64_t amount) noexcept
|
||||||
{
|
{
|
||||||
return {k400BadRequest, "\"Amount cannot be 0\""};
|
return {k400BadRequest, "\"Amount cannot be 0\""};
|
||||||
}
|
}
|
||||||
if (users.modify_if(name, [amount](User &u) { u.balance < (amount*-1)? u.balance = 0 : u.balance += amount; }))
|
if (users.modify_if(name, [amount](User &u) { u.balance < (amount * -1) ? u.balance = 0 : u.balance += amount; }))
|
||||||
{
|
{
|
||||||
#if CONSERVATIVE_DISK_SAVE
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
#if MULTI_THREADED
|
#if MULTI_THREADED
|
||||||
|
|
@ -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))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue