edelib-global.h
/*
* $Id: edelib-global.h 3328 2012-05-25 14:24:02Z karijes $
*
* Base defs for edelib
* Copyright (c) 2005-2009 edelib authors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EDELIB_EDELIB_GLOBAL_H__
#define __EDELIB_EDELIB_GLOBAL_H__
/* Needed so we don't have to include necessary libraries. */
#ifndef NULL
# ifndef __cplusplus
# define NULL ((void*)0)
# else
# define NULL 0
# endif
#endif
#ifndef EDELIB_NS
# define EDELIB_NS edelib
#endif
#ifdef EDELIB_NS
# define EDELIB_NS_BEGIN namespace EDELIB_NS {
# define EDELIB_NS_END }
#else
# define EDELIB_NS_BEGIN
# define EDELIB_NS_END
#endif
#ifdef EDELIB_NS
# define EDELIB_NS_USE using namespace EDELIB_NS;
#else
# define EDELIB_NS_USE
#endif
#ifdef EDELIB_NS
# define EDELIB_NS_USING(n) using EDELIB_NS::n;
#else
# define EDELIB_NS_USING(n)
#endif
#ifdef EDELIB_NS
# define EDELIB_NS_USING_AS(old_name, new_name) typedef EDELIB_NS::old_name new_name;
#else
# define EDELIB_NS_USING_AS(old_name, new_name) typedef old_name new_name;
#endif
#ifdef EDELIB_NS
# define EDELIB_NS_PREPEND(n) EDELIB_NS::n
#else
# define EDELIB_NS_PREPEND(n) n
#endif
#include "for-each-macro.h"
#ifdef EDELIB_FOR_EACH_FUNC
# define EDELIB_FOR_EACH_FUNC_OLD__ EDELIB_FOR_EACH_FUNC
#endif
#define EDELIB_FOR_EACH_FUNC EDELIB_NS_USING
#define EDELIB_NS_USING_LIST(n, list) EDELIB_FOR_EACH(n, list)
#ifdef EDELIB_FOR_EACH_FUNC_OLD__
# define EDELIB_FOR_EACH_FUNC EDELIB_FOR_EACH_FUNC_OLD__
# undef EDELIB_FOR_EACH_FUNC_OLD__
#endif
#if __GNUC__ >= 4
# define E_EXPORT __attribute__ ((visibility("default")))
# define E_NO_EXPORT __attribute__ ((visibility("hidden")))
#else
# define E_EXPORT
# define E_NO_EXPORT
#endif
#define EDELIB_API E_EXPORT
#define EDELIB_NO_API E_NO_EXPORT
#define E_DISABLE_CLASS_COPY(klass) \
klass(const klass&); \
klass& operator=(klass&);
#define E_CLASS_GLOBAL_DECLARE(klass) \
static klass* global(void);
#define E_CLASS_GLOBAL_IMPLEMENT(klass) \
klass* klass::global(void) { \
static klass obj; \
return &obj; \
}
#define E_CLASS_GLOBAL_EXPLICIT_DECLARE(klass) \
static void init(void); \
static void shutdown(void); \
static bool inited(void); \
static klass* global(void);
#define E_CLASS_GLOBAL_EXPLICIT_IMPLEMENT(klass) \
klass* klass##_instance = NULL; \
\
void klass::init(void) { \
if(!klass##_instance) \
klass##_instance = new klass(); \
} \
\
void klass::shutdown(void) { \
delete klass##_instance; \
klass##_instance = NULL; \
} \
\
bool klass::inited(void) { \
return (klass##_instance != NULL); \
} \
\
klass* klass::global(void) { \
E_ASSERT(klass##_instance != NULL && "Did you run init() first?"); \
return klass##_instance; \
}
#ifdef __GNUC__
# define EDELIB_DEPRECATED __attribute__ ((deprecated))
#else
# define EDELIB_DEPRECATED
#endif
#include "edelib-config.h"
#endif