You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
914 B

  1. //
  2. // PEPAutoPointer.m
  3. // pEpObjCAdapter
  4. //
  5. // Created by Dirk Zimmermann on 11.04.18.
  6. // Copyright © 2018 pp. All rights reserved.
  7. //
  8. #import "PEPAutoPointer.h"
  9. @interface PEPAutoPointer ()
  10. @property (nonatomic) void *thePointer;
  11. @end
  12. @implementation PEPAutoPointer
  13. - (instancetype)initWithPointer:(void *)pointer freeFn:(void (*)(void *))freeFn
  14. {
  15. self = [super init];
  16. if (self) {
  17. _thePointer = pointer;
  18. _freeFn = freeFn;
  19. }
  20. return self;
  21. }
  22. - (instancetype)init
  23. {
  24. return [self initWithPointer:nil freeFn:free];
  25. }
  26. - (void **)voidPointerPointer
  27. {
  28. return &_thePointer;
  29. }
  30. - (char **)charPointerPointer
  31. {
  32. return (char **) self.voidPointerPointer;
  33. }
  34. - (void *)voidPointer
  35. {
  36. return self.thePointer;
  37. }
  38. - (char *)charPointer
  39. {
  40. return (char *) self.voidPointer;
  41. }
  42. - (void)dealloc
  43. {
  44. if (_thePointer) {
  45. self.freeFn(_thePointer);
  46. }
  47. }
  48. @end