edelib: edelib/edelib-global.h Source File

edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

edelib-global.h
1 /*
2 * $Id: edelib-global.h 3328 2012-05-25 14:24:02Z karijes $
3 *
4 * Base defs for edelib
5 * Copyright (c) 2005-2009 edelib authors
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __EDELIB_EDELIB_GLOBAL_H__
22 #define __EDELIB_EDELIB_GLOBAL_H__
23
24 /* Needed so we don't have to include necessary libraries. */
25 #ifndef NULL
26 # ifndef __cplusplus
27 # define NULL ((void*)0)
28 # else
29 # define NULL 0
30 # endif
31 #endif
32
38 #ifndef EDELIB_NS
39 # define EDELIB_NS edelib
40 #endif
41
42 #ifdef EDELIB_NS
43 # define EDELIB_NS_BEGIN namespace EDELIB_NS {
44 # define EDELIB_NS_END }
45 #else
46 # define EDELIB_NS_BEGIN
47 # define EDELIB_NS_END
48 #endif
49
65 #ifdef EDELIB_NS
66 # define EDELIB_NS_USE using namespace EDELIB_NS;
67 #else
68 # define EDELIB_NS_USE
69 #endif
70
78 #ifdef EDELIB_NS
79 # define EDELIB_NS_USING(n) using EDELIB_NS::n;
80 #else
81 # define EDELIB_NS_USING(n)
82 #endif
83
91 #ifdef EDELIB_NS
92 # define EDELIB_NS_USING_AS(old_name, new_name) typedef EDELIB_NS::old_name new_name;
93 #else
94 # define EDELIB_NS_USING_AS(old_name, new_name) typedef old_name new_name;
95 #endif
96
102 #ifdef EDELIB_NS
103 # define EDELIB_NS_PREPEND(n) EDELIB_NS::n
104 #else
105 # define EDELIB_NS_PREPEND(n) n
106 #endif
107
118 #include "for-each-macro.h"
119
120 #ifdef EDELIB_FOR_EACH_FUNC
121 # define EDELIB_FOR_EACH_FUNC_OLD__ EDELIB_FOR_EACH_FUNC
122 #endif
123
124 #define EDELIB_FOR_EACH_FUNC EDELIB_NS_USING
125 #define EDELIB_NS_USING_LIST(n, list) EDELIB_FOR_EACH(n, list)
126
127 #ifdef EDELIB_FOR_EACH_FUNC_OLD__
128 # define EDELIB_FOR_EACH_FUNC EDELIB_FOR_EACH_FUNC_OLD__
129 # undef EDELIB_FOR_EACH_FUNC_OLD__
130 #endif
131
143 #if __GNUC__ >= 4
144 # define E_EXPORT __attribute__ ((visibility("default")))
145 # define E_NO_EXPORT __attribute__ ((visibility("hidden")))
146 #else
147 # define E_EXPORT
148 # define E_NO_EXPORT
149 #endif
150
151 #define EDELIB_API E_EXPORT
152 #define EDELIB_NO_API E_NO_EXPORT
153
161 #define E_DISABLE_CLASS_COPY(klass) \
162 klass(const klass&); \
163 klass& operator=(klass&);
164
176 #define E_CLASS_GLOBAL_DECLARE(klass) \
177 static klass* global(void);
178
186 #define E_CLASS_GLOBAL_IMPLEMENT(klass) \
187 klass* klass::global(void) { \
188 static klass obj; \
189 return &obj; \
190 }
191
203 #define E_CLASS_GLOBAL_EXPLICIT_DECLARE(klass) \
204 static void init(void); \
205 static void shutdown(void); \
206 static bool inited(void); \
207 static klass* global(void);
208
215 #define E_CLASS_GLOBAL_EXPLICIT_IMPLEMENT(klass) \
216 klass* klass##_instance = NULL; \
217 \
218 void klass::init(void) { \
219 if(!klass##_instance) \
220 klass##_instance = new klass(); \
221 } \
222 \
223 void klass::shutdown(void) { \
224 delete klass##_instance; \
225 klass##_instance = NULL; \
226 } \
227 \
228 bool klass::inited(void) { \
229 return (klass##_instance != NULL); \
230 } \
231 \
232 klass* klass::global(void) { \
233 E_ASSERT(klass##_instance != NULL && "Did you run init() first?"); \
234 return klass##_instance; \
235 }
236
237
238 #ifdef __GNUC__
239 # define EDELIB_DEPRECATED __attribute__ ((deprecated))
240 #else
241 # define EDELIB_DEPRECATED
242 #endif
243
244 #include "edelib-config.h"
245 #endif