FreeNOS
Callback.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBSTD_CALLBACK_H
19#define __LIBSTD_CALLBACK_H
20
21#include "Types.h"
22
35{
36 public:
37
43 virtual void execute(void *parameter) = 0;
44};
45
49template <class Base, class ParamType> class Callback : public CallbackFunction
50{
51 private:
52
54 typedef void (Base::*Function)(ParamType *param);
55
56 public:
57
64 Callback(Base *object, Function func)
65 {
66 m_object = object;
67 m_function = func;
68 }
69
75 virtual void execute(void *parameter)
76 {
77 executeOnObject((ParamType *) parameter);
78 }
79
80 private:
81
87 virtual void executeOnObject(ParamType *parameter)
88 {
89 (m_object->*m_function)(parameter);
90 }
91
92 private:
93
95 Base *m_object;
96
99};
100
106#endif /* __LIBSTD_CALLBACK_H */
Represents a callback function.
Definition Callback.h:35
virtual void execute(void *parameter)=0
Execute the callback.
Abstraction for providing a callback function to a object instance.
Definition Callback.h:50
Function m_function
Function pointer.
Definition Callback.h:98
virtual void executeOnObject(ParamType *parameter)
Execute the callback.
Definition Callback.h:87
Base * m_object
Object instance.
Definition Callback.h:95
void(Base::* Function)(ParamType *param)
Callback function prototype.
Definition Callback.h:54
virtual void execute(void *parameter)
Invoke the callback function on the object.
Definition Callback.h:75
Callback(Base *object, Function func)
Constructor.
Definition Callback.h:64
void param(Terminal *term, int key, int value)
Set terminal parameters.
Definition Terminal.cpp:305