MQLArticles/Utils/FA/AutoDelete.mqh
nique_372 77019965e7 Sanitizar encoding a UTF-8: convertir 11 archivos desde UTF-16LE
Los .mqh estaban corruptos en el working tree porque core.autocrlf
normalizaba bytes de un archivo UTF-16LE como si fuera texto de 1 byte
por caracter, desalineando el contenido tras la primera linea. Se
reconstruyeron desde el blob de git (HEAD), no desde el working tree,
y se verifico igualdad byte a byte contra la conversion limpia antes
de commitear. Los .set estaban marcados binary en .gitattributes y no
sufrian este problema; solo se les cambio el encoding.
2026-09-14 11:01:42 -05:00

140 行
4.8 KiB
MQL5

//+------------------------------------------------------------------+
//| AutoDelete.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372"
#property strict
#ifndef MQLARTICLES_UTILS_FA_AUTODELETE_MQH
#define MQLARTICLES_UTILS_FA_AUTODELETE_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "SimpleLogger.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
typedef void(*FinalCleanFunction)(const int reason);
#define MQLARTICLES_AUTOCLEANER_FLAG_PTR (1)
#define MQLARTICLES_AUTOCLEANER_FLAG_FUNCTION (2)
#define MQLARTICLES_AUTOCLEANER_ALL (MQLARTICLES_AUTOCLEANER_FLAG_PTR|MQLARTICLES_AUTOCLEANER_FLAG_FUNCTION)
//---
//#define MQLARTICLES_AUTOCLENER_DEBUG
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CAutoCleaner
{
private:
static void* s_ptrs[];
static int s_ptrs_size;
static FinalCleanFunction s_c_functions[];
static int s_c_functions_size;
public:
CAutoCleaner() {}
~CAutoCleaner() {}
//--- Inicializar
static void Init()
{
s_ptrs_size = ArrayResize(s_ptrs, 0);
s_c_functions_size = ArrayResize(s_c_functions, 0);
}
//--- Punteros
// Añadir
static void AddPtr(void* ptr)
{
if(CheckPointer(ptr) == POINTER_DYNAMIC)
{
s_ptrs[ArrayResize(s_ptrs, ++s_ptrs_size) - 1] = ptr;
}
}
// Remover
static void RemovePtr(void* ptr)
{
for(int i = 0; i < s_ptrs_size; i++)
{
if(s_ptrs[i] == ptr)
{
s_ptrs[i] = s_ptrs[--s_ptrs_size];
ArrayResize(s_ptrs, s_ptrs_size);
break;
}
}
}
//--- Funciones
// Añadir
static __forceinline void AddFunction(FinalCleanFunction f)
{
s_c_functions[ArrayResize(s_c_functions, (++s_c_functions_size)) - 1] = f;
}
//--- Totales
static __forceinline int TotalPtr() { return s_ptrs_size; }
static __forceinline int TotalFunctions() { return s_c_functions_size; }
//--- Funciones principal clean
static void Deinit(const int reason, int flags = MQLARTICLES_AUTOCLEANER_ALL)
{
//--- Ptrs
if((flags & MQLARTICLES_AUTOCLEANER_FLAG_PTR) != 0)
{
for(int i = 0; i < s_ptrs_size; i++)
{
#ifdef MQLARTICLES_AUTOCLENER_DEBUG
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Iniciado eliminacion de puntero en posicion[%d], tipo = %s", i, EnumToString(CheckPointer(s_ptrs[i]))));
#endif
if(CheckPointer(s_ptrs[i]) == POINTER_DYNAMIC)
delete s_ptrs[i];
#ifdef MQLARTICLES_AUTOCLENER_DEBUG
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Finalizando eliminacion de puntero en posicion[%d]", i));
#endif
}
s_ptrs_size = ArrayResize(s_ptrs, 0);
}
//--- Eliminacion de funciones (DESPUES) debido aque qui eestan funciones de manager o clases de eventos
if((flags & MQLARTICLES_AUTOCLEANER_FLAG_FUNCTION) != 0)
{
for(int i = 0; i < s_c_functions_size; i++)
{
#ifdef MQLARTICLES_AUTOCLENER_DEBUG
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Iniciado ejecucion de funcion[%d]", i));
#endif
s_c_functions[i](reason);
#ifdef MQLARTICLES_AUTOCLENER_DEBUG
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Finalizando ejecucion de funcion[%d]", i));
#endif
}
s_c_functions_size = ArrayResize(s_c_functions, 0);
}
#ifdef MQLARTICLES_AUTOCLENER_DEBUG
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Fin de la limpieza");
#endif
}
};
//+------------------------------------------------------------------+
//| Definición de miembros estáticos |
//+------------------------------------------------------------------+
void* CAutoCleaner::s_ptrs[];
int CAutoCleaner::s_ptrs_size = 0;
FinalCleanFunction CAutoCleaner::s_c_functions[];
int CAutoCleaner::s_c_functions_size = 0;
//+------------------------------------------------------------------+
#endif // MQLARTICLES_UTILS_FA_AUTODELETE_MQH