summaryrefslogtreecommitdiff
path: root/pktmpln.h
blob: 64000ef73ab16726c917f5296a01b83c92343464 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef PK_PKTMPLN_H
#define PK_PKTMPLN_H

#if defined (__cplusplus)
#include <functional>
template<typename Ret, typename A1, typename B1>
struct pk_tmpln_1 {
	using FuncType = std::function<Ret(A1)>;
	FuncType func;
	static Ret invoke(void *ptr, B1 b1) {
		auto *self = static_cast<pk_tmpln_1*>(ptr);
		return self->func(reinterpret_cast<A1>(b1));
	}
};
template<typename Ret, typename A1, typename A2, typename B1, typename B2>
struct pk_tmpln_2 {
	using FuncType = std::function<Ret(A1, A2)>;
	FuncType func;
	static Ret invoke(void *ptr, B1 b1, B2 b2) {
		auto *self = static_cast<pk_tmpln_2*>(ptr);
		return self->func(reinterpret_cast<A1>(b1), reinterpret_cast<A2>(b2));
	}
};
template<typename Ret, typename A1, typename A2, typename A3, typename B1, typename B2, typename B3>
struct pk_tmpln_3 {
	using FuncType = std::function<Ret(A1, A2, A3)>;
	FuncType func;
	static Ret invoke(void *ptr, B1 b1, B2 b2, B3 b3) {
		auto *self = static_cast<pk_tmpln_3*>(ptr);
		return self->func(reinterpret_cast<A1>(b1), reinterpret_cast<A2>(b2), reinterpret_cast<A3>(b3));
	}
};
#endif

#endif /* PK_PKTMPLN_H */