X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/627ef2adbb12c066764d6bd618147f6adb2b9cac..ebd170a764ab9660adee464588cda1801c7986b4:/include/stg/user_stat.h diff --git a/include/stg/user_stat.h b/include/stg/user_stat.h index 84fbba78..0ecd9e15 100644 --- a/include/stg/user_stat.h +++ b/include/stg/user_stat.h @@ -18,105 +18,104 @@ * Author : Boris Mikhailenko */ - /* - $Revision: 1.15 $ - $Date: 2010/03/11 14:42:05 $ - $Author: faust $ - */ +#pragma once -#ifndef USER_STAT_H -#define USER_STAT_H +#include "user_traff.h" #include +#include #include +#include +#include +#include -#include "os_int.h" -#include "resetable.h" -#include "user_traff.h" +namespace STG +{ //----------------------------------------------------------------------------- -struct IP_DIR_PAIR +struct IPDirPair { #ifdef TRAFF_STAT_WITH_PORTS - IP_DIR_PAIR(uint32_t _ip, - int _dir, - uint16_t _port) + IPDirPair(uint32_t _ip, int _dir, uint16_t _port) noexcept : ip(_ip), dir(_dir), port(_port) {} #else - IP_DIR_PAIR(uint32_t _ip, - int _dir) + IPDirPair(uint32_t _ip, int _dir) noexcept : ip(_ip), dir(_dir) {} #endif //------------------------ - bool operator<(const IP_DIR_PAIR & idp) const - { - if (ip < idp.ip) + bool operator<(const IPDirPair& rhs) const noexcept + { + if (ip < rhs.ip) return true; - if (ip > idp.ip) + if (ip > rhs.ip) return false; #ifdef TRAFF_STAT_WITH_PORTS - if (port < idp.port) + if (port < rhs.port) return true; - if (port > idp.port) + if (port > rhs.port) return false; #endif - if (dir < idp.dir) + if (dir < rhs.dir) return true; return false; - } + } //------------------------ - bool operator!=(const IP_DIR_PAIR & rvalue) const - { - if (ip != rvalue.ip) - return true; - + bool operator==(const IPDirPair& rhs) const noexcept + { #ifdef TRAFF_STAT_WITH_PORTS - if (port != rvalue.port) - return true; + return ip == rhs.ip && port == rhs.port && dir == rhs.dir; + #else + return ip == rhs.ip && dir == rhs.dir; #endif + } + bool operator!=(const IPDirPair& rhs) const noexcept + { + return !operator==(rhs); + } - if (dir != rvalue.dir) - return true; - - return false; - } + IPDirPair(const IPDirPair&) = default; + IPDirPair& operator=(const IPDirPair&) = default; + IPDirPair(IPDirPair&&) = default; + IPDirPair& operator=(IPDirPair&&) = default; //------------------------ - uint32_t ip; - int dir; + uint32_t ip; + int dir; #ifdef TRAFF_STAT_WITH_PORTS - uint16_t port; + uint16_t port; #endif }; //----------------------------------------------------------------------------- -struct STAT_NODE +struct StatNode { - STAT_NODE(uint64_t _up, - uint64_t _down, - double _cash) + StatNode(uint64_t _up, uint64_t _down, double _cash) noexcept : up(_up), down(_down), cash(_cash) {} - uint64_t up; - uint64_t down; - double cash; + + StatNode(const StatNode&) = default; + StatNode& operator=(const StatNode&) = default; + StatNode(StatNode&&) = default; + StatNode& operator=(StatNode&&) = default; + + uint64_t up; + uint64_t down; + double cash; }; //----------------------------------------------------------------------------- -struct USER_STAT +struct UserStat { - USER_STAT() - : up(), - down(), - cash(0), + UserStat() noexcept + : cash(0), freeMb(0), lastCashAdd(0), lastCashAddTime(0), @@ -124,32 +123,44 @@ struct USER_STAT lastActivityTime(0) {} - DIR_TRAFF up; - DIR_TRAFF down; - double cash; - double freeMb; - double lastCashAdd; - time_t lastCashAddTime; - time_t passiveTime; - time_t lastActivityTime; + UserStat(const UserStat&) = default; + UserStat& operator=(const UserStat&) = default; + UserStat(UserStat&&) = default; + UserStat& operator=(UserStat&&) = default; + + DirTraff sessionUp; + DirTraff sessionDown; + DirTraff monthUp; + DirTraff monthDown; + double cash; + double freeMb; + double lastCashAdd; + time_t lastCashAddTime; + time_t passiveTime; + time_t lastActivityTime; }; //----------------------------------------------------------------------------- -typedef std::map TRAFF_STAT; +using TraffStat = std::map; +//----------------------------------------------------------------------------- +using CashInfo = std::pair; //----------------------------------------------------------------------------- -struct USER_STAT_RES +struct UserStatOpt { - USER_STAT_RES() - : cash(), - freeMb(), - lastCashAdd(), - lastCashAddTime(), - passiveTime(), - lastActivityTime(), - up(), - down() + UserStatOpt() = default; + + UserStatOpt(const UserStat& data) noexcept + : cash(data.cash), + freeMb(data.freeMb), + lastCashAdd(data.lastCashAdd), + lastCashAddTime(data.lastCashAddTime), + passiveTime(data.passiveTime), + lastActivityTime(data.lastActivityTime), + sessionUp(data.sessionUp), + sessionDown(data.sessionDown), + monthUp(data.monthUp), + monthDown(data.monthDown) {} - - USER_STAT_RES & operator= (const USER_STAT & us) + UserStatOpt& operator=(const UserStat& us) { cash = us.cash; freeMb = us.freeMb; @@ -157,32 +168,30 @@ struct USER_STAT_RES lastCashAddTime = us.lastCashAddTime; passiveTime = us.passiveTime; lastActivityTime = us.lastActivityTime; - up = us.up; - down = us.down; + sessionUp = us.sessionUp; + sessionDown = us.sessionDown; + monthUp = us.monthUp; + monthDown = us.monthDown; return *this; } - USER_STAT GetData() const - { - USER_STAT us; - us.cash = cash.data(); - us.freeMb = freeMb.data(); - us.lastCashAdd = lastCashAdd.data(); - us.lastCashAddTime = lastCashAddTime.data(); - us.passiveTime = passiveTime.data(); - us.lastActivityTime = lastActivityTime.data(); - us.up = up.GetData(); - us.down = down.GetData(); - return us; - } - RESETABLE cash; - RESETABLE freeMb; - RESETABLE lastCashAdd; - RESETABLE lastCashAddTime; - RESETABLE passiveTime; - RESETABLE lastActivityTime; - DIR_TRAFF_RES up; - DIR_TRAFF_RES down; + UserStatOpt(const UserStatOpt&) = default; + UserStatOpt& operator=(const UserStatOpt&) = default; + UserStatOpt(UserStatOpt&&) = default; + UserStatOpt& operator=(UserStatOpt&&) = default; + + std::optional cash; + std::optional cashAdd; + std::optional cashSet; + std::optional freeMb; + std::optional lastCashAdd; + std::optional lastCashAddTime; + std::optional passiveTime; + std::optional lastActivityTime; + DirTraffOpt sessionUp; + DirTraffOpt sessionDown; + DirTraffOpt monthUp; + DirTraffOpt monthDown; }; //----------------------------------------------------------------------------- -#endif +}