/*

 Owner: Michael Ehrmann, michael@boinx.com
 Company: Boinx Software Ltd., Germany
 Projects: BXBase, BXQuartzComposer, BXReadMeViewer
 
 Abstract: Globally defined macros
 
*/


#ifdef __OBJC__

#if !defined(NSINTEGER_DEFINED) || NSINTEGER_DEFINED == 0
#if __LP64__ || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif

#define NSIntegerMax    LONG_MAX
#define NSIntegerMin    LONG_MIN
#define NSUIntegerMax   ULONG_MAX

#define NSINTEGER_DEFINED 1
#endif

#define BX_APPLICATION_SUPPORT_FOLDER_NAME @"Boinx"

#if !defined(CGFLOAT_DEFINED) || CGFLOAT_DEFINED == 0
#if defined(__LP64__) && __LP64__
typedef double CGFloat;
#define CGFLOAT_MIN DBL_MIN
#define CGFLOAT_MAX DBL_MAX
#define CGFLOAT_IS_DOUBLE 1
#else	/* !defined(__LP64__) || !__LP64__ */
typedef float CGFloat;
#define CGFLOAT_MIN FLT_MIN
#define CGFLOAT_MAX FLT_MAX
#define CGFLOAT_IS_DOUBLE 0
#endif	/* !defined(__LP64__) || !__LP64__ */
#define CGFLOAT_DEFINED 1
#endif

#pragma mark ObjC defines
#ifndef PREFS
#define PREFS [NSUserDefaults standardUserDefaults]
#endif

#ifndef DEFAULTS
#define DEFAULTS [NSUserDefaults standardUserDefaults]
#endif

#ifndef CLASS_BUNDLE
#define CLASS_BUNDLE [NSBundle bundleForClass:[self class]]
#endif

#ifndef MAIN_BUNDLE
#define MAIN_BUNDLE [NSBundle mainBundle]
#endif

#ifndef SYNTHESIZE
#define SYNTHESIZE(x) @synthesize x = _##x
#endif


#pragma mark ObjC function macros
#ifndef BXRelease
#define BXRelease(object) do { if (object) { id old = object; object = nil; [old release]; } } while (false)
#endif

#ifndef BXAutorelease
#define BXAutorelease(object) do { if (object) { id old = object; object = nil; [old autorelease]; } } while (false)
#endif

#ifndef BXNSRectToCGRect
#define BXNSRectToCGRect(r) CGRectMake(r.origin.x, r.origin.y, r.size.width, r.size.height)
#endif

#ifndef BXNSSizeToCGSize
#define BXNSSizeToCGSize(r) CGSizeMake(r.width, r.height)
#endif

#ifndef BXNSPointToCGoint
#define BXNSPointToCGoint(r) CGPointMake(r.x, r.y)
#endif

#ifndef BXCGRectToNSRect
#define BXCGRectToNSRect(r) NSMakeRect(r.origin.x, r.origin.y, r.size.width, r.size.height)
#endif

#ifndef BXCGSizeToNSSize
#define BXCGSizeToNSSize(r) NSMakeSize(r.width, r.height)
#endif

#ifndef BXCGPointToNSPoint
#define BXCGPointToNSPoint(r) NSMakePoint(r.x, r.y)
#endif

#endif



#pragma mark -
#pragma mark Pure C function macros

#ifndef BXClipValue
#define BXClipValue(x,a,b) do { if ((x)<(a)) (x)=(a); else if ((x)>(b)) (x)=(b); } while (false)
#endif

#ifndef BXCFRelease
#define BXCFRelease(object) do { if (object) { CFTypeRef old = object; object = NULL; CFRelease(old); } } while (false)
#endif

#ifndef BXFree
#define BXFree(block) do { if (block) { free(block); block=NULL; } } while (false)
#endif
