TSNStd/Src/EnumsStr/Template.mqh

100 lines
7.9 KiB
MQL5

2026-10-09 12:34:15 -05:00
//+------------------------------------------------------------------+
//| Template.mqh |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/"
#property strict
2026-10-09 12:56:38 -05:00
#ifndef TSNSTD_SRC_ENUMSTR_TEMPLATE_MQH
#define TSNSTD_SRC_ENUMSTR_TEMPLATE_MQH
2026-10-09 12:34:15 -05:00
//+------------------------------------------------------------------+
//| Algoritmo principal |
//+------------------------------------------------------------------+
#define TSN_MQLARTICLES_ENUM_REG_ALG_CORE(seeds, buckets_size_l, final_table_size_l) \
const int seed_index = int(key_hash & buckets_size_l); \
ulong h = key_hash + seeds[seed_index] * 0x9e3779b97f4a7c15; \
h = (h ^ (h >> 30)) * 0xbf58476d1ce4e5b9; \
h = (h ^ (h >> 27)) * 0x94d049bb133111eb; \
h ^= (h >> 31); \
const int fi = int(h & final_table_size_l);
//--- esto incluye el algoritmo de hash fnv1a64 + alg core...
//+------------------------------------------------------------------+
#define TSN_MQLARTICLES_ENUM_REG_ALG_STR(seeds, buckets_size_l, final_table_size_l) \
const int len = StringLen(key); \
ulong key_hash = 14695981039346656037ULL; \
FNV1A_64_AsM_Str(key, len, key_hash, 1099511628211ULL) \
TSN_MQLARTICLES_ENUM_REG_ALG_CORE(seeds, buckets_size_l, final_table_size_l)
//+------------------------------------------------------------------+
// version con uchar
#define TSN_MQLARTICLES_ENUM_REG_ALG_U(seeds, buckets_size_l, final_table_size_l) \
ulong key_hash = 14695981039346656037ULL; \
len+=pos; \
FNV1A_64_AsM_U_rL(key, pos, len, key_hash, 1099511628211ULL) \
TSN_MQLARTICLES_ENUM_REG_ALG_CORE(seeds, buckets_size_l, final_table_size_l)
//+------------------------------------------------------------------+
//| Bases comunes |
//+------------------------------------------------------------------+
#define TSN_MQLARTICLES_ENUM_REG_COMMONS(seeds, valores, hashes, buckets_size_l, final_table_size_l) \
template <typename TEnumType> \
static TEnumType GetVal(const string& key, const TEnumType default_value) \
{ \
TSN_MQLARTICLES_ENUM_REG_ALG_STR(seeds, buckets_size_l, final_table_size_l) \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
} \
template <typename TEnumType> \
static TEnumType GetValNoRef(const string key, const TEnumType default_value) \
{ \
TSN_MQLARTICLES_ENUM_REG_ALG_STR(seeds, buckets_size_l, final_table_size_l) \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
} \
template <typename TEnumType> \
static TEnumType GetValU(const uchar& key[], int pos, int len, const TEnumType default_value) \
{ \
TSN_MQLARTICLES_ENUM_REG_ALG_U(seeds, buckets_size_l, final_table_size_l) \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Version con la posiblidad de valores dinamicos..
#define TSN_MQLARTICLES_ENUM_REG_TEM(prefix, seeds, valores, hashes, buckets_size_l, final_table_size_l) \
class CEnumReg##prefix \
{ \
private: \
static void ModVal(const string& key, long new_val) \
{ \
TSN_MQLARTICLES_ENUM_REG_ALG_STR(seeds, buckets_size_l, final_table_size_l) \
if(hashes[fi] == key_hash) \
valores[fi] = new_val; \
} \
public: \
CEnumReg##prefix(void) {} \
~CEnumReg##prefix(void) {} \
static bool RunDinyamics(); \
TSN_MQLARTICLES_ENUM_REG_COMMONS(seeds, valores, hashes, buckets_size_l, final_table_size_l) \
}; \
const bool g_enumreg_asd_##prefix = CEnumReg##prefix::RunDinyamics();
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//--- Version sin mod val...
#define TSN_MQLARTICLES_ENUM_REG_TEMF(prefix, seeds, valores, hashes, buckets_size_l, final_table_size_l) \
class CEnumReg##prefix \
{ \
public: \
CEnumReg##prefix(void) {} \
~CEnumReg##prefix(void) {} \
TSN_MQLARTICLES_ENUM_REG_COMMONS(seeds, valores, hashes, buckets_size_l, final_table_size_l) \
};
//+------------------------------------------------------------------+
2026-10-09 12:56:38 -05:00
#endif // TSNSTD_SRC_ENUMSTR_TEMPLATE_MQH