mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
💄 NumOfUsers() & NumOfLogs() for loading output
This commit is contained in:
parent
c9562d26c7
commit
b6344da31d
3 changed files with 37 additions and 18 deletions
|
|
@ -41,6 +41,9 @@ private:
|
|||
public:
|
||||
std::string admin_account;
|
||||
|
||||
size_t NumOfUsers() const noexcept;
|
||||
uint64_t NumOfLogs() const noexcept;
|
||||
|
||||
#if CONSERVATIVE_DISK_SAVE
|
||||
bool GetChangeState() const noexcept;
|
||||
#endif
|
||||
|
|
|
|||
33
main.cpp
33
main.cpp
|
|
@ -28,21 +28,6 @@ void SaveSig(int s)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cout
|
||||
<< "\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled")
|
||||
<< "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled")
|
||||
<< "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled")
|
||||
<< "\nSSE 3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled")
|
||||
<< "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled")
|
||||
<< "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled")
|
||||
#if MULTI_THREADED
|
||||
<< "\n\nThreads : " << get_nprocs() + 1
|
||||
<< "\nMulti threading : enabled"
|
||||
#else
|
||||
<< "\n\nThreads : " << 2
|
||||
<< "\nMulti threading : disabled"
|
||||
#endif
|
||||
<< std::endl; //flushing before EventLoop
|
||||
|
||||
static_assert(bool(MAX_LOG_SIZE) == bool(PRE_LOG_SIZE), "You must either utilize both or neither logging variables.\n");
|
||||
static_assert(MAX_LOG_SIZE >= PRE_LOG_SIZE, "The maximum log size must be larger than or equal to the amount preallocated.\n");
|
||||
|
|
@ -58,10 +43,28 @@ int main(int argc, char **argv)
|
|||
std::cerr << "ERROR: CCash MUST be ran as root\n";
|
||||
return 0;
|
||||
}
|
||||
std::cout
|
||||
<< "\nAVX : " << (__builtin_cpu_supports("avx") ? "enabled" : "disabled")
|
||||
<< "\nAVX 2 : " << (__builtin_cpu_supports("avx2") ? "enabled" : "disabled")
|
||||
<< "\nSSE 2 : " << (__builtin_cpu_supports("sse2") ? "enabled" : "disabled")
|
||||
<< "\nSSE 3 : " << (__builtin_cpu_supports("sse3") ? "enabled" : "disabled")
|
||||
<< "\nSSE 4.1 : " << (__builtin_cpu_supports("sse4.1") ? "enabled" : "disabled")
|
||||
<< "\nSSE 4.2 : " << (__builtin_cpu_supports("sse4.2") ? "enabled" : "disabled")
|
||||
#if MULTI_THREADED
|
||||
<< "\n\nThreads : " << get_nprocs() + 1
|
||||
<< "\nMulti threading : enabled";
|
||||
#else
|
||||
<< "\n\nThreads : " << 2
|
||||
<< "\nMulti threading : disabled";
|
||||
#endif
|
||||
|
||||
//Loading users from users.json
|
||||
bank.Load();
|
||||
|
||||
std::cout << "\n\nLoaded " << bank.NumOfUsers() << " Users"
|
||||
<< "\nLoaded " << bank.NumOfLogs() << " Logs"
|
||||
<< std::endl; //flushing before EventLoop
|
||||
|
||||
//Sig handling
|
||||
struct sigaction sigIntHandler;
|
||||
|
||||
|
|
|
|||
19
src/bank.cpp
19
src/bank.cpp
|
|
@ -1,5 +1,7 @@
|
|||
#include "bank.h"
|
||||
|
||||
using namespace drogon;
|
||||
|
||||
__attribute__((always_inline)) inline bool ValidUsrname(const std::string &name) noexcept
|
||||
{
|
||||
if (name.size() < min_name_size || name.size() > max_name_size)
|
||||
|
|
@ -16,7 +18,19 @@ __attribute__((always_inline)) inline bool ValidUsrname(const std::string &name)
|
|||
return true;
|
||||
}
|
||||
|
||||
using namespace drogon;
|
||||
//NOT THREAD SAFE
|
||||
size_t Bank::NumOfUsers() const noexcept { return users.size(); }
|
||||
|
||||
//NOT THREAD SAFE
|
||||
uint64_t Bank::NumOfLogs() const noexcept
|
||||
{
|
||||
uint64_t res;
|
||||
for (const auto &u : users)
|
||||
{
|
||||
res += u.second.log.data.size();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#if CONSERVATIVE_DISK_SAVE
|
||||
bool Bank::GetChangeState() const noexcept
|
||||
|
|
@ -29,8 +43,7 @@ bool Bank::GetChangeState() const noexcept
|
|||
}
|
||||
#endif
|
||||
|
||||
BankResponse
|
||||
Bank::GetBal(const std::string &name) const noexcept
|
||||
BankResponse Bank::GetBal(const std::string &name) const noexcept
|
||||
{
|
||||
uint64_t res = 0;
|
||||
users.if_contains(name, [&res](const User &u) { res = u.balance + 1; });
|
||||
|
|
|
|||
Loading…
Reference in a new issue