Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Import

  • Loading branch information...
commit e5faf79c2dbefe1372e1b094dc0ff1447e1eeedd 0 parents
Sergei authored September 30, 2012
4  .gitignore
... ...
@@ -0,0 +1,4 @@
  1
+.DS_Store
  2
+*.orig
  3
+build/
  4
+xcuserdata/
80  NSAssert+BackingActions.h
... ...
@@ -0,0 +1,80 @@
  1
+/*
  2
+ * NSAssert+BackingActions.h
  3
+ * NSAssert 
  4
+ *
  5
+ * This header provides NSAssert based macros which provide some backing actions
  6
+ * to be performed when NS_BLOCK_ASSERTIONS is defined.
  7
+ *
  8
+ * Possible actions:
  9
+ *
  10
+ *      return
  11
+ *      return nil
  12
+ *      break
  13
+ *      continue
  14
+ *
  15
+ * Unless the NS_ASSERT_SUPRESS_BACKING_ACTION_LOGGING is defined, all assertions
  16
+ * that failed in Release mode are logged.
  17
+ *
  18
+ * (c) Sergei Cherepanov, 2012
  19
+ */
  20
+#ifndef _NSAssert_BackingActions_H_
  21
+#define _NSAssert_BackingActions_H_
  22
+#import <Foundation/NSException.h>
  23
+
  24
+#if !defined(NS_BLOCK_ASSERTIONS)
  25
+    #define NSAssertOrReturn    NSAssert
  26
+    #define NSAssertOrReturnNil NSAssert
  27
+    #define NSAssertOrReturnNO  NSAssert
  28
+    #define NSAssertOrBreak     NSAssert
  29
+    #define NSAssertOrContinue  NSAssert
  30
+    
  31
+    #define NSParameterAssertOrReturn    NSParameterAssert
  32
+    #define NSParameterAssertOrReturnNil NSParameterAssert
  33
+    #define NSParameterAssertOrReturnNO  NSParameterAssert
  34
+    #define NSParameterAssertOrBreak     NSParameterAssert
  35
+    #define NSParameterAssertOrContinue  NSParameterAssert
  36
+#else // !defined(NS_BLOCK_ASSERTIONS)
  37
+
  38
+    #if !defined(NSReleaseAssertionLog)
  39
+        #if !defined(NS_ASSERT_SUPRESS_BACKING_ACTION_LOGGING)
  40
+            #define NSReleaseAssertionLog(desc, ...)    NSLog(desc, __VA_ARGS__)
  41
+        #else
  42
+            #define NSReleaseAssertionLog(desc, ...)
  43
+        #endif // !defined(NS_ASSERT_SUPRESS_BACKING_ACTION_LOGGING)
  44
+    #endif // !defined(NSReleaseAssertionLog)
  45
+
  46
+    #define NSAssertWithReleaseAction(releaseAction, condition, desc, ...)                  \
  47
+        {                                                                                   \
  48
+            if (!(condition)) {                                                             \
  49
+                NSReleaseAssertionLog(@"*** Assertion failure in %@, %s:%d. Reason: %@",    \
  50
+                    NSStringFromSelector(_cmd), __FILE__, __LINE__,                         \
  51
+                    [NSString stringWithFormat:desc, __VA_ARGS__]);                         \
  52
+                releaseAction;                                                              \
  53
+            }                                                                               \
  54
+        }
  55
+    
  56
+    #define NSAssertOrReturn(condition, desc, ...) \
  57
+                    NSAssertWithReleaseAction(return, condition, desc, __VA_ARGS__)
  58
+    #define NSAssertOrReturnNil(condition, desc, ...) \
  59
+                    NSAssertWithReleaseAction(return nil, condition, desc, __VA_ARGS__)
  60
+    #define NSAssertOrReturnNO(condition, desc, ...) \
  61
+                    NSAssertWithReleaseAction(return NO, condition, desc, __VA_ARGS__)
  62
+    #define NSAssertOrBreak(condition, desc, ...) \
  63
+                    NSAssertWithReleaseAction(break, condition, desc, __VA_ARGS__)
  64
+    #define NSAssertOrContinue(condition, desc, ...) \
  65
+                    NSAssertWithReleaseAction(continue, condition, desc, __VA_ARGS__)
  66
+    
  67
+    #define NSParameterAssertOrReturn(condition) \
  68
+                    NSAssertWithReleaseAction(return, condition, @"Invalid parameter not satisfying: %s", #condition)
  69
+    #define NSParameterAssertOrReturnNil(condition) \
  70
+                    NSAssertWithReleaseAction(return nil, condition, @"Invalid parameter not satisfying: %s", #condition)
  71
+    #define NSParameterAssertOrReturnNO(condition) \
  72
+                    NSAssertWithReleaseAction(return NO, condition, @"Invalid parameter not satisfying: %s", #condition)
  73
+    #define NSParameterAssertOrBreak(condition) \
  74
+                    NSAssertWithReleaseAction(break, condition, @"Invalid parameter not satisfying: %s", #condition)
  75
+    #define NSParameterAssertOrContinue(condition) \
  76
+                    NSAssertWithReleaseAction(continue, condition, @"Invalid parameter not satisfying: %s", #condition)
  77
+
  78
+#endif // !defined(NS_BLOCK_ASSERTIONS)
  79
+
  80
+#endif // _NSAssert_BackingActions_H_

0 notes on commit e5faf79

Please sign in to comment.
Something went wrong with that request. Please try again.