• BlackBerry Dynamics
  • Runtime library for iOS applications
  • 8.0.0.81
GDPortability.h
Go to the documentation of this file.
1 /*
2  * (c) 2017 BlackBerry Limited. All rights reserved.
3  *
4  */
5 
6 #pragma once
7 
8 #if defined(__APPLE__)
9 
26 #include <Availability.h>
27 
28 #if defined(__OBJC__) && defined(__cplusplus)
29 
30 namespace GD {
31 
32  /* NSObject type cast function template.
33  * This template validates an instance of an NSObject subclass can be type
34  * cast to another NSObject subclass prior to performing the cast.
35  * Useage: NSCheckedCast<CastT>(arg) to cast 'arg' to type 'CastT'
36  */
37  template <typename CastT, typename ArgT>
38  static inline CastT* NSCheckedCast(ArgT arg) {
39  if (!arg || [arg isKindOfClass:[CastT class]]) {
40  return (CastT*)arg;
41  } else {
42  @throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:@"%@ is not of type %@", arg, NSStringFromClass([CastT class])] userInfo:nil];
43  }
44  }
45 
46  template <typename CastT, typename ArgT>
47  static inline CastT* CFCheckedCast(ArgT arg) {
48  if (!(__bridge CastT)arg || [(__bridge CastT)arg isKindOfClass:[CastT class]]) {
49  return (__bridge CastT*)arg;
50  } else {
51  @throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:@"%@ is not of type %@", (__bridge CastT*)arg, NSStringFromClass([CastT class])] userInfo:nil];
52  }
53  }
54 }
55 
56 
57 #endif // __OBJC__
58 
59 #if defined(__MAC_10_11) || defined(__IPHONE_9_0)
60 # define GD_NSKINDOF __kindof
61 #else
62 # define GD_NSKINDOF
63 #endif
64 
65 #if defined(__has_feature)
66 
67 
68 # if __has_feature(nullability)
69  /* Nullability */
70 # define GD_NSNULLABLE_PROP nullable,
71 # define GD_NSNULLABLE nullable
72 # define GD_NSNON_NULL_PROP nonnull,
73 # define GD_NSNON_NULL nonnull
74 # define GD_NSNULL_UNSPECIFIED null_unspecified
75 
76 # if defined(__MAC_10_11) || defined(__IPHONE_9_0)
77 # define GD_NSNULLABLE_POINTER _Nullable
78 # define GD_NSNON_NULL_POINTER _Nonnull
79 # define GD_NSNULL_UNSPECIFIED_POINTER _Null_unspecified
80 # else
81 # define GD_NSNULLABLE_POINTER __nullable
82 # define GD_NSNON_NULL_POINTER __nonnull
83 # define GD_NSNULL_UNSPECIFIED_POINTER __null_unspecified
84 # endif
85 
86 # define GD_NSNON_NULL_CAST(ObjectType, Expression) ((ObjectType __nonnull)(ObjectType)Expression)
87 
88 # define GD_NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
89 # define GD_NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
90 # else
91 # define GD_NSNULLABLE_PROP
92 # define GD_NSNULLABLE
93 # define GD_NSNON_NULL_PROP
94 # define GD_NSNON_NULL
95 # define GD_NSNULL_UNSPECIFIED
96 
97 # define GD_NSNULLABLE_POINTER
98 # define GD_NSNON_NULL_POINTER
99 # define GD_NSNULL_UNSPECIFIED_POINTER
100 
101 # define GD_NSNON_NULL_CAST(ObjectType, Expression) ((ObjectType)Expression)
102 
103 # define GD_NS_ASSUME_NONNULL_BEGIN
104 # define GD_NS_ASSUME_NONNULL_END
105 # endif
106 
107  /* Generics */
108 # if __has_feature(objc_generics)
109 # define GD_NSDictionary(KeyType, ObjectType) NSDictionary<KeyType, ObjectType>
110 # define GD_NSMutableDictionary(KeyType, ObjectType) NSMutableDictionary<KeyType, ObjectType>
111 
112 # define GD_NSArray(ObjectType) NSArray<ObjectType>
113 # define GD_NSMutableArray(ObjectType) NSMutableArray<ObjectType>
114 
115 # define GD_NSSet(ObjectType) NSSet<ObjectType>
116 # define GD_NSMutableSet(ObjectType) NSMutableSet<ObjectType>
117 
118 # define GD_NSDirectoryEnumerator(ObjectType) NSDirectoryEnumerator<ObjectType>
119 # else
120 # define GD_NSDictionary(KeyType, ObjectType) NSDictionary
121 # define GD_NSMutableDictionary(KeyType, ObjectType) NSMutableDictionary
122 
123 # define GD_NSArray(ObjectType) NSArray
124 # define GD_NSMutableArray(ObjectType) NSMutableArray
125 
126 # define GD_NSSet(ObjectType) NSSet
127 # define GD_NSMutableSet(ObjectType) NSMutableSet
128 
129 # define GD_NSDirectoryEnumerator(ObjectType) NSDirectoryEnumerator
130 # endif
131 
132  /* Availability */
133 # if __has_feature(availability) && defined(API_AVAILABLE)
134 # define GD_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__)
135 # define GD_API_UNAVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__)
136 # else
137 # define GD_API_AVAILABLE(...)
138 # define GD_API_UNAVAILABLE(...)
139 # endif
140 #endif
141 
142 #endif
GD
Definition: GDKerberosAuthHandler.h:16