edelib/edelib-global.h

00001 /*
00002  * $Id: edelib-global.h 2614 2009-03-30 15:10:53Z karijes $
00003  *
00004  * Base defs for edelib
00005  * Copyright (c) 2005-2009 edelib authors
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef __EDELIB_GLOBAL_H__
00022 #define __EDELIB_GLOBAL_H__
00023 
00024 /* Needed so we don't have to include necessary libraries.  */
00025 #ifndef NULL
00026 # ifndef __cplusplus
00027 #  define NULL ((void*)0)
00028 # else 
00029 #  define NULL 0
00030 # endif
00031 #endif
00032 
00038 #ifndef EDELIB_NS
00039 # define EDELIB_NS edelib
00040 #endif
00041 
00042 #ifdef EDELIB_NS
00043 # define EDELIB_NS_BEGIN namespace EDELIB_NS {
00044 # define EDELIB_NS_END   }
00045 #else
00046 # define EDELIB_NS_BEGIN
00047 # define EDELIB_NS_END
00048 #endif
00049 
00065 #ifdef EDELIB_NS
00066 # define EDELIB_NS_USE using namespace EDELIB_NS;
00067 #else
00068 # define EDELIB_NS_USE
00069 #endif
00070 
00078 #ifdef EDELIB_NS
00079 # define EDELIB_NS_USING(n) using EDELIB_NS::n;
00080 #else
00081 # define EDELIB_NS_USING(n)
00082 #endif
00083 
00091 #ifdef EDELIB_NS
00092 # define EDELIB_NS_USING_AS(old_name, new_name) typedef EDELIB_NS::old_name new_name;
00093 #else
00094 # define EDELIB_NS_USING_AS(old_name, new_name) typedef old_name new_name;
00095 #endif
00096 
00102 #ifdef EDELIB_NS
00103 # define EDELIB_NS_PREPEND(n) EDELIB_NS::n
00104 #else
00105 # define EDELIB_NS_PREPEND(n) n
00106 #endif
00107 
00119 #if __GNUC__ >= 4
00120 # define E_EXPORT __attribute__ ((visibility("default")))
00121 # define E_NO_EXPORT __attribute__ ((visibility("hidden")))
00122 #else
00123 # define E_EXPORT
00124 # define E_NO_EXPORT
00125 #endif
00126 
00127 #define EDELIB_API E_EXPORT
00128 #define EDELIB_NO_API E_NO_EXPORT
00129 
00137 #define E_DISABLE_CLASS_COPY(klass) \
00138         klass(const klass&);            \
00139         klass& operator=(klass&);
00140 
00152 #define E_CLASS_GLOBAL_DECLARE(klass) \
00153         static klass* global(void);
00154 
00162 #define E_CLASS_GLOBAL_IMPLEMENT(klass) \
00163         klass* klass::global(void) {        \
00164                 static klass obj;               \
00165                 return &obj;                    \
00166         }
00167 
00179 #define E_CLASS_GLOBAL_EXPLICIT_DECLARE(klass) \
00180         static void init(void);                    \
00181         static void shutdown(void);                \
00182         static bool inited(void);                  \
00183         static klass* global(void);
00184 
00191 #define E_CLASS_GLOBAL_EXPLICIT_IMPLEMENT(klass)                           \
00192         klass* klass##_instance = NULL;                                        \
00193                                                                            \
00194         void klass::init(void) {                                               \
00195                 if(!klass##_instance)                                              \
00196                         klass##_instance = new klass();                                \
00197         }                                                                      \
00198                                                                            \
00199         void klass::shutdown(void) {                                           \
00200                 delete klass##_instance;                                           \
00201                 klass##_instance = NULL;                                           \
00202         }                                                                      \
00203                                                                            \
00204         bool klass::inited(void) {                                             \
00205                 return (klass##_instance != NULL);                                 \
00206         }                                                                      \
00207                                                                            \
00208         klass* klass::global(void) {                                           \
00209                 E_ASSERT(klass##_instance != NULL && "Did you run init() first?"); \
00210                 return klass##_instance;                                           \
00211         }
00212                                                 
00213 
00214 #ifdef __GNUC__
00215 # define EDELIB_DEPRECATED __attribute__ ((deprecated))
00216 #else
00217 # define EDELIB_DEPRECATED
00218 #endif
00219 
00220 #ifdef HAVE_EDELIB_BASE_CONFIG_H
00221 # include "_conf.h"
00222 #endif
00223 
00224 #endif

Generated on Wed Dec 16 14:31:52 2009 for edelib by  doxygen 1.5.2