#ifndef H_CORAL_CORAL
#define H_CORAL_CORAL
// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

#if defined(_WIN32) || defined(__WIN32__) || defined(__MINGW32__)
# define PLATFORM_WINDOWS
# define CORAL_HIDDEN
# ifdef COMPILING_coral
#  define EXPORT_coral __declspec(dllexport)
# else
#  define EXPORT_coral __declspec(dllimport)
# endif
# define EXPORTFWD_coral EXPORT_coral
#else
# define PLATFORM_UNIX
# ifdef HAVE_CPLUSPLUS_VISIBILITY
#  define EXPORT_coral __attribute__((visibility("default")))
#  define CORAL_HIDDEN  __attribute__((visibility("hidden")))
#  define EXPORTFWD_coral
# else
#  define EXPORT_coral
#  define CORAL_HIDDEN
#  define EXPORTFWD_coral
# endif
#ifdef linux
# define CFG_HAS_BACKTRACE
#endif
#endif

#include <locale>

namespace coral {

	extern std::locale clocale;
/*
 * Coral general C++ defines, declarations and so on
 */

#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))

/* Repeatedly calls "x" until it does not throw anything. */
#define MUST_WORK(x) do { try { (x); } catch (...) { continue; } break; } while (1)

/* Can throw anything, we ignore it. Must still be executed.*/
#define MAY_FAIL(x) do { try { (x); } catch (...) { ; } } while (0)

/* Can throw anything, we ignore it. Not executed in non-debug mode. */
#ifndef NDEBUG
#define DEBUG_MAY_FAIL(x) do { try { (x); } catch (...) { ; } } while (0)
#else
#define DEBUG_MAY_FAIL(x) do { ; } while(0)
#endif

#define NAMESPACE_BEGIN(x) namespace x {
#define NAMESPACE_END() }

#define DELEGATE_FUNC(type, function, constness, variable) \
inline type function() constness { return this->variable.function(); }
#define DELEGATE_TYPE(variable, variable_name, name) \
typedef variable::variable_name name
#define DELEGATE_CONST_TYPE(variable, variable_name, name) \
typedef const variable::variable_name name

#ifdef __cplusplus
#define BEGINCPP extern "C" {
#define ENDCPP   }
#else
#define BEGINCPP 
#define ENDCPP   
#endif

#ifndef SWIG

/* Initializes the Coral framework. Returns true on success. */
int EXPORT_coral init_coral_framework() throw ();

/** Debug function to print backtrace. Required by coral_assert. */
void EXPORT_coral print_backtrace() throw ();

#endif

}

#endif
