FLEXTypeEncodingParser.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /// @return whether the given type encoding can be passed to
  14. /// \c NSMethodSignature without it throwing an exception.
  15. + (BOOL)methodTypeEncodingSupported:(NSString *)typeEncoding;
  16. /// @return The type encoding of an individual argument in a method's type encoding string.
  17. /// Pass 0 to get the type of the return value. 1 and 2 are `self` and `_cmd` respectively.
  18. + (NSString *)type:(NSString *)typeEncoding forMethodArgumentAtIndex:(NSUInteger)idx;
  19. /// @return The size in bytes of the typeof an individual argument in a method's type encoding string.
  20. /// Pass 0 to get the size of the return value. 1 and 2 are `self` and `_cmd` respectively.
  21. + (ssize_t)size:(NSString *)typeEncoding forMethodArgumentAtIndex:(NSUInteger)idx;
  22. /// @param unaligned whether to compute the aligned or unaligned size.
  23. /// @return The size in bytes, or \c -1 if the type encoding is unsupported.
  24. /// Do not pass in the result of \c method_getTypeEncoding
  25. + (ssize_t)sizeForTypeEncoding:(NSString *)type alignment:(nullable ssize_t *)alignOut unaligned:(BOOL)unaligned;
  26. /// Defaults to \C unaligned:NO
  27. + (ssize_t)sizeForTypeEncoding:(NSString *)type alignment:(nullable ssize_t *)alignOut;
  28. @end
  29. NS_ASSUME_NONNULL_END