Merge pull request #24454 from komakai:refactorObjcRange

Refactor ObjectiveC Range class #24454

### Pull Request Readiness Checklist

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch

Fix for build issue in #24405
pull/24405/head^2
Giles Payne 1 year ago committed by GitHub
parent 77a0ffc71d
commit 617d7ff575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      modules/core/misc/objc/common/Range.h
  2. 30
      modules/core/misc/objc/common/Range.mm
  3. 4
      modules/core/misc/objc/gen_dict.json

@ -25,6 +25,9 @@ CV_EXPORTS @interface Range : NSObject
@property int start;
@property int end;
#ifdef __cplusplus
@property(readonly) cv::Range& nativeRef;
#endif
#pragma mark - Constructors
@ -32,6 +35,10 @@ CV_EXPORTS @interface Range : NSObject
- (instancetype)initWithStart:(int)start end:(int)end;
- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
#ifdef __cplusplus
+ (instancetype)fromNative:(cv::Range&)range;
#endif
#pragma mark - Methods
/**

@ -1,12 +1,34 @@
//
// Range.m
// Range.mm
//
// Created by Giles Payne on 2019/10/08.
//
#import "Range.h"
@implementation Range
@implementation Range {
cv::Range native;
}
- (int)start {
return native.start;
}
- (void)setStart:(int)val {
native.start = val;
}
- (int)end {
return native.end;
}
- (void)setEnd:(int)val {
native.end = val;
}
- (cv::Range&)nativeRef {
return native;
}
- (instancetype)init {
return [self initWithStart:0 end: 0];
@ -29,6 +51,10 @@
return self;
}
+ (instancetype)fromNative:(cv::Range&)range {
return [[Range alloc] initWithStart:range.start end:range.end];
}
- (void)set:(NSArray<NSNumber*>*)vals {
self.start = (vals != nil && vals.count > 0) ? vals[0].intValue : 0;
self.end = (vals != nil && vals.count > 1 ) ? vals[1].intValue : 0;

@ -167,7 +167,9 @@
"from_cpp": "[Point3i fromNative:%(n)s]"
},
"Range": {
"objc_type": "Range*"
"objc_type": "Range*",
"to_cpp": "%(n)s.nativeRef",
"from_cpp": "[Range fromNative:%(n)s]"
},
"Rect": {
"objc_type": "Rect2i*",

Loading…
Cancel
Save