Errors, bugs, questions - page 2709

 
Stanislav Korotky:

Why can't I call a protected constructor from my factory method in MQL?

The problem is the default value, if you remove it, everything works as it should:

class A1
{
  protected:
    A1(const bool x = false){}
  public:  
    static A1 *creator()
    {
      return new A1(true);
    }
};

void OnStart()
{
  A1 *a = A1::creator();
}
 
Stanislav Korotky:

Why in MQL you can't call a protected constructor from your factory method?

I haven't guessed where that might be useful.

 
fxsaber:

Haven't guessed where this might be useful.

Classic implementation of the Singleton pattern.

 
Sergey Dzyublik:

A classic implementation of the Singleton pattern.

So you can't create more than a certain number of objects of a given class?

 
fxsaber:

So that no more than a certain number of objects of a given class can be created?

Yes, so that there is a single access point from all parts of the program to an instance of the class with changeable state.
Here's a cool site I found today about patterns in pictures and pseudocode:https://refactoring.guru/ru/design-patterns/singleton

Одиночка
Одиночка
  • refactoring.guru
Одиночка — это порождающий паттерн проектирования, который гарантирует, что у класса есть только один экземпляр, и предоставляет к нему глобальную точку доступа. Проблема Одиночка решает сразу две проблемы, нарушая принцип единственной ответственности класса. Гарантирует наличие единственного экземпляра класса. Чаще всего это полезно для...
 
Sergey Dzyublik:

Yes, to have a single access point from all parts of the program to a state-changing class instance.
Here's a cool site I found today about patterns in pictures and pseudocode:https://refactoring.guru/ru/design-patterns/singleton

Got it, thanks. I've used such a construction before.

template <typename T>
struct PTR
{
  T* Ptr;

  PTR( void ) : Ptr(NULL)
  {
  }

  PTR( T* ptr ) : Ptr(ptr)
  {
  }

  ~PTR( void )
  {
    if (this.Ptr)
      delete this.Ptr;
  }

  bool Set( T* ptr )
  {
    this.Ptr = ptr;

    return(true);
  }

  void operator =( bool )
  {
  }
};

class CLASS
{
private:
#define  THIS CLASS::sPtr.Ptr
  static PTR<CLASS> sPtr;

  CLASS( const bool x /* = false */ )
  {
  }
    
  static bool Set()
  {
    return(THIS ? false : CLASS::sPtr.Set(new CLASS(true)));
  }  
#undef  THIS  
};

// Создается скрытый объект CLASS со скрытым конструктором.
// Ни создать CLASS-объект, ни обратиться к существующему нельзя
static PTR<CLASS> CLASS::sPtr = CLASS::Set();
 
Sergey Dzyublik:

The problem is with the default value, if you remove it, everything works as it should:

But in C++, it works with the default value, too. How does it affect it?

 

Has anyone managed to make MQL-based CryptEncode(CRYPT_ARCH_ZIP, data[], key[] = {1,0,0,0}, result[]) work with deflate compression from websocket? Public echo-server (echo.websocket.org) doesn't seem to support this extension, I haven't found any other echo-server and local node.js gives error "zlib invalid distance too far back" when trying to decrypt compressed data. I set server_max_window_bits=15; client_max_window_bits=15 in the header, but it doesn't seem to be the case as the server confirms these settings. On the MQL side I can't set anything except {1,0,0,0} key ;-(.

 
Stanislav Korotky:

Has anyone has hooked up MQL's CryptEncode(CRYPT_ARCH_ZIP, data[], key[] = {1,0,0,0}, result[]) with deflate compression from websocket? Public echo-server (echo.websocket.org) doesn't seem to support this extension, I haven't found any other echo-server and local node.js gives error "zlib invalid distance too far back" when trying to decrypt compressed data. I set server_max_window_bits=15; client_max_window_bits=15 in the header, but it doesn't seem to be the case as the server confirms these settings. On the MQL side I can't set anything except {1,0,0,0} key ;-(.

If I understood your question correctly, GZIP compression is mainly used in websockets for data packaging.
The CRYPT_ARCH_ZIP constant most likely packs to regular ZIP.
If you know how to pack/unpack GZIP using mql5, I'm also interested.

 
Roman:

If I understand the question correctly, websockets mostly use GZIP compression to pack data.
The CRYPT_ARCH_ZIP constant most likely packs to regular ZIP.
If you know how to pack/unpack GZIP, using mql5 tools, I'm also interested.

As far as I know, switch {1,0,0,0} removes all wrapping and leaves only compressed package. At least "Hello" word appears in compressed form in the same way in CryptEncode output and in deflate output. Accordingly, it should work the other way round as well. However, MQL does not give any more settings and does not show deflate's "default" settings used by it. Obviously they are different, but only max_window_bits and no_context_takeover can be controlled in the websocket - firstly they are clearly less than in the deflate algorithm (which is configured on the server), secondly even they cannot be configured in CryptEncode/Decode.