mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
* foundaton/NSException.h: Added NSAssert macros and
NSAssertionHandler interface. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@343 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
618cd00c85
commit
1f358f658b
1 changed files with 90 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Interface for NSArray for GNUStep
|
||||
/* Interface for NSException for GNUStep
|
||||
Copyright (C) 1994 NeXT Computer, Inc.
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
@ -118,4 +118,93 @@ extern void _NSRemoveHandler( NSHandler *handler );
|
|||
#define NS_VOIDRETURN do { _NSRemoveHandler(&NSLocalHandler); \
|
||||
return; } while (0)
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* Assertion Handling */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@interface NSAssertionHandler : NSObject
|
||||
|
||||
+ (NSAssertionHandler *)currentHandler;
|
||||
|
||||
- (void)handleFailureInFunction:(NSString *)functionName
|
||||
file:(NSString *)fileName
|
||||
lineNumber:(int)line
|
||||
description:(NSString *)format,...;
|
||||
|
||||
- (void)handleFailureInMethod:(SEL)aSelector
|
||||
object:object
|
||||
file:(NSString *)fileName
|
||||
lineNumber:(int)line
|
||||
description:(NSString *)format,...;
|
||||
|
||||
@end
|
||||
|
||||
#define _NSAssertArgs(condition, desc, args...) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
[[NSAssertionHandler currentHandler] \
|
||||
handleFailureInMethod:_cmd \
|
||||
object:self \
|
||||
file:[NSString stringWithCString:__FILE__] \
|
||||
lineNumber:__LINE__ \
|
||||
description:(desc), ## args]; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define _NSCAssertArgs(condition, desc, args...) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
[[NSAssertionHandler currentHandler] \
|
||||
handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__] \
|
||||
file:[NSString stringWithCString:__FILE__] \
|
||||
lineNumber:__LINE__ \
|
||||
description:(desc), ## args]; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
/* Asserts to use in Objective-C method bodies*/
|
||||
#define NSAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5) \
|
||||
_NSAssertArgs((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
|
||||
|
||||
#define NSAssert4(condition, desc, arg1, arg2, arg3, arg4) \
|
||||
_NSAssertArgs((condition), (desc), (arg1), (arg2), (arg3), (arg4))
|
||||
|
||||
#define NSAssert3(condition, desc, arg1, arg2, arg3) \
|
||||
_NSAssertArgs((condition), (desc), (arg1), (arg2), (arg3))
|
||||
|
||||
#define NSAssert2(condition, desc, arg1, arg2) \
|
||||
_NSAssertArgs((condition), (desc), (arg1), (arg2))
|
||||
|
||||
#define NSAssert1(condition, desc, arg1) \
|
||||
_NSAssertArgs((condition), (desc), (arg1))
|
||||
|
||||
#define NSAssert(condition, desc) \
|
||||
_NSAssertArgs((condition), (desc))
|
||||
|
||||
#define NSParameterAssert(condition) \
|
||||
_NSAssertArgs((condition), @"Invalid parameter not satisfying: %s", #condition)
|
||||
|
||||
/* Asserts to use in C function bodies */
|
||||
#define NSCAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5) \
|
||||
_NSCAssertArgs((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
|
||||
|
||||
#define NSCAssert4(condition, desc, arg1, arg2, arg3, arg4) \
|
||||
_NSCAssertArgs((condition), (desc), (arg1), (arg2), (arg3), (arg4))
|
||||
|
||||
#define NSCAssert3(condition, desc, arg1, arg2, arg3) \
|
||||
_NSCAssertArgs((condition), (desc), (arg1), (arg2), (arg3))
|
||||
|
||||
#define NSCAssert2(condition, desc, arg1, arg2) \
|
||||
_NSCAssertArgs((condition), (desc), (arg1), (arg2))
|
||||
|
||||
#define NSCAssert1(condition, desc, arg1) \
|
||||
_NSCAssertArgs((condition), (desc), (arg1))
|
||||
|
||||
#define NSCAssert(condition, desc) \
|
||||
_NSCAssertArgs((condition), (desc))
|
||||
|
||||
#define NSCParameterAssert(condition) \
|
||||
_NSCAssertArgs((condition), @"Invalid parameter not satisfying: %s", #condition)
|
||||
|
||||
#endif /* __NSException_h_OBJECTS_INCLUDE */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue