Skip to content

Commit

Permalink
WIP. Should fix tests in MT4 and MT5.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Feb 8, 2023
1 parent a30a476 commit 720ec62
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
8 changes: 4 additions & 4 deletions DictSlot.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class DictSlot {

DictSlot(unsigned char flags = 0) : _flags(flags) {}

#ifdef __MQL__
DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key), value(r.value) {}
#else
//#ifdef __MQL__
// DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key), value(r.value) {}
//#else
DictSlot(const DictSlot& r) : _flags(r._flags), key(r.key) { value = r.value; }
#endif
//#endif

bool IsValid() { return !bool(_flags & DICT_SLOT_INVALID); }

Expand Down
4 changes: 2 additions & 2 deletions Indicator/tests/classes/Indicators.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Indicators {
DictStruct<int, Ref<IndicatorData>> _indis;

public:
void Add(IndicatorBase* _indi) {
void Add(IndicatorData* _indi) {
Ref<IndicatorData> _ref = _indi;
_indis.Push(_ref);
}
Expand All @@ -51,7 +51,7 @@ class Indicators {

IndicatorData* operator[](int index) { return Get(index); }

int Size() { return _indis.Size(); }
int Size() { return (int)_indis.Size(); }

/**
* Executes OnTick() on every added indicator.
Expand Down
16 changes: 16 additions & 0 deletions Refs.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ struct WeakRef {
return Ptr();
}

/**
* Makes a weak reference to the given weakly-referenced object.
*/
X* operator=(const WeakRef<X>& right) {
THIS_REF = right.Ptr();
return Ptr();
}

/**
* Makes a weak reference to the strongly-referenced object.
*/
Expand All @@ -365,6 +373,14 @@ struct WeakRef {
return Ptr();
}

/**
* Makes a weak reference to the strongly-referenced object.
*/
X* operator=(const Ref<X>& right) {
THIS_REF = right.Ptr();
return Ptr();
}

/**
* Equality operator.
*/
Expand Down
14 changes: 14 additions & 0 deletions Tick/Tick.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ struct MqlTick {
long time_msc; // Time of a price last update in milliseconds.
unsigned int flags; // Tick flags.
unsigned long volume; // Volume for the current last price.
// Default constructor.
MqlTick() {}

// Copy constructor.
MqlTick(){const MqlTick & r} {
time = r.time;
ask = r.ask;
bid = r.bid;
last = r.last;
volume_real = r.volume_real;
time_msc = r.time_msc;
flags = r.flags;
volume = r.volume;
}
};
#endif

Expand Down
1 change: 1 addition & 0 deletions Tick/TickManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// Includes.
#include "../BufferStruct.mqh"
#include "Tick.struct.h"
#include "TickManager.h"
//#include "TickManager.struct.h"

Expand Down
4 changes: 2 additions & 2 deletions tests/IndicatorsTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ enum ENUM_CUSTOM_INDICATORS { INDI_SPECIAL_MATH_CUSTOM = FINAL_INDICATOR_TYPE_EN

// Global variables.
Indicators indis;
DictStruct<int, IndicatorData*> whitelisted_indis;
DictStruct<int, IndicatorData*> tested;
Dict<int, IndicatorData*> whitelisted_indis;
Dict<int, IndicatorData*> tested;
double test_values[] = {1.245, 1.248, 1.254, 1.264, 1.268, 1.261, 1.256, 1.250, 1.242, 1.240, 1.235,
1.240, 1.234, 1.245, 1.265, 1.274, 1.285, 1.295, 1.300, 1.312, 1.315, 1.320,
1.325, 1.335, 1.342, 1.348, 1.352, 1.357, 1.359, 1.422, 1.430, 1.435};
Expand Down
31 changes: 15 additions & 16 deletions tests/RefsTest.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,25 @@ int OnInit() {
// Dictionary of weak references.

DictStruct<string, WeakRef<DynamicClass>> refs2;
/*

Ref<DynamicClass> dyn9_1 = new DynamicClass(1);
Ref<DynamicClass> dyn9_2 = new DynamicClass(2);
Ref<DynamicClass> dyn9_3 = new DynamicClass(3);
Ref<DynamicClass> dyn9_1 = new DynamicClass(1);
Ref<DynamicClass> dyn9_2 = new DynamicClass(2);
Ref<DynamicClass> dyn9_3 = new DynamicClass(3);

WeakRef<DynamicClass> dyn9_1_weak_ref = dyn9_1;
WeakRef<DynamicClass> dyn9_2_weak_ref = dyn9_2;
WeakRef<DynamicClass> dyn9_3_weak_ref = dyn9_3;
WeakRef<DynamicClass> dyn9_1_weak_ref = dyn9_1;
WeakRef<DynamicClass> dyn9_2_weak_ref = dyn9_2;
WeakRef<DynamicClass> dyn9_3_weak_ref = dyn9_3;

refs2.Set("1", dyn9_1_weak_ref);
refs2.Set("2", dyn9_2_weak_ref);
refs2.Set("3", dyn9_3_weak_ref);
refs2.Set("1", dyn9_1_weak_ref);
refs2.Set("2", dyn9_2_weak_ref);
refs2.Set("3", dyn9_3_weak_ref);

// Should make refs2["2"] to have no existing object.
dyn9_2 = NULL;
// Should make refs2["2"] to have no existing object.
dyn9_2 = NULL;

assertTrueOrFail(refs2.GetByKey("1").ObjectExists(), "Object should exists");
assertTrueOrFail(!refs2.GetByKey("2").ObjectExists(), "Object should not exists as it has no more strong references");
assertTrueOrFail(refs2.GetByKey("3").ObjectExists(), "Object should exists");

assertTrueOrFail(refs2.GetByKey("1").ObjectExists(), "Object should exists");
assertTrueOrFail(!refs2.GetByKey("2").ObjectExists(), "Object should not exists as it has no more strong
references"); assertTrueOrFail(refs2.GetByKey("3").ObjectExists(), "Object should exists");
*/
return INIT_SUCCEEDED;
}

0 comments on commit 720ec62

Please sign in to comment.