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

//
// PEPAutoPointer.m
// pEpObjCAdapter
//
// Created by Dirk Zimmermann on 11.04.18.
// Copyright © 2018 p≡p. All rights reserved.
//
#import "PEPAutoPointer.h"
@interface PEPAutoPointer ()
@property (nonatomic) void *thePointer;
@end
@implementation PEPAutoPointer
- (instancetype)initWithPointer:(void *)pointer freeFn:(void (*)(void *))freeFn
{
self = [super init];
if (self) {
_thePointer = pointer;
_freeFn = freeFn;
}
return self;
}
- (instancetype)init
{
return [self initWithPointer:nil freeFn:free];
}
- (void **)voidPointerPointer
{
return &_thePointer;
}
- (char **)charPointerPointer
{
return (char **) self.voidPointerPointer;
}
- (void *)voidPointer
{
return self.thePointer;
}
- (char *)charPointer
{
return (char *) self.voidPointer;
}
- (void)dealloc
{
if (_thePointer) {
self.freeFn(_thePointer);
}
}
@end