forked from nique_372/TSNStd
97 lines
3.2 KiB
MQL5
97 lines
3.2 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| Recolect.mqh |
| |
//| Copyright 2026, Niquel Mendoza. |
| |
//| https://www.mql5.com/ |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2026, Niquel Mendoza."
| |
#property link "https://www.mql5.com/"
| |
#property strict
| |
| |
#ifndef TSNSTD_SRC_ENUMSTR_GENERATE_RECOLECT_MQH
| |
#define TSNSTD_SRC_ENUMSTR_GENERATE_RECOLECT_MQH
| |
| |
#ifndef RECOLECT_MAX_SIZE
| |
#define RECOLECT_MAX_SIZE (1024)
| |
#endif // RECOLECT_MAX_SIZE
| |
| |
#ifndef MQLARTICLES_RECOLECT_V
| |
#define MQLARTICLES_RECOLECT_V int
| |
#endif // MQLARTICLES_RECOLECT_V
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CRecolect
| |
{
| |
public:
| |
CRecolect(void) {}
| |
~CRecolect(void) {}
| |
//---
| |
static MQLARTICLES_RECOLECT_V s_arr_v[RECOLECT_MAX_SIZE];
| |
static string s_arr_s[RECOLECT_MAX_SIZE];
| |
static int s_arr_size;
| |
| |
//---
| |
static bool Add(const string& vs, const MQLARTICLES_RECOLECT_V vi)
| |
{
| |
s_arr_v[s_arr_size] = vi;
| |
s_arr_s[s_arr_size++] = vs;
| |
return true;
| |
}
| |
| |
static bool Save(const string& file_name, bool comon)
| |
{
| |
::ResetLastError();
| |
const int fh = FileOpen(file_name, FILE_ANSI | FILE_TXT | FILE_WRITE | (comon ? FILE_COMMON : 0));
| |
if(fh == INVALID_HANDLE)
| |
{
| |
PrintFormat("Fallo al cargar el archivo = %s, ultimo err = %d", file_name, ::GetLastError());
| |
return false;
| |
}
| |
| |
//---
| |
FileWrite(fh, "map: {");
| |
const int last = s_arr_size - 1;
| |
for(int i = 0; i < last; i++)
| |
{
| |
const string str = " " + s_arr_s[i] + ": " + string(s_arr_v[i]) + ",";
| |
FileWrite(fh, str);
| |
}
| |
const string str = " " + s_arr_s[last] + ": " + string(s_arr_v[last]);
| |
FileWrite(fh, str);
| |
FileWrite(fh, "}");
| |
| |
//---
| |
FileClose(fh);
| |
return true;
| |
}
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
MQLARTICLES_RECOLECT_V CRecolect::s_arr_v[RECOLECT_MAX_SIZE];
| |
string CRecolect::s_arr_s[RECOLECT_MAX_SIZE];
| |
int CRecolect::s_arr_size = 0;
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#define MQLARTICLES_ENUMREC_REG(A) const bool g_asDA12_##A = CRecolect::Add(#A,int(A));
| |
// a = "user" | v = valor del enuym
| |
| |
//---
| |
// A=string
| |
// V=valor
| |
#define MQLARTICLES_ENUMREC_REG_CTS(A, V) const bool g_asDA12_##V = CRecolect::Add(A,int(V));
| |
| |
//---
| |
// prefixo custom
| |
// A=enum_v
| |
// P=prefijo
| |
// V=valor real
| |
#define MQLARTICLES_ENUMREC_REG_CTS_FULL(A, V, P) const bool g_asDA12_##P = CRecolect::Add(#A,int(V));
| |
| |
//+------------------------------------------------------------------+
| |
#endif // TSNSTD_SRC_ENUMSTR_GENERATE_RECOLECT_MQH
|