
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Easy-peazy. This is only possible because the data is structured. If you had something spitting out random bits of data on the other end then and the only way to make since of it is by inferring some value solely by type -- then it's time to refactor what is doing the serialization to begin with.
I got the idea of key+value pairs, I just assume that if the data had some more properties other then type, Alain would have used that, because that makes the problem much easier. Maybe refactoring is needed, maybe there is a reason as to why this Is the case, I can't tell for sure.
What you are suggesting would be the equivalent to sending a mixed bag and praying the computing gods that nothing dangerous will happen (spoilers: it will).
I got the idea of key+value pairs, I just assume that if the data had some more properties other then type, Alain would have used that, because that makes the problem much easier. Maybe refactoring is needed, maybe there is a reason as to why this Is the case, I can't tell for sure.
Thanks trying to help,when some are just trying to show how "smart" they are.
I give up this topic and probably this forum.
There's no need for ad hominem attacks, Alain. I have a lot of experience with serialization, and I thought I was being helpful by suggesting you go back to your client to fix their serializer instead of hacking around it's unstructured output. Perhaps there is a valid case for dumping unstructured data that I'm just not seeing. It certainly would be very unconventional, but I'm 100% open to the fact that I may be wrong. Perhaps if you shared the context which disproves my suggestion, I will humbly apologize and accept that I was wrong. Otherwise, let's remain professional and refrain from the personal attacks.
I don't think there is an easy "standard" way, so I used an enum and a factory method.
...
Now, the vicious circle. I want to extract the original value as an mql basic type :
I added a Get method :
But to call it I need to dynamic_cast the pointer stored.
Problem is 'int' is not known (from a dynamic point of view)
The actual basic type when you have a CParentType pointer like values[i] is unknown, so once again, I would need to use ENUM_TYPE and a switch or try one by one all possible dynamic cast, but I would need to repeat it for each type.
Example, imagine I have to call a functionA with an int parameter, or a functionB with a double parameter.
I will need to declare a variable for any type, then call the "dynamic cast" function, trying one by one :
So the starting generic approach leads to further need to repeat code again and again.
Maybe I am too focused on my project and there is an other solution, but I missed it for now. Any idea ?
yes, heavy messy appears to be in your views on the problem (don't be upset - all OOP-thinkers suffer from this problem - "the type-information should be "encapsulated" somehow by the sence - either explicitly or implicitly")... because such is the language -- strictly-typed
you don't want template_class (for static polymorphism), because you want dynamic polymorphism (but you'd like to avoid type_casting)... - impossible (only if overloading to use)... It seems to me, that you just don't want to accept the reality as far as it is... Of course, you will need to write any generalized_class like std::variant in C++ (BTW you can see its implementation & try to do the same)... - ? perhaps it also uses Type_identification inside ... then it seems for me )) that inspite of your link to wiki - there is really no a person (even among Nobel winners) who have created such a class without type-identification inside - because it is not possible logically (e.g. at least ENUMs should provide this identification - as you know, but do not want to bear it)...
in any case you will need to know somehow the inner m_state of your dynamic object & can use your function as member_method -- in such a case I see no problems (but of course, you need any switch to type when creating the object)... in order to even probably use then e.g. pattern State (if it suits you & you don't like to define the type in the class itself with enum, but need new abstractions)... imho
I strongly believe, that your aim is to avoid great quantity of code-lines & to achive the maximum in generalization... but as I know, the highest level of generalization is provided by templates (or template_classes) - & you will not need the dynamic polymorphism using it... but you will need to create this class (even if it seems to be large)...
and using dynamic polymorphism of course you need type-casting if you really need it (I've heard that it is needed in 5% of cases when polymorphism is used)... but sometimes people prefer something else (to provide exact! type) when the day comes to be in need of RTTI - & the choice for any substitution depends on the situation... either overloading or using static objects (people prefer just to change the Architecture of the project ) - in order not to use RTTI (where type-casting is really needed)... of course it's worth to avoid RTTI... (in c++ visit-variant was invented for this purpose)
in any case, thank you for the interesting question
here was the attempt to read the File to different type arrays (I didn't see the implementation yet)
yes, heavy messy appears to be in your views on the problem (don't be upset - all OOP-thinkers suffer from this problem - "the type-information should be "encapsulated" somehow by the sence - either explicitly or implicitly")... because such is the language -- strictly-typed
you don't want template_class (for static polymorphism), because you want dynamic polymorphism (but you'd like to avoid type_casting)... - impossible (only if overloading to use)... It seems to me, that you just don't want to accept the reality as far as it is... Of course, you will need to write any generalized_class like std::variant in C++ (BTW you can see its implementation & try to do the same)... - ? perhaps it also uses Type_identification inside ... then it seems for me )) that inspite of your link to wiki - there is really no a person (even among Nobel winners) who have created such a class without type-identification inside - because it is not possible logically (e.g. at least ENUMs should provide this identification - as you know, but do not want to bear it)...
in any case you will need to know somehow the inner m_state of your dynamic object & can use your function as member_method -- in such a case I see no problems (but of course, you need any switch to type when creating the object)... in order to even probably use then e.g. pattern State (if it suits you & you don't like to define the type in the class itself with enum, but need new abstractions)... imho
I strongly believe, that your aim is to avoid great quantity of code-lines & to achive the maximum in generalization... but as I know, the highest level of generalization is provided by templates (or template_classes) - & you will not need the dynamic polymorphism... but you will need to create this class (even if it seems to be large)...
and using dynamic polymorphism of course you need type-casting if you really need it (I've heard that it is needed in 5% of cases when polymorphism is used)... but sometimes people prefer something else (to provide exact! type) when the day comes to be in need of RTTI - & the choice for any substitution depends on the situation... either overloading or using static objects (people prefer just to change the Architecture of the project ) - in order not to use RTTI (where type-casting is really needed)... of course it's worth to avoid RTTI... (in c++ visit-variant was invented for this purpose)
in any case, thank you for the interesting question
here was the attempt to read the File to different type arrays (I didn't see the implementation yet)
You can move the functions into the CType class:
then simply call it:
You can move the functions into the CType class:
if you see the beginning of the topic - as I understood the author wants to avoid these multiple switches & ifs (that you are suggesting to him in virtual void Function)...
well, therefore I assumed State_pattern can be used for dynamic polymorphism (and it IS used for dynamic polymorphism) -- but really I don't think that it will be shorter...
in any case, your suggestion resembles choosing in "table" (with multiple ifs) - & it is less efficient than overriding the virtual method (like in pattern_State having Context abstraction)... though I really do not know if such pattern suits his goals & really am not thinking that it will be real generalization - just for children of base class State & not for any other types... but if types are common (like int or double) then of course ENUM is ok (as already was mentioned) - if he really needs RTTI... it seems he really do need))
p.s.
BTW I'm now sure, that I do not need dynamic polymorphic objects in my problem - therefore am thankful to this topic
Probably won't help as well just playing around..
Idea is class that accepts any type (need to add a constructor for each new type possible - basic types for now) without needing to know upfront the type.
And get methods, that are used to retrieve a value, based on a receiving field type - without checking it's type (Overridden get methods for each type do that).
And the use:
Result:

Just to clarify, the idea of this topic is to be able to write generic code. Which seems not much people are understanding if I read the last few code examples which are not generic at all.
Anyway, it's currently impossible to write truly (complex) generic code in MQL.