2017-08-14 12:16:45 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-08-14 12:16:45 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-01 14:59:06 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2017-08-14 12:16:45 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type erased wrapper over any cxx value that can be passed as an argument
|
|
|
|
* to native method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@interface RCTManagedPointer: NSObject
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) void *voidPointer;
|
|
|
|
|
|
|
|
- (instancetype)initWithPointer:(std::shared_ptr<void>)pointer;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-09-01 14:59:06 +00:00
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
template <typename T, typename P>
|
|
|
|
RCTManagedPointer *managedPointer(P initializer)
|
|
|
|
{
|
|
|
|
auto ptr = std::shared_ptr<void>(new T(initializer));
|
|
|
|
return [[RCTManagedPointer alloc] initWithPointer:std::move(ptr)];
|
2017-08-14 12:16:45 +00:00
|
|
|
}
|
2017-09-01 14:59:06 +00:00
|
|
|
|
|
|
|
} }
|
|
|
|
|
|
|
|
#endif
|