FastArduino  v1.9
C++ library to build fast but small Arduino/AVR projects
virtual_support::VirtualMethod Class Reference

Holder of a "virtual method". More...

#include <fastarduino/virtual.h>

Public Types

using METHOD = void(*)(void *)
 The type of function that will get the call.
 

Public Member Functions

 VirtualMethod (const VirtualMethod &)=default
 
VirtualMethodoperator= (const VirtualMethod &)=default
 
 VirtualMethod (METHOD method=nullptr, void *arg=nullptr)
 Create a VirtualMethod with the given arguments. More...
 
void operator() () const
 Call dispatching method.
 

Detailed Description

Holder of a "virtual method".

Typical use:

class A {
public:
A(VirtualMethod::METHOD callback, void* arg) : callback_{callback, arg} {}
void call_back() {
callback_();
}
private:
VirtualMethod callback_;
}
class B {
public:
B() : a{B::callback, this} {}
private:
// this is the actual "virtual" method
void do_something() {
...
}
// this method is in hcarge of dispatching to the actual "virtual" method
static void callback(void* arg) {
((B*) arg)->do_something();
}
A a;
}
void(*)(void *) METHOD
The type of function that will get the call.
Definition: virtual.h:78

Definition at line 69 of file virtual.h.

Constructor & Destructor Documentation

◆ VirtualMethod()

virtual_support::VirtualMethod::VirtualMethod ( METHOD  method = nullptr,
void *  arg = nullptr 
)
inlineexplicit

Create a VirtualMethod with the given arguments.

Parameters
methodthe method that will receive the call and shall dispatch to the proper method of the proper object, which pointer is given by arg
arga pointer to the object that should receive the actual dispatch

Definition at line 86 of file virtual.h.


The documentation for this class was generated from the following file: