ekg2
|
00001 /* $Id$ */ 00002 00003 /* 00004 * (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License Version 2 as 00008 * published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __EKG_OBJECTS_H 00021 #define __EKG_OBJECTS_H 00022 00023 #include "xmalloc.h" 00024 00025 #ifdef __cplusplus 00026 extern "C" { 00027 #endif 00028 00029 #define PROPERTY_INT_GET(object,property,type) \ 00030 \ 00031 type object##_##property##_get(object##_t *o) \ 00032 { \ 00033 return (o) ? o->property : -1; \ 00034 } 00035 00036 #define PROPERTY_INT_SET(object,property,type) \ 00037 \ 00038 int object##_##property##_set(object##_t *o, type v) \ 00039 { \ 00040 if (!o) \ 00041 return -1; \ 00042 \ 00043 o->property = v; \ 00044 \ 00045 return 0; \ 00046 } 00047 00048 #define PROPERTY_INT(object,property,type) \ 00049 \ 00050 PROPERTY_INT_GET(object,property,type) \ 00051 PROPERTY_INT_SET(object,property,type) 00052 00053 00054 00055 #define PROPERTY_STRING_GET(object,property) \ 00056 \ 00057 const char *object##_##property##_get(object##_t *o) \ 00058 { \ 00059 return (o) ? o->property : NULL; \ 00060 } 00061 00062 00063 #define PROPERTY_STRING_SET(object,property) \ 00064 \ 00065 int object##_##property##_set(object##_t *o, const char *v) \ 00066 { \ 00067 if (!o) \ 00068 return -1; \ 00069 \ 00070 xfree(o->property); \ 00071 o->property = xstrdup(v); \ 00072 \ 00073 return 0; \ 00074 } 00075 00076 #define PROPERTY_STRING(object,property) \ 00077 \ 00078 PROPERTY_STRING_SET(object, property) \ 00079 PROPERTY_STRING_GET(object, property) 00080 00081 00082 #define PROPERTY_PRIVATE_GET(object) \ 00083 \ 00084 void *object##_private_get(object##_t *o) \ 00085 { \ 00086 return (o) ? o->priv : NULL; \ 00087 } 00088 00089 #define PROPERTY_PRIVATE_SET(object) \ 00090 \ 00091 int object##_private_set(object##_t *o, void *v) \ 00092 { \ 00093 if (!o) \ 00094 return -1; \ 00095 \ 00096 o->priv = v; \ 00097 \ 00098 return 0; \ 00099 } 00100 00101 #define PROPERTY_PRIVATE(object) \ 00102 \ 00103 PROPERTY_PRIVATE_GET(object) \ 00104 PROPERTY_PRIVATE_SET(object) 00105 00106 00107 #define PROPERTY_MISC_GET(object,property,type,null) \ 00108 \ 00109 type object##_##property##_get(object##_t *o) \ 00110 { \ 00111 return (o) ? o->property : null; \ 00112 } 00113 00114 #define PROPERTY_MISC_SET(object,property,type) \ 00115 \ 00116 int object##_##property##_set(object##_t *o, type v) \ 00117 { \ 00118 if (!o) \ 00119 return -1; \ 00120 \ 00121 o->property = v; \ 00122 \ 00123 return 0; \ 00124 } 00125 00126 #define PROPERTY_MISC(object,property,type,null) \ 00127 \ 00128 PROPERTY_MISC_GET(object,property,type,null) \ 00129 PROPERTY_MISC_SET(object,property,type) 00130 00131 #ifdef __cplusplus 00132 } 00133 #endif 00134 00135 #endif /* __EKG_OOP_H */ 00136 00137 00138 /* 00139 * Local Variables: 00140 * mode: c 00141 * c-file-style: "k&r" 00142 * c-basic-offset: 8 00143 * indent-tabs-mode: t 00144 * End: 00145 */