SDWebImageOptionsProcessor.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDWebImageCompat.h"
  10. #import "SDWebImageDefine.h"
  11. @class SDWebImageOptionsResult;
  12. typedef SDWebImageOptionsResult * _Nullable(^SDWebImageOptionsProcessorBlock)(NSURL * _Nullable url, SDWebImageOptions options, SDWebImageContext * _Nullable context);
  13. /**
  14. The options result contains both options and context.
  15. */
  16. @interface SDWebImageOptionsResult : NSObject
  17. /**
  18. WebCache options.
  19. */
  20. @property (nonatomic, assign, readonly) SDWebImageOptions options;
  21. /**
  22. Context options.
  23. */
  24. @property (nonatomic, copy, readonly, nullable) SDWebImageContext *context;
  25. /**
  26. Create a new options result.
  27. @param options options
  28. @param context context
  29. @return The options result contains both options and context.
  30. */
  31. - (nonnull instancetype)initWithOptions:(SDWebImageOptions)options context:(nullable SDWebImageContext *)context;
  32. @end
  33. /**
  34. This is the protocol for options processor.
  35. Options processor can be used, to control the final result for individual image request's `SDWebImageOptions` and `SDWebImageContext`
  36. Implements the protocol to have a global control for each indivadual image request's option.
  37. */
  38. @protocol SDWebImageOptionsProcessor <NSObject>
  39. /**
  40. Return the processed options result for specify image URL, with its options and context
  41. @param url The URL to the image
  42. @param options A mask to specify options to use for this request
  43. @param context A context contains different options to perform specify changes or processes, see `SDWebImageContextOption`. This hold the extra objects which `options` enum can not hold.
  44. @return The processed result, contains both options and context
  45. */
  46. - (nullable SDWebImageOptionsResult *)processedResultForURL:(nullable NSURL *)url
  47. options:(SDWebImageOptions)options
  48. context:(nullable SDWebImageContext *)context;
  49. @end
  50. /**
  51. A options processor class with block.
  52. */
  53. @interface SDWebImageOptionsProcessor : NSObject<SDWebImageOptionsProcessor>
  54. - (nonnull instancetype)initWithBlock:(nonnull SDWebImageOptionsProcessorBlock)block;
  55. + (nonnull instancetype)optionsProcessorWithBlock:(nonnull SDWebImageOptionsProcessorBlock)block;
  56. @end