Skip to content

Commit

Permalink
C++ compatibility fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Sep 9, 2024
1 parent f6380d1 commit fb06375
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 44 deletions.
32 changes: 16 additions & 16 deletions EA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class EA : public Taskable<DataParamEntry> {
void InitTask() {
// Add and process init task.
TaskEntry _task_entry(eparams.GetStruct<TaskEntry>(STRUCT_ENUM(EAParams, EA_PARAM_STRUCT_TASK_ENTRY)));
TaskObject<EA, EA> _taskobj_init(_task_entry,
THIS_PTR, THIS_PTR);
TaskObject<EA, EA> _taskobj_init(_task_entry, THIS_PTR, THIS_PTR);
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), true);
_taskobj_init.Process();
estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_ON_INIT), false);
Expand Down Expand Up @@ -163,7 +162,7 @@ class EA : public Taskable<DataParamEntry> {
*/
template <typename T>
T Get(ENUM_TRADE_STATE _state, string _symbol = NULL) {
return trade.GetByKey(_symbol != "" ? _symbol : _Symbol) PTR_DEREF Get<T>(_state);
return trade.GetByKey(_symbol != "" ? _symbol : _Symbol) REF_DEREF Get<T>(_state);
}

/**
Expand Down Expand Up @@ -221,7 +220,7 @@ class EA : public Taskable<DataParamEntry> {
/**
* Gets EA's trade instance.
*/
Trade *GetTrade(string _symbol) { return trade.GetByKey(_symbol); }
Trade *GetTrade(string _symbol) { return trade.GetByKey(_symbol).Ptr(); }

/* Setters */

Expand Down Expand Up @@ -254,8 +253,8 @@ class EA : public Taskable<DataParamEntry> {
*/
template <typename T>
void Set(ENUM_TRADE_PARAM _param, T _value) {
for (DictObjectIterator<string, Ref<Trade>> iter = trade.Begin(); iter.IsValid(); ++iter) {
Trade *_trade = iter.Value();
for (DictStructIterator<string, Ref<Trade>> iter = trade.Begin(); iter.IsValid(); ++iter) {
Trade *_trade = iter.Value().Ptr();
_trade PTR_DEREF Set<T>(_param, _value);
}
for (DictStructIterator<int64, Ref<Strategy>> iter = strats.Begin(); iter.IsValid(); ++iter) {
Expand Down Expand Up @@ -642,10 +641,10 @@ class EA : public Taskable<DataParamEntry> {
Strategy *_strat = _iter.Value().Ptr();
if (data_stg.KeyExists(_sid)) {
string _key_stg = StringFormat("Strategy-%d", _sid);
BufferStruct<StgEntry> _stg_buff = data_stg.GetByKey(_sid);
SerializerConverter _obj = SerializerConverter::FromObject(_stg_buff, _serializer_flags);
BufferStruct<StgEntry> *_stg_buff = data_stg.GetByKey(_sid);
SerializerConverter _obj = SerializerConverter::FromObject(PTR_TO_REF(_stg_buff), _serializer_flags);

_key_stg += StringFormat("-%d-%d-%d", _sid, _stg_buff.GetMin(), _stg_buff.GetMax());
_key_stg += StringFormat("-%d-%d-%d", _sid, _stg_buff PTR_DEREF GetMin(), _stg_buff PTR_DEREF GetMax());
if ((_methods & EA_DATA_EXPORT_CSV) != 0) {
_obj.ToFile<SerializerCsv>(_key_stg + ".csv", _serializer_flags, &_stub);
}
Expand Down Expand Up @@ -790,7 +789,7 @@ class EA : public Taskable<DataParamEntry> {
logger.Error("Strategy adding conflict!", __FUNCTION_LINE__);
DebugBreak();
}
OnStrategyAdd(_strat PTR_DEREF Ptr());
OnStrategyAdd(_strat.Ptr());
return _result;
}

Expand Down Expand Up @@ -856,8 +855,10 @@ class EA : public Taskable<DataParamEntry> {
ResetLastError();
for (DictStructIterator<string, Ref<Trade>> titer = trade.Begin(); titer.IsValid(); ++titer) {
Trade *_trade = titer.Value().Ptr();
if (_trade PTR_DEREF Get<bool>(TRADE_STATE_ORDERS_ACTIVE) && !_trade PTR_DEREF Get<bool>(TRADE_STATE_MARKET_CLOSED)) {
for (DictStructIterator<int64, Ref<Order>> oiter = _trade PTR_DEREF GetOrdersActive() PTR_DEREF Begin(); oiter.IsValid(); ++oiter) {
if (_trade PTR_DEREF Get<bool>(TRADE_STATE_ORDERS_ACTIVE) &&
!_trade PTR_DEREF Get<bool>(TRADE_STATE_MARKET_CLOSED)) {
for (DictStructIterator<int64, Ref<Order>> oiter = _trade PTR_DEREF GetOrdersActive() PTR_DEREF Begin();
oiter.IsValid(); ++oiter) {
bool _sl_valid = false, _tp_valid = false;
double _sl_new = 0, _tp_new = 0;
Order *_order = oiter.Value().Ptr();
Expand Down Expand Up @@ -1054,10 +1055,9 @@ class EA : public Taskable<DataParamEntry> {
// 1st (i:0) - Strategy's enum action to execute.
// 2nd (i:1) - Strategy's argument to pass.
TaskActionEntry _entry_strat = _entry;
_entry_strat PTR_DEREF ArgRemove(0);
for (DictStructIterator<int64, Ref<Strategy>> iter_strat = strats.Begin(); iter_strat PTR_DEREF IsValid(); ++iter_strat) {
Strategy *_strat = iter_strat PTR_DEREF Value().Ptr();

_entry_strat.ArgRemove(0);
for (DictStructIterator<int64, Ref<Strategy>> iter_strat = strats.Begin(); iter_strat.IsValid(); ++iter_strat) {
Strategy *_strat = iter_strat.Value().Ptr();
_result &= _strat PTR_DEREF Run(_entry_strat);
}
break;
Expand Down
16 changes: 11 additions & 5 deletions Exchange/Account/Account.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

/* Account type of values for statistics. */
Expand Down Expand Up @@ -99,7 +99,7 @@ enum ENUM_ACCOUNT_INFO_DOUBLE {
* https://www.mql5.com/en/docs/constants/environment_state/accountinformation
*/
enum ENUM_ACCOUNT_INFO_INTEGER {
ACCOUNT_CURRENCY_DIGITS = 0, // The number of decimal places in the account currency (int).
ACCOUNT_CURRENCY_DIGITS, // The number of decimal places in the account currency (int).
ACCOUNT_FIFO_CLOSE, // Whether positions can only be closed by FIFO rule (bool).
ACCOUNT_LEVERAGE, // Account leverage (long).
ACCOUNT_LIMIT_ORDERS, // Maximum allowed number of active pending orders (int).
Expand Down Expand Up @@ -148,8 +148,14 @@ enum ENUM_ACCOUNT_STOPOUT_MODE {
ACCOUNT_STOPOUT_MODE_PERCENT, // Account stop out mode in percents.
ACCOUNT_STOPOUT_MODE_MONEY, // Account stop out mode in money.
};

#endif

// C++ only enum values for ENUM_ACCOUNT_PARAM_INTEGER. Avoids conflicts.
#define ACCOUNT_MARGIN_MODE 100
#define ACCOUNT_CURRENCY_DIGITS 101
#define ACCOUNT_FIFO_CLOSE 102

/**
* Enumeration for the account integer param values.
*
Expand All @@ -167,9 +173,9 @@ enum ENUM_ACCOUNT_PARAM_INTEGER {
ACCOUNT_MARGIN_SO_MODE, // Mode for setting the minimal allowed margin (ENUM_ACCOUNT_STOPOUT_MODE).
ACCOUNT_PARAM_TRADE_ALLOWED = ACCOUNT_TRADE_ALLOWED, // Allowed trade for the current account (bool).
ACCOUNT_PARAM_TRADE_EXPERT = ACCOUNT_TRADE_EXPERT, // Allowed trade for an Expert Advisor (bool).
ACCOUNT_PARAM_MARGIN_MODE = ACCOUNT_MARGIN_MODE, // Margin calculation mode (ENUM_ACCOUNT_MARGIN_MODE).
ACCOUNT_PARAM_MARGIN_MODE = ACCOUNT_MARGIN_MODE, // Margin calculation mode (ENUM_ACCOUNT_MARGIN_MODE).
ACCOUNT_PARAM_CURRENCY_DIGITS =
ACCOUNT_CURRENCY_DIGITS, // The number of decimal places in the account currency (int).
ACCOUNT_PARAM_FIFO_CLOSE =
ACCOUNT_FIFO_CLOSE, // An indication showing that positions can only be closed by FIFO rule (bool).
ACCOUNT_FIFO_CLOSE // An indication showing that positions can only be closed by FIFO rule (bool).
};
6 changes: 3 additions & 3 deletions Exchange/Account/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -77,7 +77,7 @@ class Account : public AccountBase {
/**
* Returns serialized representation of the object instance.
*/
virtual SerializerNodeType Serialize(Serializer &_s) const {
virtual SerializerNodeType Serialize(Serializer &_s) {
_s.PassStruct(THIS_REF, "state", state);
return SerializerNodeObject;
}
Expand Down
8 changes: 4 additions & 4 deletions Exchange/Account/AccountBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -64,14 +64,14 @@ class AccountBase : public Dynamic {
/**
* Returns textual representation of the object instance.
*/
virtual string ToString() const { return SerializerConverter::FromObject(THIS_REF).ToString<SerializerJson>(); }
const string ToString() override { return SerializerConverter::FromObject(THIS_REF).ToString<SerializerJson>(); }

/* Serializers */

/**
* Returns serialized representation of the object instance.
*/
virtual SerializerNodeType Serialize(Serializer &_s) const = 0;
virtual SerializerNodeType Serialize(Serializer &_s) = 0;

/* Virtual methods */

Expand Down
2 changes: 1 addition & 1 deletion Exchange/Account/AccountMt.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class AccountMt : public AccountBase {
/**
* Returns serialized representation of the object instance.
*/
SerializerNodeType Serialize(Serializer &_s) const {
SerializerNodeType Serialize(Serializer &_s) {
AccountEntry _entry = GetEntry();
_s.PassStruct(THIS_REF, "account-entry", _entry, SERIALIZER_FIELD_FLAG_DYNAMIC);
return SerializerNodeObject;
Expand Down
2 changes: 1 addition & 1 deletion Exchange/Account/tests/Account.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AccountTest : public Account<AccountBaseState, AccountBaseEntry> {
*/
int OnInit() {
bool _result = true;
AccountTest acc1;
// AccountTest acc1;
// ...
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
}
Expand Down
2 changes: 1 addition & 1 deletion Exchange/Account/tests/AccountForex.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AccountForexTest : public Account<AccountForexState, AccountForexEntry> {
*/
int OnInit() {
bool _result = true;
AccountForexTest acc1;
// AccountForexTest acc1;
// ...
return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED;
}
Expand Down
8 changes: 4 additions & 4 deletions Exchange/Exchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -191,7 +191,7 @@ class Exchange : public Taskable<DataParamEntry> {
/**
* Returns serialized representation of the object instance.
*/
SerializerNodeType Serialize(Serializer &_s) const {
SerializerNodeType Serialize(Serializer &_s) {
_s.PassStruct(THIS_REF, "eparams", eparams);
_s.PassStruct(THIS_REF, "accounts", accounts);
//_s.PassStruct(THIS_REF, "symbols", symbols);
Expand All @@ -202,5 +202,5 @@ class Exchange : public Taskable<DataParamEntry> {
/**
* Returns textual representation of the object instance.
*/
string ToString() const { return SerializerConverter::FromObject(THIS_REF).ToString<SerializerJson>(); }
const string ToString() override { return SerializerConverter::FromObject(THIS_REF).ToString<SerializerJson>(); }
};
4 changes: 1 addition & 3 deletions Exchange/tests/Exchange.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class AccountDummy : public AccountBase {
/**
* Returns serialized representation of the object instance.
*/
virtual SerializerNodeType Serialize(Serializer &_s) const {
return SerializerNodeObject;
}
virtual SerializerNodeType Serialize(Serializer &_s) { return SerializerNodeObject; }
};

class ExchangeDummy : public Exchange {
Expand Down
6 changes: 3 additions & 3 deletions Platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "Deal.enum.h"
#include "Order.struct.h"
#include "Platform.define.h"
#include "Platform.enum.h"
#include "Platform.enum.h"

/**
* Extern declarations for C++.
Expand Down Expand Up @@ -622,7 +622,7 @@ class Platform : public Taskable<DataParamEntry> {
/**
* Returns serialized representation of the object instance.
*/
SerializerNodeType Serialize(Serializer &_s) const {
SerializerNodeType Serialize(Serializer &_s) {
_s.PassStruct(THIS_REF, "params", pparams);
//_s.PassStruct(THIS_REF, "exchanges", exchanges);
return SerializerNodeObject;
Expand All @@ -631,7 +631,7 @@ class Platform : public Taskable<DataParamEntry> {
/**
* Returns textual representation of the object instance.
*/
string ToString() const { return SerializerConverter::FromObject(THIS_REF).ToString<SerializerJson>(); }
const string ToString() override { return SerializerConverter::FromObject(THIS_REF).ToString<SerializerJson>(); }
};

bool Platform::initialized = false;
Expand Down
6 changes: 3 additions & 3 deletions Platform/Platform.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Includes.
Expand Down Expand Up @@ -82,7 +82,7 @@ struct PlatformParams {
SetUserError(ERR_INVALID_PARAMETER);
}
// Serializers.
SerializerNodeType Serialize(Serializer &s) const {
SerializerNodeType Serialize(Serializer &s) {
s.Pass(THIS_REF, "id", id);
s.Pass(THIS_REF, "name", name);
return SerializerNodeObject;
Expand Down

0 comments on commit fb06375

Please sign in to comment.