FLEXTypeEncodingParser.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // FLEXTypeEncodingParser.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/22/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. /// @return \c YES if the type is supported, \c NO otherwise
  11. BOOL FLEXGetSizeAndAlignment(const char *type, NSUInteger * _Nullable sizep, NSUInteger * _Nullable alignp);
  12. @interface FLEXTypeEncodingParser : NSObject
  13. /// \c cleanedEncoding is necessary because a type encoding may contain a pointer
  14. /// to an unsupported type. \c NSMethodSignature will pass each type to \c NSGetSizeAndAlignment
  15. /// which will throw an exception on unsupported struct pointers, and this exception is caught
  16. /// by \c NSMethodSignature, but it still bothers anyone debugging with \c objc_exception_throw
  17. ///
  18. /// @param cleanedEncoding the "safe" type encoding you can pass to \c NSMethodSignature
  19. /// @return whether the given type encoding can be passed to
  20. /// \c NSMethodSignature without it throwing an exception.
  21. + (BOOL)methodTypeEncodingSupported:(NSString *)typeEncoding cleaned:(NSString *_Nonnull*_Nullable)cleanedEncoding;
  22. /// @return The type encoding of an individual argument in a method's type encoding string.
  23. /// Pass 0 to get the type of the return value. 1 and 2 are `self` and `_cmd` respectively.
  24. + (NSString *)type:(NSString *)typeEncoding forMethodArgumentAtIndex:(NSUInteger)idx;
  25. /// @return The size in bytes of the typeof an individual argument in a method's type encoding string.
  26. /// Pass 0 to get the size of the return value. 1 and 2 are `self` and `_cmd` respectively.
  27. + (ssize_t)size:(NSString *)typeEncoding forMethodArgumentAtIndex:(NSUInteger)idx;
  28. /// @param unaligned whether to compute the aligned or unaligned size.
  29. /// @return The size in bytes, or \c -1 if the type encoding is unsupported.
  30. /// Do not pass in the result of \c method_getTypeEncoding
  31. + (ssize_t)sizeForTypeEncoding:(NSString *)type alignment:(nullable ssize_t *)alignOut unaligned:(BOOL)unaligned;
  32. /// Defaults to \C unaligned:NO
  33. + (ssize_t)sizeForTypeEncoding:(NSString *)type alignment:(nullable ssize_t *)alignOut;
  34. @end
  35. NS_ASSUME_NONNULL_END