]> git.stg.codes - stg.git/blobdiff - include/stg/admin_conf.h
More std::jthread
[stg.git] / include / stg / admin_conf.h
index df6d9e22456f0f633a804c1311cf25fa7d7dff90..8531647e055f8a10bf39f239441788315b872828 100644 (file)
@@ -1,33 +1,21 @@
- /*
- $Revision: 1.9 $
- $Date: 2010/09/10 05:02:08 $
- $Author: faust $
- */
+#pragma once
 
-#ifndef ADMIN_CONF_H
-#define ADMIN_CONF_H
+#include "stg/optional.h"
 
 #include <string>
 
-#include "os_int.h"
+#include <cstdint>
 
 #define ADM_LOGIN_LEN   (32)
 #define ADM_PASSWD_LEN  (32)
-//-----------------------------------------------------------------------------
-struct PRIV
+
+namespace STG
 {
-    PRIV()
-        : userStat(0),
-          userConf(0),
-          userCash(0),
-          userPasswd(0),
-          userAddDel(0),
-          adminChg(0),
-          tariffChg(0),
-          serviceChg(0),
-          corpChg(0)
-    {}
-    PRIV(uint32_t p)
+
+struct Priv
+{
+    Priv() noexcept : Priv(0) {}
+    explicit Priv(uint32_t p) noexcept
         : userStat((p & 0x00000003) >> 0x00),
           userConf((p & 0x0000000C) >> 0x02),
           userCash((p & 0x00000030) >> 0x04),
@@ -39,8 +27,24 @@ struct PRIV
           corpChg((p & 0x00030000) >> 0x10)
     {}
 
-    uint32_t ToInt() const;
-    void FromInt(uint32_t p);
+    Priv(const Priv&) = default;
+    Priv& operator=(const Priv&) = default;
+    Priv(Priv&&) = default;
+    Priv& operator=(Priv&&) = default;
+
+    uint32_t toInt() const noexcept
+    {
+        uint32_t p = (userStat   << 0)  |
+                     (userConf   << 2)  |
+                     (userCash   << 4)  |
+                     (userPasswd << 6)  |
+                     (userAddDel << 8)  |
+                     (adminChg   << 10) |
+                     (tariffChg  << 12) |
+                     (serviceChg << 14) |
+                     (corpChg    << 16);
+        return p;
+    }
 
     uint16_t userStat;
     uint16_t userConf;
@@ -53,31 +57,30 @@ struct PRIV
     uint16_t corpChg;
 };
 //-----------------------------------------------------------------------------
-struct ADMIN_CONF
+struct AdminConf
 {
-    ADMIN_CONF()
-        : priv(),
-          login(),
-          password("* NO PASSWORD *")
-    {}
-    ADMIN_CONF(const ADMIN_CONF & rvalue)
-        : priv(rvalue.priv),
-          login(rvalue.login),
-          password(rvalue.password)
-    {}
-    ADMIN_CONF(const PRIV & pr, const std::string & l, const std::string & p)
+    AdminConf() : AdminConf({}, {}, "* NO PASSWORD *") {}
+    AdminConf(const Priv& pr, const std::string& l, const std::string& p)
         : priv(pr),
           login(l),
           password(p)
     {}
-    PRIV          priv;
+
+    AdminConf(const AdminConf&) = default;
+    AdminConf& operator=(const AdminConf&) = default;
+    AdminConf(AdminConf&&) = default;
+    AdminConf& operator=(AdminConf&&) = default;
+
+    Priv          priv;
     std::string   login;
     std::string   password;
 };
 //-----------------------------------------------------------------------------
+struct AdminConfOpt
+{
+    Optional<Priv> priv;
+    Optional<std::string> login;
+    Optional<std::string> password;
+};
 
-#include "admin_conf.inc.h"
-
-#endif
-
-
+}