ekg2  GIT master
objects.h
Idź do dokumentacji tego pliku.
1 /* $Id$ */
2 
3 /*
4  * (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef __EKG_OBJECTS_H
21 #define __EKG_OBJECTS_H
22 
23 #include "xmalloc.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define PROPERTY_INT_GET(object,property,type) \
30  \
31  type object##_##property##_get(object##_t *o) \
32  { \
33  return (o) ? o->property : -1; \
34  }
35 
36 #define PROPERTY_INT_SET(object,property,type) \
37  \
38  int object##_##property##_set(object##_t *o, type v) \
39  { \
40  if (!o) \
41  return -1; \
42  \
43  o->property = v; \
44  \
45  return 0; \
46  }
47 
48 #define PROPERTY_INT(object,property,type) \
49  \
50  PROPERTY_INT_GET(object,property,type) \
51  PROPERTY_INT_SET(object,property,type)
52 
53 
54 
55 #define PROPERTY_STRING_GET(object,property) \
56  \
57  const char *object##_##property##_get(object##_t *o) \
58  { \
59  return (o) ? o->property : NULL; \
60  }
61 
62 
63 #define PROPERTY_STRING_SET(object,property) \
64  \
65  int object##_##property##_set(object##_t *o, const char *v) \
66  { \
67  if (!o) \
68  return -1; \
69  \
70  xfree(o->property); \
71  o->property = xstrdup(v); \
72  \
73  return 0; \
74  }
75 
76 #define PROPERTY_STRING(object,property) \
77 \
78 PROPERTY_STRING_SET(object, property) \
79 PROPERTY_STRING_GET(object, property)
80 
81 
82 #define PROPERTY_PRIVATE_GET(object) \
83  \
84  void *object##_private_get(object##_t *o) \
85  { \
86  return (o) ? o->priv : NULL; \
87  }
88 
89 #define PROPERTY_PRIVATE_SET(object) \
90  \
91  int object##_private_set(object##_t *o, void *v) \
92  { \
93  if (!o) \
94  return -1; \
95  \
96  o->priv = v; \
97  \
98  return 0; \
99  }
100 
101 #define PROPERTY_PRIVATE(object) \
102  \
103  PROPERTY_PRIVATE_GET(object) \
104  PROPERTY_PRIVATE_SET(object)
105 
106 
107 #define PROPERTY_MISC_GET(object,property,type,null) \
108  \
109  type object##_##property##_get(object##_t *o) \
110  { \
111  return (o) ? o->property : null; \
112  }
113 
114 #define PROPERTY_MISC_SET(object,property,type) \
115  \
116  int object##_##property##_set(object##_t *o, type v) \
117  { \
118  if (!o) \
119  return -1; \
120  \
121  o->property = v; \
122  \
123  return 0; \
124  }
125 
126 #define PROPERTY_MISC(object,property,type,null) \
127  \
128  PROPERTY_MISC_GET(object,property,type,null) \
129  PROPERTY_MISC_SET(object,property,type)
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /* __EKG_OOP_H */
136 
137 
138 /*
139  * Local Variables:
140  * mode: c
141  * c-file-style: "k&r"
142  * c-basic-offset: 8
143  * indent-tabs-mode: t
144  * End:
145  */