Questions on OOP in MQL5 - page 62

 
Dmitry Fedoseev:

Finally something very interesting. Is it the "Steam Train" pattern?

Dima, you're not dragging here, calm down)))

 
Vladimir Simakov:

Somehow you're not doing it right)

PS Corrected

Wizard!

it works!

void OnStart(){
   CTest test;
   Print("1.-----------------------");
   Print(test.JSon());
   Print("2.-----------------------");
   test.a = 123456789;
   test.b = 9999999999999999;
   Print(test.JSon());
 }

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) 1.-----------------------

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) {

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "test":{

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "a":10,

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "b":0.369,

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "t": "Hi"

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) }

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "a":555,

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "b":-9223372036854775808

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) }

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) 2.-----------------------

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) {

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "test":{

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "a":10,

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "b":0.369,

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "t": "Hi"

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) }

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "a":123456789

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) "b":9999999999999999

2020.05.21 20:56:34.192 tst_json (EURUSD,H1) }


cool! So, in general, in this easy way I can download simple objects into json, and not via binary data like I used to do before

THANK YOU!

 
Vladimir Simakov:

Dima, you're not pulling any punches here, calm down))))

What a megalomaniac you have here in your club. And who would talk about it here, after that keeper. Don't you think you're the only one who can read?

It's more a matter of you not being able to fully master all the wisdom. You chop off one little piece at a time and then put on a show in public with your megalomania. Proud of its elitism from this knowledge could be 15 years ago, but now books on the subject and a lot of courses.

 
Igor Makanu:

Wizard!

it works!


cool! in general, in this way, it is possible to unload simple objects to json, not as I used to do - through binary data

THANK YOU!

That's how it should look like, line break is unnecessary, it was for clarity:

#define COMMA (text==NULL?"{":",")
#define VALUE(dVal) Push(#dVal,dVal)
#define STRUCT(dVal) PushStruct(#dVal,dVal.JSon())

class CJSon{
   string text;
public:
   CJSon():text(NULL){}
   CJSon* Push(string key,string value) {text+=COMMA+"\""+key+"\":\""+value+"\""; return &this;}
   CJSon* PushStruct(string key,string value) {text+=COMMA+"\""+key+"\":"+value; return &this;}
   CJSon* Push(string key,long value)   {text+=COMMA+"\""+key+"\":"+(string)value; return &this;}
   CJSon* Push(string key,double value) {text+=COMMA+"\""+key+"\":"+(string)value; return &this;}
   string Finish()   {return text+="}";}
};

I'd also like to add methods for arrays and array structures (I'm too lazy). And, in principle, can be run in kodobase.

I present, who will be the first in time.

PS: I will go in and check))))

 
Vladimir Simakov:

This is how it should look like, line break is unnecessary, it was for clarity:

And also methods for arrays and arrays of structures should be added (lazy). And, in principle, can be run in kodobase.

I present, who will be the first in time.

PS: I'll go in and check it out))))

post it in QB

imho, the right thing!

json is a well-established format, it's convenient for me to be able to have 100% one-to-one classes in C# and in MQL , and to organize loading of models in runtime - so far there's a hitch in this direction

and pass binary data here and there.... Well, it's not a novelty and only lazy person can do it)))


ZS: Python also seems to work with json without any problems, i don't know what Metaquotes has given to pythonists with its new MT5 capabilities - just pump out historical data? - what's the point? it wasn't a problem, imho

 
Vladimir Simakov:

This is how it should look like, line break is unnecessary, it was for clarity:

And also methods for arrays and arrays of structures should be added (lazy). And, in principle, can be run in kodobase.

I present, who will be the first in time.

PS: I'll go in and check))))

And how quickly such an object creation works? How much expedient is its application? Wouldn't it be better to use another macro for finishing? If of course the task is to make an impression, then undoubtedly the effect is killer.

 
Vladimir Simakov:

This is how it should look like, line break is unnecessary, it was for clarity:

checked in VS , no problem via clipboard {"test":{"a":10, "b":0.369, "t": "Hi"}, "a":123456789, "b":9999999999999999}

put in the editor:

 public class Rootobject
    {
        public Test test { get; set; }
        public int a { get; set; }
        public long b { get; set; }
    }

    public class Test
    {
        public int a { get; set; }
        public float b { get; set; }
        public string t { get; set; }
    }
 
Dmitry Fedoseev:

How fast does this kind of object creation work? How useful is it? Wouldn't it be better to use one more macro for the finish? Of course, if the task is to make a great impression, the effect is undoubtedly killer.

If you need it quickly, just run the binary without any caveats. A string is a stoka - you can, of course, allocate memory for N characters at once. Here, the only overhead is
text==NULL?"{":","

But it's this very thing the compiler is obliged to optimize and remove. This is what text(NULL) is initialized for and not text("{").

 
Vladimir Simakov:
And if you need it fast, just run the binary without any hassle. A string is a stoka - you can, of course, allocate memory for N characters at once. Here, the only overhead is

But this is exactly what the compiler is obliged to optimize and remove. That's why text(NULL) is initialized, not text("{")

I mean this: (CJSon()).V..

 
Dmitry Fedoseev:

I mean this: (CJSon()).V...

What's the problem, allocate 12 bytes of memory on the stack, I don't know exactly what a string object is?

Reason: