X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8569ecdc2c9368dc0fe650b901cce7b37337ffec..90b793eb07dc190eeb1144a1da079de760d17c36:/include/stg/admin.h?ds=inline diff --git a/include/stg/admin.h b/include/stg/admin.h index 961968a1..7f302bb4 100644 --- a/include/stg/admin.h +++ b/include/stg/admin.h @@ -18,26 +18,52 @@ * Author : Maxim Mamontov */ -#ifndef ADMIN_H -#define ADMIN_H +#pragma once + +#include "admin_conf.h" + +#include "stg/common.h" #include +#include -#include "admin_conf.h" -#include "os_int.h" - -class ADMIN { -public: - virtual ~ADMIN() {} - virtual const std::string & GetPassword() const = 0; - virtual const std::string & GetLogin() const = 0; - virtual PRIV const * GetPriv() const = 0; - virtual uint32_t GetPrivAsInt() const = 0; - virtual const ADMIN_CONF & GetConf() const = 0; - virtual uint32_t GetIP() const = 0; - virtual std::string GetIPStr() const = 0; - virtual void SetIP(uint32_t ip) = 0; - virtual const std::string GetLogStr() const = 0; +namespace STG +{ + +class Admin +{ + public: + Admin() noexcept : Admin(AdminConf{}) {} + Admin(const Priv& priv, + const std::string& login, + const std::string& password) noexcept + : Admin(AdminConf{priv, login, password}) + {} + explicit Admin(const AdminConf& ac) noexcept : m_conf(ac), m_ip(0) {} + + Admin(const Admin&) = default; + Admin& operator=(const Admin&) = default; + Admin(Admin&&) = default; + Admin& operator=(Admin&&) = default; + + Admin& operator=(const AdminConf& ac) noexcept { m_conf = ac; return *this; } + bool operator==(const Admin& rhs) const noexcept { return m_conf.login == rhs.m_conf.login; } + bool operator!=(const Admin& rhs) const noexcept { return !(*this == rhs); } + bool operator<(const Admin& rhs) const noexcept { return m_conf.login < rhs.m_conf.login; } + + const std::string& password() const { return m_conf.password; } + const std::string& login() const { return m_conf.login; } + const Priv& priv() const { return m_conf.priv; } + uint32_t privAsInt() const { return m_conf.priv.toInt(); } + const AdminConf& conf() const { return m_conf; } + uint32_t IP() const { return m_ip; } + std::string IPStr() const { return inet_ntostring(m_ip); } + void setIP(uint32_t v) { m_ip = v; } + const std::string logStr() const { return "Admin \'" + m_conf.login + "\', " + IPStr() + ":"; } + + private: + AdminConf m_conf; + uint32_t m_ip; }; -#endif +}