• BlackBerry Dynamics
  • Runtime library for iOS applications
  • 10.2.0.83
GDPortability.h
Go to the documentation of this file.
1 /*
2  * (c) 2021 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 #endif // __OBJC__
58 #endif
GD
Definition: GDKerberosAuthHandler.h:16