taskrambler  0.1.9
Web server and task management solution.
interface.h
Go to the documentation of this file.
1 /**
2  * \file
3  * Interface definition code. Each interface is a set of selector functions
4  * as well as a data structure where the concrete implementation will be stored.
5  * This structure is the intergrated in the class that implements the
6  * interface.
7  *
8  * \author Georg Hopp
9  *
10  * \copyright
11  * Copyright © 2012 Georg Hopp
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #ifndef __CLASS_INTERFACE_H__
28 #define __CLASS_INTERFACE_H__
29 
30 #include <sys/types.h>
31 
32 #define MAX_IFACE 32 // ATTENTION: every iface_impl will use MAX_IFACE * sizeof(void*)
33 
34 #define IFACE(name) ((const struct i_##name const*)&i_##name##_impl)
35 #define INIT_IFACE(name,...) \
36  static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__}
37 
38 #define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*))
39 #define INIT_IFACE_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}}
40 
41 
42 struct interface {
43  const char * name;
44  const size_t nmethods;
45 };
46 typedef const struct interface * iface_ptr;
47 
48 struct iface_impl {
49  const size_t nimpl; // number of interface implementations
50  char simpl; // implementations sorted??
51  const void * impl[MAX_IFACE]; // implementations
52 };
53 typedef struct iface_impl * iface_impl_ptr;
54 
55 extern iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr);
56 
57 #endif // __CLASS_INTERFACE_H__
58 
59 // vim: set ts=4 sw=4:
const struct interface * iface_ptr
Definition: interface.h:46
const size_t nmethods
Definition: interface.h:44
const char * name
Definition: interface.h:43
const void * impl[MAX_IFACE]
Definition: interface.h:51
iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr)
Definition: interface.c:44
const size_t nimpl
Definition: interface.h:49
char simpl
Definition: interface.h:50
#define MAX_IFACE
Definition: interface.h:32