319 linhas
10 KiB
MQL5
319 linhas
10 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| NodeBase.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_NODEBASE_MQH
|
|
#define BASESPARSERSLAN_SRC_NODEBASE_MQH
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#include "DomImp.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
namespace TSN
|
|
{
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#define NODEBASEF_RES_BASE(_ctx_, _idx_) ((_ctx_ != NULL && int(_ctx_.m_cinta[_idx_] & TSN_SBL_BIT_MASK_TYPE) == TSN_SBL_BASE_TYPE_OBJ) ? _ctx_.FindNodePos(_idx_) : -1)
|
|
#define NODEBASEF_RES m_node_pos = NODEBASEF_RES_BASE(m_ctx, m_idx);
|
|
#define NODEBASE_IS_NOT_VALID_F (m_ctx == NULL)
|
|
#define NODEBASE_IS_VALID (m_ctx != NULL)
|
|
#define NODEBASE_IS_NOT_VALID_FULL (m_ctx == NULL || m_idx < 1 || m_end < 1)
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
struct CNodeSFLBase
|
|
{
|
|
//---
|
|
TCtx* const m_ctx;
|
|
int m_idx;
|
|
int m_end;
|
|
int m_node_pos;
|
|
|
|
//---
|
|
CNodeSFLBase(TCtx* ctx, const int idx, const int end, const int node_pos)
|
|
: m_ctx(ctx), m_idx(idx), m_end(end), m_node_pos(node_pos) {}
|
|
|
|
//---
|
|
__forceinline void RecalcNodePos() { NODEBASEF_RES }
|
|
|
|
//--- Tipo
|
|
__forceinline uint GetFlag() const { return 1 << uint(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE); }
|
|
|
|
//--- Bool
|
|
bool ToBool(const bool def) const;
|
|
bool ToBoolSafe(bool& val) const;
|
|
|
|
//--- Is
|
|
__forceinline bool IsValid() const;
|
|
__forceinline bool IsInvalid() const;
|
|
__forceinline bool IsArray() const;
|
|
__forceinline bool IsObject() const;
|
|
|
|
//--- Size (arr u obj)
|
|
int Size() const;
|
|
__forceinline bool InRange(const int index) const;
|
|
bool InRangeSafe(const int index) const;
|
|
|
|
//--- JIT
|
|
bool NodeHashing();
|
|
__forceinline bool ObjectIsJit() const;
|
|
__forceinline int ObjectAttempCount() const;
|
|
|
|
//--- Mov raw
|
|
bool MoveToNextToken(const bool solo_en_el_bloque_actual = true);
|
|
bool MoveNextPositionsThis(const int posiciones, const bool solo_en_el_bloque_actual = true);
|
|
|
|
//--- Dom
|
|
bool ToDom(CDomNodeBase* &root, CDomNodeManager* manager);
|
|
};
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::ToDom(CDomNodeBase* &root, CDomNodeManager* manager)
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F || ((1 << int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE)) &
|
|
(TSN_SBL_BASE_F_OBJ | TSN_SBL_BASE_F_ARR)) == 0)
|
|
return false;
|
|
|
|
m_ctx.SerializeToDom(root, manager, m_idx, m_end);
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+}
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::NodeHashing(void)
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F || (m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != TSN_SBL_BASE_TYPE_OBJ)
|
|
return false;
|
|
|
|
//---
|
|
if(m_ctx.NodeHashing(m_idx, int((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_NUM_EL) & TSN_SBL_BIT_MASK_NUM_EL),
|
|
m_end, m_node_pos))
|
|
{
|
|
m_ctx.m_cinta[m_idx] = m_ctx.m_cinta[m_idx] | (long(1) << TSN_SBL_BIT_START_IS_HASING);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Jit instrocpeccion |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
__forceinline bool CNodeSFLBase::ObjectIsJit(void) const
|
|
{
|
|
return NODEBASE_IS_NOT_VALID_F || ((m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != TSN_SBL_BASE_TYPE_OBJ) ? false
|
|
: ((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_IS_HASING) & TSN_SBL_BIT_MASK_IS_HASHSING) != 0;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
__forceinline int CNodeSFLBase::ObjectAttempCount(void) const
|
|
{
|
|
return NODEBASE_IS_NOT_VALID_F || ((m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != TSN_SBL_BASE_TYPE_OBJ) ? 0
|
|
: int(m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_NUM_C_HASH) & TSN_SBL_BIT_MASK_NUM_C_HASH;
|
|
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Size |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
int CNodeSFLBase::Size() const
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F || ((1 << int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE)) & (TSN_SBL_BASE_F_OBJ | TSN_SBL_BASE_F_ARR)) == 0)
|
|
return 0;
|
|
|
|
//---
|
|
return int((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_NUM_EL) & TSN_SBL_BIT_MASK_NUM_EL);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
__forceinline bool CNodeSFLBase::InRange(const int index) const
|
|
{
|
|
const int t = int((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_NUM_EL) & TSN_SBL_BIT_MASK_NUM_EL);
|
|
return index >= 0 && index < t;
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::InRangeSafe(const int index) const
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F || ((1 << int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE)) & (TSN_SBL_BASE_F_OBJ | TSN_SBL_BASE_F_ARR)) == 0)
|
|
return false;
|
|
|
|
//---
|
|
const int t = int((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_NUM_EL) & TSN_SBL_BIT_MASK_NUM_EL);
|
|
return index >= 0 && index < t;
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| ToBool |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::ToBool(const bool def) const
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F)
|
|
return def;
|
|
|
|
//---
|
|
switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
|
{
|
|
case TSN_SBL_BASE_TYPE_INT:
|
|
{
|
|
return m_ctx.m_cinta[m_idx + 1] != 0;
|
|
}
|
|
case TSN_SBL_BASE_TYPE_FLT:
|
|
{
|
|
static BitInterpreter un;
|
|
return un.double_value != 0.0;
|
|
}
|
|
case TSN_SBL_BASE_TYPE_BOL:
|
|
return ((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_BOOL) & 1) != 0;
|
|
}
|
|
|
|
//---
|
|
return def;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::ToBoolSafe(bool & val) const
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F)
|
|
return false;
|
|
|
|
//---
|
|
switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
|
{
|
|
case TSN_SBL_BASE_TYPE_INT:
|
|
{
|
|
val = m_ctx.m_cinta[m_idx + 1] != 0;
|
|
return true;
|
|
}
|
|
case TSN_SBL_BASE_TYPE_FLT:
|
|
{
|
|
static BitInterpreter un;
|
|
val = un.double_value != 0.0;
|
|
return true;
|
|
}
|
|
case TSN_SBL_BASE_TYPE_BOL:
|
|
val = ((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_BOOL) & 1) != 0;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Is |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
__forceinline bool CNodeSFLBase::IsValid() const { return m_ctx != NULL && m_idx >= 0 && m_end >= 0; }
|
|
template <typename TCtx>
|
|
__forceinline bool CNodeSFLBase::IsInvalid() const { return NODEBASE_IS_NOT_VALID_FULL; }
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
__forceinline bool CNodeSFLBase::IsArray() const
|
|
{
|
|
return NODEBASE_IS_VALID && int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) == TSN_SBL_BASE_TYPE_ARR;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
__forceinline bool CNodeSFLBase::IsObject() const
|
|
{
|
|
return NODEBASE_IS_VALID && int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) == TSN_SBL_BASE_TYPE_OBJ;
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Navegacion raw |
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::MoveToNextToken(const bool solo_en_el_bloque_actual = true)
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F)
|
|
return false;
|
|
|
|
//---
|
|
const int next_pos = m_idx + m_ctx.GetStep(m_idx);
|
|
const int final_pos = next_pos + m_ctx.GetStep(next_pos);
|
|
|
|
//---
|
|
if(next_pos >= (solo_en_el_bloque_actual ? m_end : m_ctx.m_cinta_pos))
|
|
return false;
|
|
|
|
//---
|
|
m_idx = next_pos;
|
|
m_end = final_pos;
|
|
|
|
//---
|
|
NODEBASEF_RES
|
|
|
|
//---
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
template <typename TCtx>
|
|
bool CNodeSFLBase::MoveNextPositionsThis(const int posiciones, const bool solo_en_el_bloque_actual = true)
|
|
{
|
|
//---
|
|
if(NODEBASE_IS_NOT_VALID_F)
|
|
return false;
|
|
|
|
//---
|
|
const int next_pos = m_idx + posiciones;
|
|
const int final_pos = solo_en_el_bloque_actual ? m_end : next_pos + m_ctx.GetStep(next_pos);
|
|
|
|
//---
|
|
if(next_pos >= (solo_en_el_bloque_actual ? m_end : m_ctx.m_cinta_pos))
|
|
return false;
|
|
|
|
//---
|
|
m_idx = next_pos;
|
|
m_end = final_pos;
|
|
|
|
//---
|
|
NODEBASEF_RES
|
|
|
|
//---
|
|
return true;
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
#endif // BASESPARSERSLAN_SRC_NODEBASE_MQH
|