blackberry.com
BlackBerry Dynamics
Runtime library for macOS applications
from the application developer portal

GDPortability.h

Go to the documentation of this file.
00001 /*
00002  * (c) 2017 BlackBerry Limited. All rights reserved.
00003  *
00004  */
00005 
00006 #pragma once
00007 
00008 #if defined(__APPLE__)
00009 
00020 #include <Availability.h>
00021 
00022 #if defined(__OBJC__) && defined(__cplusplus)
00023 
00024 namespace GD {
00025     
00026     /* NSObject type cast function template.
00027      * This template validates an instance of an NSObject subclass can be type
00028      * cast to another NSObject subclass prior to performing the cast.
00029      * Useage: NSCheckedCast<CastT>(arg) to cast 'arg' to type 'CastT'
00030      */
00031     template <typename CastT, typename ArgT>
00032     static inline CastT* NSCheckedCast(ArgT arg) {
00033         if (!arg || [arg isKindOfClass:[CastT class]]) {
00034             return (CastT*)arg;
00035         } else {
00036             @throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:@"%@ is not of type %@", arg, NSStringFromClass([CastT class])] userInfo:nil];
00037         }
00038     }
00039     
00040     template <typename CastT, typename ArgT>
00041     static inline CastT* CFCheckedCast(ArgT arg) {
00042         if (!(__bridge CastT)arg || [(__bridge CastT)arg isKindOfClass:[CastT class]]) {
00043             return (__bridge CastT*)arg;
00044         } else {
00045             @throw [NSException exceptionWithName:NSGenericException reason:[NSString stringWithFormat:@"%@ is not of type %@", (__bridge CastT*)arg, NSStringFromClass([CastT class])] userInfo:nil];
00046         }
00047     }
00048 }
00049 
00050 
00051 #endif // __OBJC__
00052 
00053 #if defined(__MAC_10_11) || defined(__IPHONE_9_0)
00054 #   define GD_NSKINDOF __kindof
00055 #else
00056 #   define GD_NSKINDOF
00057 #endif
00058 
00059 #if defined(__has_feature)
00060 
00061 #   if __has_feature(nullability)
00062 
00063 #       define GD_NSNULLABLE_PROP      nullable,
00064 #       define GD_NSNULLABLE           nullable
00065 #       define GD_NSNON_NULL_PROP      nonnull,
00066 #       define GD_NSNON_NULL           nonnull
00067 #       define GD_NSNULL_UNSPECIFIED   null_unspecified
00068 
00069 #       if defined(__MAC_10_11) || defined(__IPHONE_9_0)
00070 #           define GD_NSNULLABLE_POINTER           _Nullable
00071 #           define GD_NSNON_NULL_POINTER           _Nonnull
00072 #           define GD_NSNULL_UNSPECIFIED_POINTER   _Null_unspecified
00073 #       else
00074 #           define GD_NSNULLABLE_POINTER           __nullable
00075 #           define GD_NSNON_NULL_POINTER           __nonnull
00076 #           define GD_NSNULL_UNSPECIFIED_POINTER   __null_unspecified
00077 #       endif
00078 
00079 #       define GD_NSNON_NULL_CAST(ObjectType, Expression) ((ObjectType __nonnull)(ObjectType)Expression)
00080 
00081 #       define GD_NS_ASSUME_NONNULL_BEGIN  NS_ASSUME_NONNULL_BEGIN
00082 #       define GD_NS_ASSUME_NONNULL_END    NS_ASSUME_NONNULL_END
00083 #   else
00084 #       define GD_NSNULLABLE_PROP
00085 #       define GD_NSNULLABLE
00086 #       define GD_NSNON_NULL_PROP
00087 #       define GD_NSNON_NULL
00088 #       define GD_NSNULL_UNSPECIFIED
00089 
00090 #       define GD_NSNULLABLE_POINTER
00091 #       define GD_NSNON_NULL_POINTER
00092 #       define GD_NSNULL_UNSPECIFIED_POINTER
00093 
00094 #       define GD_NSNON_NULL_CAST(ObjectType, Expression) ((ObjectType)Expression)
00095 
00096 #       define GD_NS_ASSUME_NONNULL_BEGIN
00097 #       define GD_NS_ASSUME_NONNULL_END
00098 #   endif
00099 
00101 #   if __has_feature(objc_generics)
00102 #       define GD_NSDictionary(KeyType, ObjectType)        NSDictionary<KeyType, ObjectType>
00103 #       define GD_NSMutableDictionary(KeyType, ObjectType) NSMutableDictionary<KeyType, ObjectType>
00104 
00105 #       define GD_NSArray(ObjectType)                  NSArray<ObjectType>
00106 #       define GD_NSMutableArray(ObjectType)           NSMutableArray<ObjectType>
00107 
00108 #       define GD_NSSet(ObjectType)                    NSSet<ObjectType>
00109 #       define GD_NSMutableSet(ObjectType)             NSMutableSet<ObjectType>
00110 
00111 #       define GD_NSDirectoryEnumerator(ObjectType)    NSDirectoryEnumerator<ObjectType>
00112 #   else
00113 #       define GD_NSDictionary(KeyType, ObjectType)        NSDictionary
00114 #       define GD_NSMutableDictionary(KeyType, ObjectType) NSMutableDictionary
00115 
00116 #       define GD_NSArray(ObjectType)                  NSArray
00117 #       define GD_NSMutableArray(ObjectType)           NSMutableArray
00118 
00119 #       define GD_NSSet(ObjectType)                    NSSet
00120 #       define GD_NSMutableSet(ObjectType)             NSMutableSet
00121 
00122 #       define GD_NSDirectoryEnumerator(ObjectType)    NSDirectoryEnumerator
00123 #   endif
00124 
00126 #   if __has_feature(availability) && defined(API_AVAILABLE)
00127 #       define GD_API_AVAILABLE(...)       API_AVAILABLE(__VA_ARGS__)
00128 #       define GD_API_UNAVAILABLE(...)     API_UNAVAILABLE(__VA_ARGS__)
00129 #   else
00130 #       define GD_API_AVAILABLE(...)
00131 #       define GD_API_UNAVAILABLE(...)
00132 #   endif
00133 #endif
00134 
00135 #endif