123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #pragma once
- #include "data.h"
- #include <iomanip>
- #include <openssl/sha.h>
- template<class T>
- inline rettype::type getmapvalue(std::string strvalue, std::map<std::string, std::string>& tmapvalue, T& tValue)
- {
- if (strvalue.empty())
- {
- return rettype::except;
- }
- std::map<std::string, std::string>::iterator ifindvalue;
- ifindvalue = tmapvalue.find(strvalue);
- if (ifindvalue == tmapvalue.end())
- {
- return rettype::except;
- }
- try
- {
- using F = std::decay_t<decltype(tValue)>;
- if constexpr (std::is_same_v<F, std::int32_t>)
- {
- tValue = std::stoi(ifindvalue->second);
- }
- else if constexpr (std::is_same_v<F, std::int64_t>)
- {
- tValue = std::stoll(ifindvalue->second);
- }
- if constexpr (std::is_same_v<F, std::uint32_t>)
- {
- tValue = std::stoul(ifindvalue->second);
- }
- else if constexpr (std::is_same_v<F, std::uint64_t>)
- {
- tValue = std::stoull(ifindvalue->second);
- }
- else if constexpr (std::is_same_v<F, std::string>)
- {
- tValue = ifindvalue->second;
- }
- else if constexpr (std::is_same_v<F, std::double_t>)
- {
- tValue = std::stod(ifindvalue->second);
- }
- return rettype::exist;
- }
- catch (std::exception)
- {
- return rettype::except;
- }
- return rettype::absent;
- }
- template <typename T>
- inline rettype::type getvaluedata(std::map<std::string, std::string> tmapdata, T& tdata)
- {
- rettype::type rettype;
- boost::pfr::for_each_field(tdata, [&rettype, &tdata, &tmapdata](auto& member, size_t index) {
- rettype = getmapvalue(tdata.getfieldvalue(index), tmapdata, member);
- if (rettype != rettype::exist)
- {
- rettype = rettype::absent;
- }
- });
- tdata.getdata();
- return rettype;
- }
- template <class T>
- inline void Random_Shuffle(T a, T b)
- {
- std::random_device rd;
- std::mt19937 g(rd());
- std::shuffle(a, b, g);
- }
- inline std::double_t getdouble_t(__int64 itemp)
- {
- std::double_t dscore = itemp;
- dscore = itemp;
- dscore /= 10000;
- return dscore;
- }
- //±£ÁôÁ½Î»
- inline std::double_t getdouble_t_two(__int64 itemp)
- {
- itemp /= 100;
- itemp *= 100;
- std::double_t dscore = itemp;
- dscore = itemp;
- dscore /= 10000;
- return dscore;
- }
- inline std::string sha256_to_base16(const std::string& input) {
- unsigned char hash[SHA256_DIGEST_LENGTH];
- SHA256_CTX sha256_ctx;
- SHA256_Init(&sha256_ctx);
- SHA256_Update(&sha256_ctx, input.c_str(), input.length());
- SHA256_Final(hash, &sha256_ctx);
- std::stringstream oss;
- for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
- oss << std::setw(2) << std::setfill('0') << std::hex << (int)hash[i];
- }
- return oss.str();
- }
|