Skip to content

Commit

Permalink
Std: Adds STRUCT_ENUM to handle MQL4 back-compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Aug 18, 2021
1 parent a3ed0e0 commit a8668f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Std.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ unsigned int GetPointer(void* _ptr) { return (unsigned int)_ptr; }
const char* cstring_from(const std::string& _value) { return _value.c_str(); }
#endif

/**
* Referencing struct's enum.
*
* @usage
* STRUCT_ENUM(<struct_name>, <enum_name>)
*/
#ifdef __MQL4__
#define STRUCT_ENUM(S, E) E
#else
#define STRUCT_ENUM(S, E) S::E
#endif

#ifndef __MQL__
/**
* @file
Expand Down
4 changes: 2 additions & 2 deletions tests/DrawIndicatorTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void OnTick() {
Indicator *_indi = iter.Value();
_indi.OnTick();
IndicatorDataEntry _entry = _indi.GetEntry();
if (_indi.Get<bool>(IndicatorState::INDICATOR_STATE_PROP_IS_READY) && _entry.IsValid()) {
if (_indi.Get<bool>(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY)) && _entry.IsValid()) {
PrintFormat("%s: bar %d: %s", _indi.GetName(), bar_processed, _indi.ToString());
}
}
Expand Down Expand Up @@ -159,7 +159,7 @@ bool PrintIndicators(string _prefix = "") {
ResetLastError();
continue;
}
if (_indi.Get<bool>(IndicatorState::INDICATOR_STATE_PROP_IS_READY)) {
if (_indi.Get<bool>(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) {
PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString());
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/IndicatorsTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void OnTick() {
Indicator *_indi = iter.Value();
_indi.OnTick();
IndicatorDataEntry _entry = _indi.GetEntry();
if (_indi.Get<bool>(IndicatorState::INDICATOR_STATE_PROP_IS_READY) && _entry.IsValid()) {
if (_indi.Get<bool>(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY)) && _entry.IsValid()) {
PrintFormat("%s: bar %d: %s", _indi.GetFullName(), bar_processed, _indi.ToString());
tested.Set(iter.Key(), true); // Mark as tested.
}
Expand Down Expand Up @@ -645,7 +645,7 @@ bool PrintIndicators(string _prefix = "") {
ResetLastError();
continue;
}
if (_indi.Get<int>(IndicatorState::INDICATOR_STATE_PROP_IS_READY)) {
if (_indi.Get<int>(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) {
PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString(0));
}
}
Expand Down

0 comments on commit a8668f9

Please sign in to comment.