dingmaotu / mql4-lib

MQL4/5 Foundation Library For Professional Developers
Apache License 2.0
544 stars 251 forks source link

Set no more compatible with Collection #32

Closed JJJHawk closed 6 years ago

JJJHawk commented 6 years ago

Hi Ding Li,

still I dont know how to make pull requests, so here is what I did local to make Set work again. I dont know, if that is all what is todo. But at least it should be the compatibility with the new iterator interface and with the new Collection constructor.

Greetings Martin

` Collection/Set.mqh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Collection/Set.mqh b/Collection/Set.mqh index efe3ee0..b6234c7 100644 --- a/Collection/Set.mqh +++ b/Collection/Set.mqh @@ -34,7 +34,7 @@ public: // Iterator interface Iterator*iterator() const {return new SetIterator(m_array);} // for Set initial buffer set to zero

JJJHawk commented 6 years ago

Still it doesn't work to make a simple Set of Integers for example:

m_strategies = new Set<int>();

Error is: Cannot instantiate abstract class

I dont find the reason but my changes above are not enough.

yerden commented 6 years ago

As you can see, Set's hierarchy of inheritance is ConstIterable->Iterable->Collection->Set. The latter one is an abstract class which you cannot instantiate. If you devise some implementation of a Set, you have to satisfy all ancestor classes' interfaces.

dingmaotu commented 6 years ago

@JJJHawk Hi what @yerden said is a future state, where the Set is an abstract class. You can use HashSet though, which is a concrete class that can be instantiated. Now the Set is an array based concrete implementation, but it is in a broken state as recently the collection classes had gone through a rather big refactoring and I don't have time to make it an ArraySet and turn the Set into an abstract interface. Sorry for the inconvenience. I will spend some time to close this issue.

Thank you for answering questions @yerden and your recent pull requests will be processed as soon as I have some time.

JJJHawk commented 6 years ago

Hello Yerden,

yes I understand. That is why I changed the constructor in the Set-Class to:

Set(bool owned=true,int buffer=0,EqualityComparer<T>*comparer=NULL):Collection<T>(owned,comparer),m_array(buffer){}

which I took from the Vector Class, but unfortunately it doesn't help.

The line m_strategies = new Set<int>(); worked fine before the last big update to Collection Classes. The Set Constructor as it is now cannot work anymore so there is something to do: Set(int buffer=0):m_array(buffer){}

I switched to Vector now and my code works again. Its OK. But I dont need any sorting mechanism so a set would be the better choice. I simply need Contains(). Its just a bucket for strategies with which I fill the EA. Like {1,3,4} means do strategies 1,3,4.

JJJHawk commented 6 years ago

Hi Ding Li,

thank you very much for your answer which fits my last comment. Great work ! Thumbs Up!

Greetings Martin