ExpressEvalByLeo/Src/MathEval/NodeMath.mqh

336 lines
13 KiB
MQL5
Raw Permalink Normal View History

2026-05-14 11:13:22 -05:00
//+------------------------------------------------------------------+
//| NodeMath.mqh |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372/news"
#property strict
#ifndef EXPRESSEVALBYLEO_SRC_MATHEVAL_NODEMATH
#define EXPRESSEVALBYLEO_SRC_MATHEVAL_NODEMATH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\Common\\Node.mqh"
#include "Defines.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Dinamico (ambos)
// Almenos un double
//+------------------------------------------------------------------+
#define BYN_OP_DYN_DD(prefix, OP) \
template<typename T> \
class CAstBinaryOpNodeDync_DD_##prefix : public IValorSimpleValue<T> \
{ \
private: \
IValorSimpleValue<T>* const m_left; \
IValorSimpleValue<T>* const m_right; \
public: \
CAstBinaryOpNodeDync_DD_##prefix(IValorSimpleValue<T>* l, IValorSimpleValue<T>* r) : m_left(l), m_right(r) {} \
~CAstBinaryOpNodeDync_DD_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_left.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_left) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_left; \
2026-05-14 14:13:20 -05:00
if(m_right.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_right) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_right; \
} \
T Get() const override final \
{ \
return m_left.Get() OP m_right.Get(); \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//---
BYN_OP_DYN_DD(sum, +)
BYN_OP_DYN_DD(res, -)
BYN_OP_DYN_DD(mul, *)
BYN_OP_DYN_DD(div, /)
// Los demas no
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Number Number
#define BYN_OP_DYN_NN(prefix, OP) \
template<typename L, typename R, typename RES> \
class CAstBinaryOpNodeDync_NN_##prefix : public IValorSimpleValue<RES> \
{ \
private: \
IValorSimpleValue<L>* const m_left; \
IValorSimpleValue<R>* const m_right; \
public: \
CAstBinaryOpNodeDync_NN_##prefix(IValorSimpleValue<L>* l, IValorSimpleValue<R>* r) : m_left(l), m_right(r) {} \
~CAstBinaryOpNodeDync_NN_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_left.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_left) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_left; \
2026-05-14 14:13:20 -05:00
if(m_right.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_right) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_right; \
} \
RES Get() const override final \
{ \
return m_left.Get() OP m_right.Get(); \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//---
// negacion sera otro decendie de valor simple
BYN_OP_DYN_NN(sum, +)
BYN_OP_DYN_NN(res, -)
BYN_OP_DYN_NN(div, /)
BYN_OP_DYN_NN(mul, *)
BYN_OP_DYN_NN(modulo, %)
BYN_OP_DYN_NN(bit_or, |)
BYN_OP_DYN_NN(bit_and, &)
BYN_OP_DYN_NN(bit_xor, ^)
BYN_OP_DYN_NN(bit_dez_izq, <<)
BYN_OP_DYN_NN(bit_dez_der, >>)
// Falta negacion
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//---
// Dinamico(ANY Number | Double) X Estatico(double) (DS)
// any | double (ad)
#define BYN_OP_STATIC_DS_ad(prefix, OP) \
template<typename L> \
class CAstBynaryNodeStatic_DS_ad_##prefix : public IValorSimpleValue<double> \
{ \
private: \
IValorSimpleValue<L>* const m_left; \
const double m_right; \
public: \
CAstBynaryNodeStatic_DS_ad_##prefix(IValorSimpleValue<L>* l, const double r) : m_left(l), m_right(r) {} \
~CAstBynaryNodeStatic_DS_ad_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_left.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_left) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_left; \
} \
double Get() const override final \
{ \
return m_left.Get() OP m_right; \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BYN_OP_STATIC_DS_ad(sum, +)
BYN_OP_STATIC_DS_ad(res, -)
BYN_OP_STATIC_DS_ad(mul, *)
BYN_OP_STATIC_DS_ad(div, /)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//---
// Dinamico(integer) X Estatico(integer) (DS)
// integer | integer | ii
#define BYN_OP_STATIC_DS_ii(prefix, OP) \
2026-05-14 11:59:38 -05:00
template<typename L, typename RES> \
class CAstBynaryNodeStatic_DS_ii_##prefix : public IValorSimpleValue<RES> \
2026-05-14 11:13:22 -05:00
{ \
private: \
IValorSimpleValue<L>* const m_left; \
2026-05-14 11:59:38 -05:00
const RES m_right; \
2026-05-14 11:13:22 -05:00
public: \
2026-05-14 11:59:38 -05:00
CAstBynaryNodeStatic_DS_ii_##prefix(IValorSimpleValue<L>* l, const RES r) : m_left(l), m_right(r) {} \
2026-05-14 11:13:22 -05:00
~CAstBynaryNodeStatic_DS_ii_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_left.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_left) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_left; \
} \
2026-05-14 11:59:38 -05:00
RES Get() const override final \
2026-05-14 11:13:22 -05:00
{ \
return m_left.Get() OP m_right; \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BYN_OP_STATIC_DS_ii(sum, +)
BYN_OP_STATIC_DS_ii(res, -)
BYN_OP_STATIC_DS_ii(div, /)
BYN_OP_STATIC_DS_ii(mul, *)
BYN_OP_STATIC_DS_ii(modulo, %)
BYN_OP_STATIC_DS_ii(bit_or, |)
BYN_OP_STATIC_DS_ii(bit_and, &)
BYN_OP_STATIC_DS_ii(bit_xor, ^)
BYN_OP_STATIC_DS_ii(bit_dez_izq, <<)
BYN_OP_STATIC_DS_ii(bit_dez_der, >>)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Dinamico(double) X Estatico(integer) (DS)
2026-05-14 11:59:38 -05:00
// double|float | integer (di)
2026-05-14 11:13:22 -05:00
#define BYN_OP_STATIC_DS_di(prefix, OP) \
2026-05-14 11:59:38 -05:00
template<typename T> \
class CAstBynaryNodeStatic_DS_di_##prefix : public IValorSimpleValue<T> \
2026-05-14 11:13:22 -05:00
{ \
private: \
2026-05-14 11:59:38 -05:00
IValorSimpleValue<T>* const m_left; \
2026-05-14 11:13:22 -05:00
const long m_right; \
public: \
2026-05-14 11:59:38 -05:00
CAstBynaryNodeStatic_DS_di_##prefix(IValorSimpleValue<T>* l, const long r) : m_left(l), m_right(r) {} \
2026-05-14 11:13:22 -05:00
~CAstBynaryNodeStatic_DS_di_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_left.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_left) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_left; \
} \
2026-05-14 11:59:38 -05:00
T Get() const override final \
2026-05-14 11:13:22 -05:00
{ \
return m_left.Get() OP m_right; \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BYN_OP_STATIC_DS_di(sum, +)
BYN_OP_STATIC_DS_di(res, -)
BYN_OP_STATIC_DS_di(div, /)
BYN_OP_STATIC_DS_di(mul, *)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//---
// Estatico(double) X Dynamico(Double | Integer) (SD)
// double | any (da)
#define BYN_OP_STATIC_SD_da(prefix, OP) \
template<typename R> \
class CAstBynaryNodeStatic_SD_da_##prefix : public IValorSimpleValue<double> \
{ \
private: \
const double m_left; \
IValorSimpleValue<R>* const m_right; \
public: \
CAstBynaryNodeStatic_SD_da_##prefix(const double l, IValorSimpleValue<R>* r) : m_left(l), m_right(r) {} \
~CAstBynaryNodeStatic_SD_da_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_right.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_right) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_right; \
} \
double Get() const override final \
{ \
return m_left OP m_right.Get(); \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BYN_OP_STATIC_SD_da(sum, +)
BYN_OP_STATIC_SD_da(res, -)
BYN_OP_STATIC_SD_da(mul, *)
BYN_OP_STATIC_SD_da(div, /)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//---
// Estatico(integer) X Dinamico(integer) (SD)
// interger | integer (ii)
#define BYN_OP_STATIC_SD_ii(prefix, OP) \
template<typename L, typename RES> \
class CAstBynaryNodeStatic_SD_ii_##prefix : public IValorSimpleValue<RES> \
{ \
private: \
const long m_left; \
IValorSimpleValue<L>* const m_right; \
public: \
CAstBynaryNodeStatic_SD_ii_##prefix(const long l, IValorSimpleValue<L>* r) : m_left(l), m_right(r) {} \
~CAstBynaryNodeStatic_SD_ii_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_right.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_right) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_right; \
} \
RES Get() const override final \
{ \
return m_left OP m_right.Get(); \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BYN_OP_STATIC_SD_ii(sum, +)
BYN_OP_STATIC_SD_ii(res, -)
BYN_OP_STATIC_SD_ii(div, /)
BYN_OP_STATIC_SD_ii(mul, *)
BYN_OP_STATIC_SD_ii(modulo, %)
BYN_OP_STATIC_SD_ii(bit_or, |)
BYN_OP_STATIC_SD_ii(bit_and, &)
BYN_OP_STATIC_SD_ii(bit_xor, ^)
BYN_OP_STATIC_SD_ii(bit_dez_izq, <<)
BYN_OP_STATIC_SD_ii(bit_dez_der, >>)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Estatico(integer) X Dinamico(Double) (SD)
// integer | double )(id)
#define BYN_OP_STATIC_SD_id(prefix, OP) \
template<typename T> \
class CAstBynaryNodeStatic_SD_id_##prefix : public IValorSimpleValue<T> \
{ \
private: \
const long m_left; \
IValorSimpleValue<T>* const m_right; \
public: \
CAstBynaryNodeStatic_SD_id_##prefix(const long l, IValorSimpleValue<T>* r) : m_left(l), m_right(r) {} \
~CAstBynaryNodeStatic_SD_id_##prefix(void) \
{ \
2026-05-14 14:13:20 -05:00
if(m_right.TypeValue() == AST_EXPVAL_NODE_TYPE_BINRAY_NODE && CheckPointer(m_right) == POINTER_DYNAMIC) \
2026-05-14 11:13:22 -05:00
delete m_right; \
} \
T Get() const override final \
{ \
return m_left OP m_right.Get(); \
} \
2026-05-14 14:13:20 -05:00
__forceinline ENUM_AST_NODE_TYPE TypeValue() const override final { return AST_EXPVAL_NODE_TYPE_BINRAY_NODE; }\
2026-05-14 11:13:22 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BYN_OP_STATIC_SD_id(sum, +)
BYN_OP_STATIC_SD_id(res, -)
BYN_OP_STATIC_SD_id(div, /)
BYN_OP_STATIC_SD_id(mul, *)
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
struct ValueNode
{
IValor* d_val;
BitInterpreter s_val;
int s_val_type;
int type;
};
#endif // EXPRESSEVALBYLEO_SRC_MATHEVAL_NODEMATH
//+------------------------------------------------------------------+