X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9701b7ab4dc4cd709ad4dcaa750fc0021f15e231..8bfaedfaf22377ff1beadebff699613bf19a1ce2:/include/stg/user_stat.h?ds=inline diff --git a/include/stg/user_stat.h b/include/stg/user_stat.h index 42d436fd..a486a56e 100644 --- a/include/stg/user_stat.h +++ b/include/stg/user_stat.h @@ -18,139 +18,149 @@ * 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 "stg/optional.h" +#include "user_traff.h" #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 & operator= (const USER_STAT_RES & usr); - USER_STAT() - : up(), - down(), - cash(0), + UserStat() noexcept + : cash(0), freeMb(0), lastCashAdd(0), lastCashAddTime(0), passiveTime(0), 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; @@ -158,32 +168,30 @@ struct USER_STAT_RES lastCashAddTime = us.lastCashAddTime; passiveTime = us.passiveTime; lastActivityTime = us.lastActivityTime; - up = us.up; - down = us.down; - return * this; - }; - operator USER_STAT() const - { - USER_STAT us; - us.cash = cash; - us.freeMb = freeMb; - us.lastCashAdd = lastCashAdd; - us.lastCashAddTime = lastCashAddTime; - us.passiveTime = passiveTime; - us.lastActivityTime = lastActivityTime; - us.up = up; - us.down = down; - return us; - }; - - RESETABLE cash; - RESETABLE freeMb; - RESETABLE lastCashAdd; - RESETABLE lastCashAddTime; - RESETABLE passiveTime; - RESETABLE lastActivityTime; - RESETABLE up; - RESETABLE down; + sessionUp = us.sessionUp; + sessionDown = us.sessionDown; + monthUp = us.monthUp; + monthDown = us.monthDown; + return *this; + } + + UserStatOpt(const UserStatOpt&) = default; + UserStatOpt& operator=(const UserStatOpt&) = default; + UserStatOpt(UserStatOpt&&) = default; + UserStatOpt& operator=(UserStatOpt&&) = default; + + Optional cash; + Optional cashAdd; + Optional cashSet; + Optional freeMb; + Optional lastCashAdd; + Optional lastCashAddTime; + Optional passiveTime; + Optional lastActivityTime; + DirTraffOpt sessionUp; + DirTraffOpt sessionDown; + DirTraffOpt monthUp; + DirTraffOpt monthDown; }; //----------------------------------------------------------------------------- -#endif +}