Closed fabri9532 closed 4 years ago
I think that this situation can be solved without requiring the modification of the callbacks signatures. In fact, in this case there are two options for the callback function:
Use a lambda which captures the this
pointer.
compressor.setTotalCallback( [this]( uint64_t total_size ) {
//both this and total_size are accessible
});
Use std::bind
with a (non-static) member function which takes the same parameters of the callback you need.
void MyClass::method() {
//...
auto callback = std::bind( &MyClass::callbackMethod, this, std::placeholders::_1 );
compressor.setTotalCallback( callback );
//...
}
//...
void MyClass:callbackMethod( uint64_t total_size ) {
//callback
}
Many thanks for the reply. The solution you proposed fully meets my needs.
Fabrizio.
You are welcome, glad to help!
Riccardo
Let me explain: When I use the library in a class, I need to declare tha Callback procedure as "static" member. With a static Callback procedure, I need to known from wich class object the call is made. So I need the "this" pointer to be passed to the Callback.
Modification example: Set Total callback: setTotalCallback( const TotalCallback &callback, void lpData ) TotalCallback: void(uint64_t total_size, void lpData)