219
|
1 |
#ifndef __ACCESSOR_H
|
|
2 |
#define __ACCESSOR_H
|
|
3 |
|
|
4 |
// variable declaration macros
|
|
5 |
#define __DECLARE_VAR(type, name)\
|
|
6 |
type name;
|
|
7 |
#define __DECLARE_GLOBAL(type, resource, name)\
|
|
8 |
type resource##__##name;\
|
|
9 |
static type *GLOBAL__##name = &resource##__##name;\
|
|
10 |
type __GET_GLOBAL_##name(void) {return *GLOBAL__##name;}\
|
|
11 |
void __SET_GLOBAL_##name(type value) {*GLOBAL__##name = value;}
|
|
12 |
#define __DECLARE_GLOBAL_LOCATION(type, location)\
|
|
13 |
extern type *location;
|
|
14 |
#define __DECLARE_GLOBAL_LOCATED(type, resource, name)\
|
|
15 |
type *resource##__##name;\
|
|
16 |
static type *GLOBAL__##name;\
|
|
17 |
type __GET_GLOBAL_##name(void) {return *GLOBAL__##name;}\
|
|
18 |
void __SET_GLOBAL_##name(type value) {*GLOBAL__##name = value;}
|
|
19 |
#define __DECLARE_EXTERNAL(type, name)\
|
|
20 |
type *name;
|
|
21 |
#define __DECLARE_LOCATED(type, name)\
|
|
22 |
type *name;
|
|
23 |
|
|
24 |
|
|
25 |
// variable initialization macros
|
|
26 |
#define __INIT_VAR(name, initial)\
|
|
27 |
name = initial;
|
|
28 |
#define __INIT_GLOBAL(name, initial)\
|
|
29 |
*GLOBAL__##name = initial;
|
|
30 |
#define __INIT_GLOBAL_LOCATED(resource, name, location)\
|
|
31 |
resource##__##name = location;\
|
|
32 |
GLOBAL__##name = location;
|
|
33 |
#define __INIT_EXTERNAL(type, global, name)\
|
|
34 |
{extern type *GLOBAL__##global;\
|
|
35 |
name = GLOBAL__##global;}
|
|
36 |
#define __INIT_LOCATED(type, location, name)\
|
|
37 |
{extern type *location;\
|
|
38 |
name = location;}
|
|
39 |
#define __INIT_LOCATED_VALUE(name, initial)\
|
|
40 |
*name = initial;
|
|
41 |
|
|
42 |
|
|
43 |
// variable getting macros
|
|
44 |
#define __GET_VAR(name)\
|
|
45 |
name
|
|
46 |
#define __GET_EXTERNAL(name)\
|
|
47 |
__GET_GLOBAL_##name()
|
|
48 |
#define __GET_LOCATED(name)\
|
|
49 |
*(name)
|
|
50 |
#define __GET_VAR_BY_REF(name)\
|
|
51 |
&(name)
|
|
52 |
#define __GET_EXTERNAL_BY_REF(name)\
|
|
53 |
GLOBAL__##name
|
|
54 |
#define __GET_LOCATED_BY_REF(name)\
|
|
55 |
name
|
|
56 |
|
|
57 |
// variable setting macros
|
|
58 |
#define __SET_VAR(name, new_value)\
|
|
59 |
name = new_value
|
|
60 |
#define __SET_EXTERNAL(name, new_value)\
|
|
61 |
__SET_GLOBAL_##name(value)
|
|
62 |
#define __SET_LOCATED(name, new_value)\
|
|
63 |
*(name) = value
|
|
64 |
|
|
65 |
#endif //__ACCESSOR_H
|