IntVector.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // IntVector.h
  3. //
  4. // Created by Giles Payne on 2020/01/04.
  5. //
  6. #pragma once
  7. #import <Foundation/Foundation.h>
  8. #ifdef __cplusplus
  9. #import <vector>
  10. #endif
  11. #import "CVObjcUtil.h"
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. * Utility class to wrap a `std::vector<int>`
  15. */
  16. CV_EXPORTS @interface IntVector : NSObject
  17. #pragma mark - Constructors
  18. /**
  19. * Create IntVector and initialize with the contents of an NSData object
  20. * @param data NSData containing raw int array
  21. */
  22. -(instancetype)initWithData:(NSData*)data;
  23. /**
  24. * Create IntVector and initialize with the contents of another IntVector object
  25. * @param src IntVector containing data to copy
  26. */
  27. -(instancetype)initWithVector:(IntVector*)src;
  28. #ifdef __OBJC__
  29. /**
  30. * Create IntVector from raw C array
  31. * @param array The raw C array
  32. * @elements elements The number of elements in the array
  33. */
  34. -(instancetype)initWithNativeArray:(int*)array elements:(NSInteger)elements;
  35. #endif
  36. #ifdef __cplusplus
  37. /**
  38. * Create IntVector from std::vector<int>
  39. * @param src The std::vector<int> object to wrap
  40. */
  41. -(instancetype)initWithStdVector:(std::vector<int>&)src;
  42. +(instancetype)fromNative:(std::vector<int>&)src;
  43. #endif
  44. #pragma mark - Properties
  45. /**
  46. * Length of the vector
  47. */
  48. @property(readonly) NSInteger length;
  49. #ifdef __OBJC__
  50. /**
  51. * Raw C array
  52. */
  53. @property(readonly) int* nativeArray;
  54. #endif
  55. #ifdef __cplusplus
  56. /**
  57. * The wrapped std::vector<int> object
  58. */
  59. @property(readonly) std::vector<int>& nativeRef;
  60. #endif
  61. /**
  62. * NSData object containing the raw int data
  63. */
  64. @property(readonly) NSData* data;
  65. #pragma mark - Accessor method
  66. /**
  67. * Return array element
  68. * @param index Index of the array element to return
  69. */
  70. -(int)get:(NSInteger)index;
  71. @end
  72. NS_ASSUME_NONNULL_END