forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| App.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_INDICATORSCTS_IMP_INTERNLA_APP_MQH
| |
#define MQLARTICLES_INDICATORSCTS_IMP_INTERNLA_APP_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "Def.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CApp : public CLoggerBase
| |
{
| |
private:
| |
TSN::CJsonParser m_json;
| |
| |
//---
| |
//string m_fn_out_pool;
| |
string m_fn_src_file_ind; // arhcivo de config de indicaodres (json)
| |
| |
//---
| |
/*uchar m_file_pool[];
| |
int m_file_pool_s;
| |
int m_file_pool_r;*/
| |
| |
//--- Archivo de indicadores
| |
uchar m_file_ind_guard[256]; // Buffer del guard
| |
int m_file_ind_guard_s; // Numero de bytes ocupados guard
| |
uchar m_file_ind[]; // Buffer del archivo ind
| |
int m_file_ind_s; // Tamaño del archivo ind
| |
int m_file_ind_r; // Tamaño real (reserva) del archivo ind
| |
string m_fn_out_ind; // Name del archivo final de esctritura
| |
| |
//---
| |
const ulong m_hash_relative;
| |
| |
//--- Procesar json
| |
bool ProccesConfig();
| |
bool ProccesIndicators();
| |
| |
//--- Utilidades de archivos
| |
bool AssingFileWJson(const string& file);
| |
bool SaveFile(const uchar& raw[], int size, const string& file);
| |
| |
//---
| |
bool FileProrrogo(TSN::CJsonNode& file,
| |
uchar& raw[], int& raw_s, int& raw_r, string& out_path);
| |
| |
//--- Utilidades de escritura
| |
void FileAddLineWC(const string& line, uchar& raw[], int& raw_s);
| |
void FileAddLineWC(const uchar& line[], int line_s, int line_len, uchar& raw[], int& raw_s);
| |
void FileAddInclude(const bool relative, uchar& raw[], int& raw_s,
| |
const uchar& include[], int inc_start, int inc_len);
| |
void AddGuardEnd(uchar& raw[], int& raw_s, const uchar& guard[], int guard_start, int guard_len);
| |
void FileAddGuardInit(uchar& raw[], int& raw_s, const uchar& guard[], int guard_start, int guard_len);
| |
| |
//--- Utilidad para json
| |
int JsonObjStrLen(TSN::CJsonNode& node, const uchar& in[]);
| |
| |
public:
| |
CApp(void);
| |
~CApp(void) {}
| |
| |
//---
| |
bool Run(const string& fn_config);
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CApp::CApp(void)
| |
: m_hash_relative(TSN::FNV1a_64("relative", StringLen("relative"))), m_fn_src_file_ind(NULL),
| |
| |
//---
| |
m_file_ind_s(0), m_file_ind_r(0), m_fn_out_ind(NULL), m_file_ind_guard_s(0)
| |
{
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CApp::AssingFileWJson(const string &file)
| |
{
| |
//---
| |
HANDLE handle = kernel32::CreateFileW(file, GENERIC_READ, SHARE_READ, 0, OPEN_EXISTING, 0, 0);
| |
if(handle == INVALID_HANDLE)
| |
{
| |
LogError(::StringFormat("Failed to open file = %s, last err = %d",
| |
file, kernel32::GetLastError()), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
long size;
| |
kernel32::GetFileSizeEx(handle, size);
| |
uint read;
| |
| |
//---
| |
const int isize = (int)size;
| |
m_json.m_len = isize;
| |
::ArrayResize(m_json.m_raw, m_json.m_len);
| |
kernel32::ReadFile(handle, m_json.m_raw, (uint)isize, read, 0);
| |
kernel32::CloseHandle(handle);
| |
| |
//---
| |
m_json.NormalizeUft();
| |
| |
//---
| |
if(!m_json.Parse())
| |
{
| |
LogError(::StringFormat("Fallo al parsear json:\nFile: '%s'\n", file), FUNCION_ACTUAL);
| |
m_json.ErrorInfo();
| |
return false;
| |
}
| |
| |
//---
| |
return true;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CApp::SaveFile(const uchar &raw[], int size, const string &file)
| |
{
| |
//---
| |
HANDLE handle = kernel32::CreateFileW(file, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
| |
if(handle == INVALID_HANDLE)
| |
{
| |
LogCriticalError(::StringFormat("Failed to create file:\n'%s'\nLast err in kernel32 = %d",
| |
file, kernel32::GetLastError()), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
uint writen = 0;
| |
kernel32::WriteFile(handle, raw, sizeof(uchar) * size, writen, NULL);
| |
kernel32::CloseHandle(handle);
| |
return true;
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CApp::Run(const string& fn_config)
| |
{
| |
//--- Parseamos la configuracion
| |
if(!AssingFileWJson(fn_config))
| |
return false;
| |
if(!ProccesConfig())
| |
return false;
| |
| |
//--- Parseamos ahora si el archivo de indicadores
| |
if(!AssingFileWJson(m_fn_src_file_ind))
| |
return false;
| |
//---
| |
if(!ProccesIndicators())
| |
return false;
| |
| |
//--- Guardamos el archivo final
| |
if(!SaveFile(m_file_ind, m_file_ind_s, m_fn_out_ind))
| |
return false;
| |
| |
//---
| |
LogInfo("Se termino", FUNCION_ACTUAL);
| |
| |
//---
| |
return true;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CApp::ProccesConfig(void)
| |
{
| |
//---
| |
TSN::CJsonNode root = m_json.GetRoot();
| |
| |
//---
| |
if(!root["src_inds_file"].ToStringSafe(m_fn_src_file_ind))
| |
{
| |
LogError("Falta el campo 'src_inds_file' que idnica el archivo donde estan los indicadores, o esta malformado", FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
if(!FileProrrogo(root["main_file"], m_file_ind,
| |
m_file_ind_s, m_file_ind_r, m_fn_out_ind))
| |
return false;
| |
/* if(!FileProrrogo(root["pool_file"], m_file_pool,
| |
m_file_pool_s, m_file_pool_r, m_fn_out_pool))
| |
return false;*/
| |
| |
//---
| |
return true;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CApp::FileProrrogo(TSN::CJsonNode& file,
| |
uchar& raw[], int& raw_s, int& raw_r, string& out_path)
| |
{
| |
//--- Reserva inicial
| |
SCRIPT_RESERVE_ARR(raw, raw_s, raw_r, 2048)
| |
| |
//---
| |
if(!file["path"].ToStringSafe(out_path))
| |
{
| |
LogError("No se pudo obtener el campo path", FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
const string pure = TSN::CPathUtils::GetPureFileName(out_path); // nombre puro del archivo (sin barras y eso)
| |
| |
//--- parte inciial header de comentarios
| |
//- primera linea
| |
SCRIPT_ADD_ONE_LINE(raw, raw_s)
| |
| |
//- File
| |
FileAddLineWC(pure, raw, raw_s);
| |
| |
//- (autor solo ascci puro)
| |
const int autor_start = file["autor"].StrStart();
| |
const int autor_len = file["autor"].StrLenRaw();
| |
if(autor_len == 0 || autor_start == 0)
| |
{
| |
LogError(::StringFormat("Falta el campo autor en file = '%s'", pure), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
FileAddLineWC(m_json.m_raw, autor_start, autor_len, raw, raw_s);
| |
| |
//- (link solo ascci puro)
| |
const int link_start = file["link"].StrStart();
| |
const int link_len = file["link"].StrLenRaw();
| |
if(link_len == 0 || link_start == 0)
| |
{
| |
LogError(::StringFormat("Falta el campo link en file = '%s'", pure), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
FileAddLineWC(m_json.m_raw, link_start, link_len, raw, raw_s);
| |
| |
//--- Linea de terminacion
| |
SCRIPT_ADD_ONE_LINE(raw, raw_s)
| |
| |
//--- Ahora si parrte de props
| |
//- copryrgith
| |
SCRIPT_ADD_PROP(SCRIPT_PROP_COPYRIGHT, raw, raw_s)
| |
raw[raw_s++] = '"';
| |
raw_s += ArrayCopy(raw, m_json.m_raw, raw_s, autor_start, autor_len);
| |
raw[raw_s++] = '"';
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
| |
//- link
| |
SCRIPT_ADD_PROP(SCRIPT_PROP_LINK, raw, raw_s)
| |
raw[raw_s++] = '"';
| |
raw_s += ArrayCopy(raw, m_json.m_raw, raw_s, link_start, link_len);
| |
raw[raw_s++] = '"';
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
| |
//- strict
| |
SCRIPT_ADD_PROP(SCRIPT_PROP_STRICT, raw, raw_s)
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
| |
//--- Espacio separador
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
| |
//--- Guards (trunca a 256 el guard)
| |
const int guard_start = file["guard"].StrStart();
| |
m_file_ind_guard_s = MathMin(file["guard"].StrLenRaw(), 256);
| |
if(guard_start != 0 && m_file_ind_guard_s > 0)
| |
{
| |
ArrayCopy(m_file_ind_guard, m_json.m_raw, 0, guard_start, m_file_ind_guard_s); // copiamos
| |
FileAddGuardInit(raw, raw_s, m_file_ind_guard, 0, m_file_ind_guard_s); // Agregamos el guard
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
}
| |
| |
//---
| |
SCRIPT_ADD_ONE_BLOCK(raw, raw_s)
| |
| |
//--- Includes
| |
// volvemos a reservas por si acaso
| |
const int t = file["includes"].Size() * 256;
| |
SCRIPT_RESERVE_ARR(raw, raw_s, raw_r, t)
| |
| |
//---
| |
CJsonIteratorArray it = file["includes"].BeginArr();
| |
while(it.IsValid())
| |
{
| |
TSN::CJsonNode include = it.Val();
| |
ulong key_h;
| |
if(!include.AtObjKey(0).KeyHashFVN1A64(key_h))
| |
{
| |
LogError("Se esperaba una key en el objeto de includes, no se obutvo nada", FUNCION_ACTUAL);
| |
return false;
| |
}
| |
const bool is_rel = key_h == m_hash_relative;
| |
int start = 0, len = 0;
| |
if(is_rel) // relatvie
| |
{
| |
TSN::CJsonNode r = include["relative"];
| |
start = r.StrStart();
| |
len = r.StrLenRaw();
| |
}
| |
else // <>
| |
{
| |
TSN::CJsonNode m = include["mql5"];
| |
if(m.IsInvalid())
| |
{
| |
LogError("Solo se permite dos tipos para los includes [relative, mql5] nada mas", FUNCION_ACTUAL);
| |
return false;
| |
}
| |
start = m.StrStart();
| |
len = m.StrLenRaw();
| |
}
| |
| |
//--- truncamos si hace falta
| |
FileAddInclude(is_rel, raw, raw_s, m_json.m_raw, start, MathMin(len, 256));
| |
| |
//---
| |
it.Next();
| |
}
| |
| |
//---
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
| |
//---
| |
LogInfo(::StringFormat("Archivo = '%s' procesado correctamente", pure), FUNCION_ACTUAL);
| |
| |
//---
| |
return true; // terminamos el prologo
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void CApp::FileAddLineWC(const string& line, uchar& raw[], int& raw_s)
| |
{
| |
//---
| |
const int line_pure_size = SCRIPT_LINEW_PURESIZE; // espacio util
| |
const int norm_len = MathMin(line_pure_size, StringLen(line));
| |
const int rest_len = line_pure_size - norm_len; // espacio que necesitare
| |
int to_copy_linew = 4 + rest_len; // cuanto copiar de linew
| |
| |
//---
| |
raw_s += ArrayCopy(raw, g_res_linew, raw_s, 0, to_copy_linew); // ws
| |
raw_s += StringToCharArray(line, raw, raw_s, norm_len, CP_UTF8); // ahora si
| |
| |
//---
| |
raw[raw_s++] = ' ';
| |
raw[raw_s++] = '|';
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CApp::FileAddLineWC(const uchar& line[], int line_s, int line_len, uchar& raw[], int& raw_s)
| |
{
| |
//---
| |
const int line_pure_size = SCRIPT_LINEW_PURESIZE; // espacio util
| |
const int norm_len = MathMin(line_pure_size, line_len);
| |
const int rest_len = line_pure_size - norm_len; // espacio que necesitare
| |
int to_copy_linew = 4 + rest_len; // cuanto copiar de linew
| |
| |
//---
| |
raw_s += ArrayCopy(raw, g_res_linew, raw_s, 0, to_copy_linew); // ws
| |
raw_s += ArrayCopy(raw, line, raw_s, line_s, norm_len); // ahora si
| |
| |
//---
| |
raw[raw_s++] = ' ';
| |
raw[raw_s++] = '|';
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CApp::FileAddGuardInit(uchar& raw[], int& raw_s, const uchar& guard[], int guard_start, int guard_len)
| |
{
| |
//---
| |
raw[raw_s++] = '#';
| |
raw[raw_s++] = 'i';
| |
raw[raw_s++] = 'f';
| |
raw[raw_s++] = 'n';
| |
raw[raw_s++] = 'd';
| |
raw[raw_s++] = 'e';
| |
raw[raw_s++] = 'f';
| |
raw[raw_s++] = ' ';
| |
| |
raw_s += ArrayCopy(raw, guard, raw_s, guard_start, guard_len);
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
| |
//---
| |
raw[raw_s++] = '#';
| |
raw[raw_s++] = 'd';
| |
raw[raw_s++] = 'e';
| |
raw[raw_s++] = 'f';
| |
raw[raw_s++] = 'i';
| |
raw[raw_s++] = 'n';
| |
raw[raw_s++] = 'e';
| |
raw[raw_s++] = ' ';
| |
| |
raw_s += ArrayCopy(raw, guard, raw_s, guard_start, guard_len);
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CApp::AddGuardEnd(uchar& raw[], int& raw_s, const uchar& guard[], int guard_start, int guard_len)
| |
{
| |
//---
| |
raw[raw_s++] = '#';
| |
raw[raw_s++] = 'e';
| |
raw[raw_s++] = 'n';
| |
raw[raw_s++] = 'd';
| |
raw[raw_s++] = 'i';
| |
raw[raw_s++] = 'f';
| |
raw[raw_s++] = ' ';
| |
raw[raw_s++] = '/';
| |
raw[raw_s++] = '/';
| |
| |
//---
| |
raw_s += ArrayCopy(raw, guard, raw_s, guard_start, guard_len);
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CApp::FileAddInclude(const bool relative, uchar& raw[], int& raw_s, const uchar& include[], int inc_start, int inc_len)
| |
{
| |
//---
| |
raw[raw_s++] = '#';
| |
raw[raw_s++] = 'i';
| |
raw[raw_s++] = 'n';
| |
raw[raw_s++] = 'c';
| |
raw[raw_s++] = 'l';
| |
raw[raw_s++] = 'u';
| |
raw[raw_s++] = 'd';
| |
raw[raw_s++] = 'e';
| |
raw[raw_s++] = ' ';
| |
| |
//---
| |
raw[raw_s++] = relative ? '"' : '<';
| |
| |
//---
| |
raw_s += ArrayCopy(raw, include, raw_s, inc_start, inc_len);
| |
| |
//---
| |
raw[raw_s++] = relative ? '"' : '>';
| |
| |
//---
| |
SCRIPT_ADD_LINETERMINATOR(raw, raw_s)
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
int CApp::JsonObjStrLen(TSN::CJsonNode& node, const uchar& in[])
| |
{
| |
//---
| |
if(node.Size() < 1)
| |
return 16; // Default size
| |
| |
//---
| |
const int li = node.AtObjKey(0).StrStart() - 2; // Start de string
| |
int read_i = li;
| |
uchar c;
| |
| |
//---
| |
int stack = 1;
| |
| |
//---
| |
while(true)
| |
{
| |
//--- Saltamos los ws
| |
while((c = in[++read_i]) < 33) {}
| |
| |
//--- Salimos
| |
if(c == '}')
| |
break;
| |
| |
//--- Verificamos si es string
| |
if(c != '"')
| |
continue;
| |
| |
//---
| |
while((c = in[++read_i]) != '"')
| |
{
| |
if(c == '\\') // backslsaw saltamos
| |
read_i++;
| |
}
| |
}
| |
| |
//--- retornamos
| |
return (read_i - li) + 32;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CApp::ProccesIndicators(void)
| |
{
| |
//---
| |
TSN::CJsonNode indicators = m_json.GetRoot()["indicators"];
| |
if(indicators.IsInvalid())
| |
{
| |
LogError("No se encontro indicators en el root", FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
int expected_len = 0;
| |
| |
//--- Caluclo del len
| |
CJsonIteratorArray it = indicators.BeginArr();
| |
while(it.IsValid())
| |
{
| |
// 32 lineas de 256 carcteras mas el len del subnodo.. (contnado todos los chars) * 3 + 128
| |
TSN::CJsonNode params = it.Val()["parameters"];
| |
if(params.IsInvalid())
| |
{
| |
LogError(::StringFormat("Campo parametres no esta presente.. en pos = %d", it.m_cur), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
expected_len += (256 * 8) + (JsonObjStrLen(params, m_json.m_raw) * 3) + 128;
| |
it.Next();
| |
}
| |
| |
//---
| |
SCRIPT_RESERVE_ARR(m_file_ind, m_file_ind_s, m_file_ind_r, expected_len)
| |
//SCRIPT_RESERVE_ARR(m_file_pool, m_file_pool_s, m_file_pool_r, expected_len)
| |
| |
//--- Ahora si iteramos de verdad
| |
it = indicators.BeginArr();
| |
int curr_el = 0;
| |
while(it.IsValid())
| |
{
| |
//--- Defoines de ayuda
| |
#define SCRIPT_APPEND_CLASSNAME m_file_ind_s += ArrayCopy(m_file_ind, m_json.m_raw, m_file_ind_s, class_name.StrStart(), class_name.StrLenRaw());
| |
#define SCRIPT_APPEND_PADRE m_file_ind_s += ArrayCopy(m_file_ind, m_file_ind, m_file_ind_s, class_padre_start, class_padre_len);
| |
| |
//---
| |
TSN::CJsonNode ind = it.Val();
| |
| |
//--- bloque inciia
| |
SCRIPT_ADD_ONE_BLOCK(m_file_ind, m_file_ind_s)
| |
| |
//--- class
| |
m_file_ind[m_file_ind_s++] = 'c';
| |
m_file_ind[m_file_ind_s++] = 'l';
| |
m_file_ind[m_file_ind_s++] = 'a';
| |
m_file_ind[m_file_ind_s++] = 's';
| |
m_file_ind[m_file_ind_s++] = 's';
| |
m_file_ind[m_file_ind_s++] = ' ';
| |
| |
//---
| |
TSN::CJsonNode class_name = ind["class_name"];
| |
if(class_name.IsInvalid())
| |
{
| |
LogError(::StringFormat("No se encontro el campo class name en indicators[%d]", curr_el), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
SCRIPT_APPEND_CLASSNAME
| |
| |
//---
| |
const ulong num_buffers = ind["num_buffers"].ToUInt(0);
| |
if(num_buffers == 0)
| |
{
| |
LogError(::StringFormat("indicators[%d], Clase = %s, proporicono un numero de buffers menor a 1", curr_el, class_name.ToString("")), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_class_start, m_file_ind_s, 0); // public: padre
| |
| |
//--- Name CiIndicatorSimple<MQLA_B(algo)>
| |
const int class_padre_start = m_file_ind_s;
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_class_p, m_file_ind_s, 0); // nombre
| |
// ahora el buffer y cirrea
| |
STRCONV_VALTOBUFFER_USIGNED(num_buffers, m_file_ind, m_file_ind_s)
| |
m_file_ind[m_file_ind_s++] = ')';
| |
m_file_ind[m_file_ind_s++] = '>';
| |
const int class_padre_len = m_file_ind_s - class_padre_start;
| |
| |
| |
//--- termiansmo la linea de class
| |
SCRIPT_ADD_LINETERMINATOR(m_file_ind, m_file_ind_s)
| |
| |
//---
| |
SCRIPT_CTX(m_file_ind, m_file_ind_s, '{')
| |
| |
//--- public:\r\n
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_class_start, m_file_ind_s, RES_CLASS_START_OFF_PUBLIC, RES_CLASS_START_L_PUBLIC);
| |
m_file_ind[m_file_ind_s++] = ':';
| |
SCRIPT_ADD_LINETERMINATOR(m_file_ind, m_file_ind_s)
| |
| |
//--- espacios para el contructor Class() :
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_contructor_start, m_file_ind_s, 0);
| |
SCRIPT_APPEND_CLASSNAME
| |
m_file_ind[m_file_ind_s++] = '(';
| |
m_file_ind[m_file_ind_s++] = ')';
| |
m_file_ind[m_file_ind_s++] = ' ';
| |
m_file_ind[m_file_ind_s++] = ':';
| |
| |
//--- CiIndicatorSimple<MQL_A(buff)>()
| |
SCRIPT_APPEND_PADRE
| |
m_file_ind[m_file_ind_s++] = '(';
| |
| |
//--- Valor del contructor
| |
TSN::CJsonNode type = ind["type"];
| |
int ts, tl;
| |
if((tl = type.StrLenRaw()) > 0 && m_json.m_raw[(ts = type.StrStart())] == '$')
| |
{
| |
ts++; // aumenta
| |
tl--; // reduce el len
| |
m_file_ind_s += ArrayCopy(m_file_ind, m_json.m_raw, m_file_ind_s, ts, tl);
| |
}
| |
else
| |
{
| |
// solo numero enteoro no negaitvo asi que uint
| |
const ulong type_n = type.ToUInt(ULONG_MAX);
| |
if(type_n == ULONG_MAX)
| |
{
| |
LogError(::StringFormat("indicators[%d]: no se encontro el campo 'type' o el tipo debe de ser string (enum y emepzar con $)o un numero unsigned valido",
| |
curr_el), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
STRCONV_VALTOBUFFER_USIGNED(type_n, m_file_ind, m_file_ind_s)
| |
}
| |
| |
//--- finalziamos la linea del contrutro
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_fina_b, m_file_ind_s, 0);
| |
| |
//--- Ahora destructor
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_contructor_start, m_file_ind_s, 0);
| |
m_file_ind[m_file_ind_s++] = '~';
| |
SCRIPT_APPEND_CLASSNAME
| |
m_file_ind[m_file_ind_s++] = '(';
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_fina_b, m_file_ind_s, 0);
| |
| |
//--- Funcion create (Firma)
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_create_func, m_file_ind_s, 0);
| |
// Continuamos con la firma
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_initial_firm, m_file_ind_s, 0);
| |
| |
//---
| |
TSN::CJsonNode parameters = ind["parameters"];
| |
CJsonIteratorObj it_params = parameters.BeginObj();
| |
while(it_params.IsValid())
| |
{
| |
//---
| |
TSN::CJsonNode val = it_params.Val();
| |
TSN::CJsonNode key = it_params.Key();
| |
| |
//---
| |
m_file_ind[m_file_ind_s++] = ',';
| |
m_file_ind[m_file_ind_s++] = ' ';
| |
| |
//---
| |
if(val.GetType() != TSN::JSON_VTYPE_STRING)
| |
{
| |
LogError(::StringFormat("indiator[%d][parameter=%s] = Solo se permite strings como valores",
| |
curr_el, it_params.Key().KeyToString()), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//--- tipo name
| |
m_file_ind_s += ArrayCopy(m_file_ind, m_json.m_raw, m_file_ind_s, val.StrStart(), val.StrLenRaw());
| |
m_file_ind[m_file_ind_s++] = ' ';
| |
m_file_ind_s += ArrayCopy(m_file_ind, m_json.m_raw, m_file_ind_s, key.StrStart(), key.KeyLenRaw());
| |
| |
//---
| |
it_params.Next();
| |
}
| |
| |
//--- Finalizamos
| |
m_file_ind[m_file_ind_s++] = ')';
| |
SCRIPT_ADD_LINETERMINATOR(m_file_ind, m_file_ind_s)
| |
// apertura del body
| |
SCRIPT_CTX(m_file_ind, m_file_ind_s, '{')
| |
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_hide_s, m_file_ind_s, 0); // Hide start
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_h_assing, m_file_ind_s, 0); // const int h = ::
| |
// Ahora si el handle y parametros
| |
| |
//---
| |
TSN::CJsonNode creator = ind["creator"];
| |
if(creator.GetType() != TSN::JSON_VTYPE_STRING)
| |
{
| |
LogError(::StringFormat("indicator[%d][%s]: no se encontro el campo creator o este no es del tipo de string",
| |
curr_el, class_name.ToString()), FUNCION_ACTUAL);
| |
return false;
| |
}
| |
| |
//---
| |
m_file_ind_s += ArrayCopy(m_file_ind, m_json.m_raw, m_file_ind_s, creator.StrStart(), creator.StrLenRaw()); // const int h = ::
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_create_h_ini, m_file_ind_s, 0);
| |
| |
//--- parametros
| |
it_params = parameters.BeginObj();
| |
while(it_params.IsValid())
| |
{
| |
TSN::CJsonNode key = it_params.Key();
| |
m_file_ind_s += ArrayCopy(m_file_ind, m_json.m_raw, m_file_ind_s, key.StrStart(), key.KeyLenRaw());
| |
m_file_ind[m_file_ind_s++] = ',';
| |
m_file_ind[m_file_ind_s++] = ' ';
| |
it_params.Next();
| |
}
| |
| |
//---
| |
if(parameters.Size())
| |
m_file_ind_s -= 2; // pop los finales
| |
| |
//---
| |
m_file_ind[m_file_ind_s++] = ')';
| |
m_file_ind[m_file_ind_s++] = ';';
| |
SCRIPT_ADD_LINETERMINATOR(m_file_ind, m_file_ind_s)
| |
| |
//---
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_body_ee, m_file_ind_s, 0); // Hide END
| |
| |
//--- Return:
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_return, m_file_ind_s, 0); // return
| |
SCRIPT_APPEND_PADRE
| |
m_file_ind_s += ArrayCopy(m_file_ind, g_res_ret_i_final, m_file_ind_s, 0); // return
| |
| |
//---
| |
SCRIPT_CTX_WCLOSE(m_file_ind, m_file_ind_s) // cuerpo de clase
| |
| |
//---
| |
it.Next();
| |
curr_el++;
| |
}
| |
| |
//---
| |
#undef SCRIPT_APPEND_CLASSNAME
| |
#undef SCRIPT_APPEND_PADRE
| |
| |
//---
| |
if(m_file_ind_guard_s)
| |
AddGuardEnd(m_file_ind, m_file_ind_s, m_file_ind_guard, 0, m_file_ind_guard_s);
| |
| |
//---
| |
return true;
| |
}
| |
#endif // MQLARTICLES_INDICATORSCTS_IMP_INTERNLA_APP_MQH
|