RCTManagedPointer.h 798 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #ifdef __cplusplus
  8. #include <memory>
  9. #import <Foundation/Foundation.h>
  10. /**
  11. * Type erased wrapper over any cxx value that can be passed as an argument
  12. * to native method.
  13. */
  14. @interface RCTManagedPointer : NSObject
  15. @property (nonatomic, readonly) void *voidPointer;
  16. - (instancetype)initWithPointer:(std::shared_ptr<void>)pointer;
  17. @end
  18. namespace facebook {
  19. namespace react {
  20. template <typename T, typename P>
  21. RCTManagedPointer *managedPointer(P initializer)
  22. {
  23. auto ptr = std::shared_ptr<void>(new T(initializer));
  24. return [[RCTManagedPointer alloc] initWithPointer:std::move(ptr)];
  25. }
  26. }
  27. }
  28. #endif