BVB Source Codes

AsyncDisplayKit Show ASAssert.h Source code

Return Download AsyncDisplayKit: download ASAssert.h Source code - Download AsyncDisplayKit Source code - Type:.h
  1. //
  2. //  ASAssert.h
  3. //  AsyncDisplayKit
  4. //
  5. //  Copyright (c) 2014-present, Facebook, Inc.  All rights reserved.
  6. //  This source code is licensed under the BSD-style license found in the
  7. //  LICENSE file in the root directory of this source tree. An additional grant
  8. //  of patent rights can be found in the PATENTS file in the same directory.
  9. //
  10.  
  11. #pragma once
  12.  
  13. #import <Foundation/NSException.h>
  14. #import <pthread.h>
  15.  
  16. #define ASDISPLAYNODE_ASSERTIONS_ENABLED (!defined(NS_BLOCK_ASSERTIONS))
  17.  
  18. /**
  19.  * Note: In some cases it would be sufficient to do e.g.:
  20.  *  ASDisplayNodeAssert(...) NSAssert(__VA_ARGS__)
  21.  * but we prefer not to, because we want to match the autocomplete behavior of NSAssert.
  22.  * The construction listed above does not show the user what arguments are required and what are optional.
  23.  */
  24.  
  25. #define ASDisplayNodeAssert(condition, desc, ...) NSAssert(condition, desc, ##__VA_ARGS__)
  26. #define ASDisplayNodeCAssert(condition, desc, ...) NSCAssert(condition, desc, ##__VA_ARGS__)
  27.  
  28. #define ASDisplayNodeAssertNil(condition, desc, ...) ASDisplayNodeAssert((condition) == nil, desc, ##__VA_ARGS__)
  29. #define ASDisplayNodeCAssertNil(condition, desc, ...) ASDisplayNodeCAssert((condition) == nil, desc, ##__VA_ARGS__)
  30.  
  31. #define ASDisplayNodeAssertNotNil(condition, desc, ...) ASDisplayNodeAssert((condition) != nil, desc, ##__VA_ARGS__)
  32. #define ASDisplayNodeCAssertNotNil(condition, desc, ...) ASDisplayNodeCAssert((condition) != nil, desc, ##__VA_ARGS__)
  33.  
  34. #define ASDisplayNodeAssertImplementedBySubclass() ASDisplayNodeAssert(NO, @"This method must be implemented by subclass %@", [self class]);
  35. #define ASDisplayNodeAssertNotInstantiable() ASDisplayNodeAssert(NO, nil, @"This class is not instantiable.");
  36. #define ASDisplayNodeAssertNotSupported() ASDisplayNodeAssert(NO, nil, @"This method is not supported by class %@", [self class]);
  37.  
  38. #define ASDisplayNodeAssertMainThread() ASDisplayNodeAssert(0 != pthread_main_np(), @"This method must be called on the main thread")
  39. #define ASDisplayNodeCAssertMainThread() ASDisplayNodeCAssert(0 != pthread_main_np(), @"This function must be called on the main thread")
  40.  
  41. #define ASDisplayNodeAssertNotMainThread() ASDisplayNodeAssert(0 == pthread_main_np(), @"This method must be called off the main thread")
  42. #define ASDisplayNodeCAssertNotMainThread() ASDisplayNodeCAssert(0 == pthread_main_np(), @"This function must be called off the main thread")
  43.  
  44. #define ASDisplayNodeAssertFlag(X, desc, ...) ASDisplayNodeAssert((1 == __builtin_popcount(X)), desc, ##__VA_ARGS__)
  45. #define ASDisplayNodeCAssertFlag(X, desc, ...) ASDisplayNodeCAssert((1 == __builtin_popcount(X)), desc, ##__VA_ARGS__)
  46.  
  47. #define ASDisplayNodeAssertTrue(condition) ASDisplayNodeAssert((condition), @"Expected %s to be true.", #condition)
  48. #define ASDisplayNodeCAssertTrue(condition) ASDisplayNodeCAssert((condition), @"Expected %s to be true.", #condition)
  49.  
  50. #define ASDisplayNodeAssertFalse(condition) ASDisplayNodeAssert(!(condition), @"Expected %s to be false.", #condition)
  51. #define ASDisplayNodeCAssertFalse(condition) ASDisplayNodeCAssert(!(condition), @"Expected %s to be false.", #condition)
  52.  
  53. #define ASDisplayNodeFailAssert(desc, ...) ASDisplayNodeAssert(NO, desc, ##__VA_ARGS__)
  54. #define ASDisplayNodeCFailAssert(desc, ...) ASDisplayNodeCAssert(NO, desc, ##__VA_ARGS__)
  55.  
  56. #define ASDisplayNodeConditionalAssert(shouldTestCondition, condition, desc, ...) ASDisplayNodeAssert((!(shouldTestCondition) || (condition)), desc, ##__VA_ARGS__)
  57. #define ASDisplayNodeConditionalCAssert(shouldTestCondition, condition, desc, ...) ASDisplayNodeCAssert((!(shouldTestCondition) || (condition)), desc, ##__VA_ARGS__)
  58.  
  59. #define ASDisplayNodeCAssertPositiveReal(description, num) ASDisplayNodeCAssert(num >= 0 && num <= CGFLOAT_MAX, @"%@ must be a real positive integer.", description)
  60. #define ASDisplayNodeCAssertInfOrPositiveReal(description, num) ASDisplayNodeCAssert(isinf(num) || (num >= 0 && num <= CGFLOAT_MAX), @"%@ must be infinite or a real positive integer.", description)
  61.  
  62. #define ASDisplayNodeErrorDomain @"ASDisplayNodeErrorDomain"
  63. #define ASDisplayNodeNonFatalErrorCode 1
  64.  
  65. #define ASDisplayNodeAssertNonFatal(condition, desc, ...)                                                                         \
  66.   ASDisplayNodeAssert(condition, desc, ##__VA_ARGS__);                                                                            \
  67.   if (condition ==  NO) {                                                                                                         \
  68.     ASDisplayNodeNonFatalErrorBlock block = [ASDisplayNode nonFatalErrorBlock];                                                   \
  69.     if (block != nil) {                                                                                                           \
  70.       NSDictionary *userInfo = nil;                                                                                               \
  71.       if (desc.length > 0) {                                                                                                      \
  72.         userInfo = @{ NSLocalizedDescriptionKey : desc };                                                                         \
  73.       }                                                                                                                           \
  74.       NSError *error = [NSError errorWithDomain:ASDisplayNodeErrorDomain code:ASDisplayNodeNonFatalErrorCode userInfo:userInfo];  \
  75.       block(error);                                                                                                               \
  76.     }                                                                                                                             \
  77.   }
  78.  
downloadASAssert.h Source code - Download AsyncDisplayKit Source code
Related Source Codes/Software:
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
react-boilerplate - 2017-06-07
webtorrent - Streaming torrent client for the web ... 2017-06-06
ionicons - The premium icon font for Ionic ... 2017-06-07
storybook - 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top