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