FastArduino  v1.9
C++ library to build fast but small Arduino/AVR projects
virtual.h
Go to the documentation of this file.
1 // Copyright 2016-2022 Jean-Francois Poilpret
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
23 #ifndef VIRTUAL_HH
24 #define VIRTUAL_HH
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 
34 namespace virtual_support
35 {
70  {
71  public:
72  VirtualMethod(const VirtualMethod&) = default;
73  VirtualMethod& operator=(const VirtualMethod&) = default;
74 
78  using METHOD = void (*)(void*);
79 
86  explicit VirtualMethod(METHOD method = nullptr, void* arg = nullptr): method_{method}, arg_{arg} {}
87 
91  void operator()() const
92  {
93  if (method_ != nullptr)
94  method_(arg_);
95  }
96 
97  private:
98  const METHOD method_;
99  void* const arg_;
100  };
101 
102 }
103 
104 #endif /* VIRTUAL_HH */
Holder of a "virtual method".
Definition: virtual.h:70
VirtualMethod(METHOD method=nullptr, void *arg=nullptr)
Create a VirtualMethod with the given arguments.
Definition: virtual.h:86
void(*)(void *) METHOD
The type of function that will get the call.
Definition: virtual.h:78
void operator()() const
Call dispatching method.
Definition: virtual.h:91
Defines utility types for emulating virtual methods.
Definition: virtual.h:35