Questions on OOP in MQL5 - page 60

 
Igor Makanu:

hello again!


this question, there is an enum , we need either an array enum or a list enum or a container enum - something where to store 7 enum , but the appetite grows, maybe 70 enum


where ?

Both array and list and container can be done depending on the task. As I understand it, most likely you need to simplify the code writing, then you can split the enums into groups and combine them into structures for the parameters of each object.

If we are talking about the stage of execution, I think it's normal practice to use enums only when specifying values/pairs. And to store them, use a simple base type.

 
Aleksey Mavrin:

You can make an array, a list and a container, depending on the task. As I understand it, you probably need to simplify the code writing, then you can divide the enums into groups and combine them into structures for parameters of each object.

If we are talking about the stage of execution, I think it's normal practice to use enums only when specifying values/pairs. And to store them, use a simple base type.

did so at first, i walked away from it for some reason, it seems there were problems with initialization of such fields, or rather with autocomplete variants of enum in ME in some build, perhaps due to the fact that part of the code in another injector was.... let's look into this option.


surfed the internet, i want something Sharp like this... some properties (((.

 public class COrder
    {
        public enum E_MOTION { HIGHER, LOWER, ZIGZAG }
        public enum E_VOLUME { FIXED, INC, DEC }
        public E_MOTION OrderMotionType { get; set; }
        public E_VOLUME OrderVolumeType { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var current = new COrder { OrderMotionType = COrder.E_MOTION.HIGHER, OrderVolumeType = COrder.E_VOLUME.FIXED };
            
        }
    }
 
Igor Makanu:

did so at first, for some reason I abandoned it, it seems there were problems with initialization of such fields, or rather with autocompletion of enum variants in ME in some build, probably because part of the code in another injector was.... let's look into this option.


surfed the internet, i want something Sharp like this... some kind of properties (((

What's the problem?

If it's one-to-one, then:

class COrder
{
public:
   enum E_MOTION { HIGHER, LOWER, ZIGZAG };
   enum E_VOLUME { FIXED, INC, DEC };
   E_MOTION orderMotionType;
   E_VOLUME orderVolumeType;
   COrder(E_MOTION _motion, E_VOLUME _volume):orderMotionType(_motion),orderVolumeType(_volume){}
};

void OnStart(){
   COrder* current = new COrder(COrder::HIGHER,COrder::FIXED);
 } 

This is if you don't want to put the enumeration in a global scope.

 
Vladimir Simakov:

This is if you don't want to put the enumeration in the global scope.

hmm...

I just didn't know how to do that:

 COrder* current = new COrder(COrder::HIGHER,COrder::FIXED);

Thanks!

 

Does anyone have an elegant solution for JSON to upload uncomplicated objects?

I need an example of such a code for MQL:

public class COrder
    {
        public enum E_MOTION { HIGHER, LOWER, ZIGZAG }
        public enum E_VOLUME { FIXED, INC, DEC }

        public bool IsRunning { get; set; }
        public int OpenPrice { get; set; }
        public int ClosePrice { get; set; }
        public E_VOLUME OrderVolumeType { get; set; }
        public E_MOTION OrderMotionType { get; set; }
        
    }

    class Program
    {
        static void Main(string[] args)
        {
            var current = new COrder {
                IsRunning = false, 
                OpenPrice = 1200,
                ClosePrice = 1300,
                OrderMotionType = COrder.E_MOTION.ZIGZAG, 
                OrderVolumeType = COrder.E_VOLUME.FIXED };

            string json = JsonSerializer.Serialize<COrder>(current);
            Console.WriteLine(json);
            Console.ReadLine();
        }
    }

{"IsRunning":false,"OpenPrice":1200,"ClosePrice":1300,"OrderVolumeType":0,"OrderMotionType":2}

MQL serializer availableat https://www.mql5.com/ru/code/13663

but I don't understand the structure of correct field traversal

 
Igor Makanu:

But I have no idea how to properly traverse the object's fields

Macros are everything.)
 
Alexey Navoykov:
macros are everything!)

Uh-huh... I'll try asking again:

HELP ME AID AN EXAMPLER! PLEASE!

 
Igor Makanu:

Uh-huh... I'll try asking again:

HELP ME AND NEED AN EXAMPLE! Please!

Well, if the question specifically about bypassing the fields, it's something like this:

#define SERIALIZE5(object, m1, m2, m3, m4, m5)  /* your code */

...

SERIALIZE5(current, IsRunning, OpenPrice, ClosePrice, OrderVolumeType, OrderMotionType);

You can work out the body of the macro by yourself.)

 
Alexey Navoykov:

Well, if the question is specifically about field traversal, it's more or less like this:

And you can work out the body of the macro by yourself.)

OK, that's something!

Thank you!

 
On the other hand, for serialisation, it is probably better to specify the text names of the fields explicitly, so that you can rename them later in the code without worrying that the saved files will stop working.
Reason: