MQLArticles/Utils/EnumsStr/Template.mqh

115 lines
4.9 KiB
MQL5

2026-06-28 16:04:40 -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
#ifndef MQLARTICLES_ENUMSTR_TEMPLATE_MQH
#define MQLARTICLES_ENUMSTR_TEMPLATE_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-07-06 07:09:50 -05:00
// Version con la posiblidad de valores dinamicos..
2026-06-28 16:04:40 -05:00
#define TSN_MQLARTICLES_ENUM_REG_TEM(prefix, seeds, valores, hashes, buckets_size, final_table_size) \
class CEnumReg##prefix \
{ \
private: \
static void ModVal(const string& key, long new_val) \
{ \
const int len = StringLen(key); \
ulong key_hash = 14695981039346656037ULL; \
FNV1a_64_AsM_Str(key, len, key_hash, 1099511628211ULL) \
const int seed_index = int(key_hash % buckets_size); \
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); \
if(hashes[fi] == key_hash) \
{ \
valores[fi] = new_val; \
} \
} \
public: \
CEnumReg##prefix(void) {} \
~CEnumReg##prefix(void) {} \
static bool RunDinyamics(); \
template <typename TEnumType> \
static TEnumType GetVal(const string& key, const TEnumType default_value) \
{ \
const int len = StringLen(key); \
ulong key_hash = 14695981039346656037ULL; \
FNV1a_64_AsM_Str(key, len, key_hash, 1099511628211ULL) \
const int seed_index = int(key_hash % buckets_size); \
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); \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
} \
template <typename TEnumType> \
static TEnumType GetValNoRef(const string key, const TEnumType default_value) \
{ \
const int len = StringLen(key); \
ulong key_hash = 14695981039346656037ULL; \
FNV1a_64_AsM_Str(key, len, key_hash, 1099511628211ULL) \
const int seed_index = int(key_hash % buckets_size); \
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); \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
} \
}; \
const bool g_enumreg_asd_##prefix = CEnumReg##prefix::RunDinyamics(); \
//+------------------------------------------------------------------+
2026-07-06 07:09:50 -05:00
//| |
//+------------------------------------------------------------------+
//--- Version sin mod val...
#define TSN_MQLARTICLES_ENUM_REG_TEMF(prefix, seeds, valores, hashes, buckets_size, final_table_size) \
class CEnumReg##prefix \
{ \
public: \
CEnumReg##prefix(void) {} \
~CEnumReg##prefix(void) {} \
static bool RunDinyamics(); \
template <typename TEnumType> \
static TEnumType GetVal(const string& key, const TEnumType default_value) \
{ \
const int len = StringLen(key); \
ulong key_hash = 14695981039346656037ULL; \
FNV1a_64_AsM_Str(key, len, key_hash, 1099511628211ULL) \
const int seed_index = int(key_hash % buckets_size); \
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); \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
} \
template <typename TEnumType> \
static TEnumType GetValNoRef(const string key, const TEnumType default_value) \
{ \
const int len = StringLen(key); \
ulong key_hash = 14695981039346656037ULL; \
FNV1a_64_AsM_Str(key, len, key_hash, 1099511628211ULL) \
const int seed_index = int(key_hash % buckets_size); \
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); \
return hashes[fi] == key_hash ? (TEnumType)valores[fi] : default_value; \
} \
};
//+------------------------------------------------------------------+
#endif // MQLARTICLES_ENUMSTR_TEMPLATE_MQH