2026-07-19 12:14:17 -05:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| DomBaseHeader.mqh |
|
|
|
|
|
//| Copyright 2026, Niquel Mendoza. |
|
|
|
|
|
//| https://www.mql5.com/ |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#property copyright "Copyright 2026, Niquel Mendoza."
|
|
|
|
|
#property link "https://www.mql5.com/"
|
|
|
|
|
#property strict
|
|
|
|
|
|
|
|
|
|
#ifndef BASESPARSERSLAN_SRC_DOM_BASE_HEADER_MQH
|
|
|
|
|
#define BASESPARSERSLAN_SRC_DOM_BASE_HEADER_MQH
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Include |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#include "Main.mqh"
|
|
|
|
|
#include <TSN\\GCol\\GenericHashes.mqh>
|
|
|
|
|
#include <TSN\\GCol\\HashMap.mqh>
|
|
|
|
|
|
|
|
|
|
namespace TSN
|
|
|
|
|
{
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CDomNodeManager;
|
2026-07-19 15:10:50 -05:00
|
|
|
#define TSN_SBL_BASE_DOM_NULL 7
|
|
|
|
|
|
2026-07-19 12:14:17 -05:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CDomNodeBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CDomNodeManager* m_ctx;
|
|
|
|
|
int m_type;
|
|
|
|
|
union Value
|
|
|
|
|
{
|
|
|
|
|
long iv;
|
|
|
|
|
double dv;
|
|
|
|
|
bool bv;
|
|
|
|
|
int ix;
|
|
|
|
|
} m_v;
|
|
|
|
|
|
|
|
|
|
//---
|
2026-07-19 15:10:50 -05:00
|
|
|
CDomNodeBase(CDomNodeManager* ctx, const int type, const double v)
|
|
|
|
|
: m_ctx(ctx), m_type(type) { m_v.dv = v; }
|
|
|
|
|
CDomNodeBase(CDomNodeManager* ctx, const int type, const long v)
|
|
|
|
|
: m_ctx(ctx), m_type(type) { m_v.iv = v; }
|
|
|
|
|
CDomNodeBase(CDomNodeManager* ctx, const int type, const bool v)
|
|
|
|
|
: m_ctx(ctx), m_type(type) { m_v.bv = v; }
|
|
|
|
|
CDomNodeBase(CDomNodeManager* ctx, const int type, const string& v)
|
|
|
|
|
: m_ctx(ctx), m_type(type)
|
|
|
|
|
{
|
|
|
|
|
m_v.ix = m_ctx.ReserveString();
|
|
|
|
|
m_ctx.m_string_stack[m_v.ix] = v;
|
|
|
|
|
}
|
|
|
|
|
CDomNodeBase(CDomNodeManager* ctx)
|
|
|
|
|
: m_ctx(ctx), m_type(TSN_SBL_BASE_DOM_NULL) {}
|
|
|
|
|
CDomNodeBase(CDomNodeManager* ctx, const int type)
|
|
|
|
|
: m_ctx(ctx), m_type(type) {}
|
|
|
|
|
|
|
|
|
|
//---
|
2026-07-19 12:14:17 -05:00
|
|
|
CDomNodeBase() : m_ctx(NULL), m_type(-1) {}
|
2026-07-19 15:10:50 -05:00
|
|
|
~CDomNodeBase();
|
2026-07-19 12:14:17 -05:00
|
|
|
|
|
|
|
|
//--- Keys
|
|
|
|
|
__forceinline int GetKeys(string& out[]) const;
|
|
|
|
|
__forceinline bool HasKey(const string& key) const;
|
|
|
|
|
bool Remove(const string& key); // Elimina una key
|
|
|
|
|
|
|
|
|
|
//--- Acceso
|
2026-07-20 07:27:42 -05:00
|
|
|
CDomNodeBase* operator[](const string& key); // si no existe lo crea..
|
|
|
|
|
CDomNodeBase* Get(const string& key); // devuelve un puntero null si falla
|
2026-07-19 12:14:17 -05:00
|
|
|
CDomNodeBase* At(const int idx) const;
|
|
|
|
|
|
|
|
|
|
//--- Arr
|
2026-07-19 21:43:38 -05:00
|
|
|
template <typename T>
|
|
|
|
|
__forceinline int ToArray(T& array[]) const;
|
2026-07-19 12:14:17 -05:00
|
|
|
__forceinline int Size() const;
|
|
|
|
|
__forceinline bool InRange(const int index) const;
|
|
|
|
|
__forceinline bool Remove(const int index); // elimina un index del array
|
2026-07-19 15:10:50 -05:00
|
|
|
bool AddItem(CDomNodeBase* node); // añade un item al array
|
2026-07-19 12:14:17 -05:00
|
|
|
|
|
|
|
|
//--- Comun entre arr y obj
|
|
|
|
|
void Clear(); // Elimina todos los elemetnos de array u obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--- Asignacion
|
|
|
|
|
void operator=(CDomNodeBase& v);
|
|
|
|
|
bool operator=(const long v);
|
|
|
|
|
bool operator=(const double v);
|
|
|
|
|
bool operator=(const bool v);
|
|
|
|
|
bool operator=(const string& v);
|
|
|
|
|
bool NewObj(int inital_hash_map_size);
|
|
|
|
|
bool NewArr(int inital_reserve);
|
|
|
|
|
|
|
|
|
|
//--- Is
|
2026-07-19 15:10:50 -05:00
|
|
|
__forceinline bool IsNull() const { return m_type == TSN_SBL_BASE_DOM_NULL; }
|
2026-07-19 12:14:17 -05:00
|
|
|
__forceinline bool IsArray() const { return m_type == TSN_SBL_BASE_TYPE_ARR; }
|
|
|
|
|
__forceinline bool IsObject() const { return m_type == TSN_SBL_BASE_TYPE_OBJ; }
|
|
|
|
|
|
|
|
|
|
//--- To
|
|
|
|
|
//- Int
|
|
|
|
|
long ToInt(const long def) const;
|
|
|
|
|
bool ToIntSafe(long& val) const;
|
|
|
|
|
|
|
|
|
|
//- Double
|
|
|
|
|
double ToDouble(const double def) const;
|
|
|
|
|
bool ToDoubleSafe(double& val) const;
|
|
|
|
|
|
|
|
|
|
//--- Bool
|
|
|
|
|
bool ToBool(const bool def) const;
|
|
|
|
|
bool ToBoolSafe(bool& val) const;
|
|
|
|
|
|
|
|
|
|
//--- String
|
|
|
|
|
string ToString(const string def = "") const;
|
|
|
|
|
int StrLenRaw() const;
|
2026-07-19 21:43:38 -05:00
|
|
|
|
|
|
|
|
//---
|
|
|
|
|
__forceinline CHashMapFastIterator(string, CDomNodeBase*) BenginIteration();
|
2026-07-19 12:14:17 -05:00
|
|
|
};
|
2026-07-19 15:10:50 -05:00
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
CDomNodeBase::~CDomNodeBase()
|
|
|
|
|
{
|
|
|
|
|
switch(m_type)
|
|
|
|
|
{
|
|
|
|
|
case TSN_SBL_BASE_TYPE_OBJ:
|
|
|
|
|
m_ctx.FreeObj(m_v.ix);
|
|
|
|
|
break;
|
|
|
|
|
case TSN_SBL_BASE_TYPE_ARR:
|
|
|
|
|
m_ctx.FreeArr(m_v.ix);
|
|
|
|
|
break;
|
|
|
|
|
case TSN_SBL_BASE_TYPE_INT:
|
|
|
|
|
case TSN_SBL_BASE_TYPE_FLT:
|
|
|
|
|
case TSN_SBL_BASE_TYPE_BOL:
|
|
|
|
|
break;
|
|
|
|
|
case TSN_SBL_BASE_TYPE_STR:
|
|
|
|
|
m_ctx.FreeString(m_v.ix);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 21:43:38 -05:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
__forceinline CHashMapFastIterator(string, CDomNodeBase*) CDomNodeBase::BenginIteration()
|
|
|
|
|
{
|
|
|
|
|
if(m_type != TSN_SBL_BASE_TYPE_OBJ)
|
|
|
|
|
return CHashMapFastIterator(string, CDomNodeBase*)();
|
|
|
|
|
return m_ctx.m_objs[m_v.ix].BeginIteration();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 12:14:17 -05:00
|
|
|
}
|
|
|
|
|
#endif // BASESPARSERSLAN_SRC_DOM_BASE_HEADER_MQH
|
|
|
|
|
//+------------------------------------------------------------------+
|