Skip to content

Commit

Permalink
Merge pull request opencv#24454 from komakai:refactorObjcRange
Browse files Browse the repository at this point in the history
Refactor ObjectiveC Range class opencv#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 opencv#24405
  • Loading branch information
komakai authored Oct 27, 2023
1 parent 77a0ffc commit 617d7ff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
7 changes: 7 additions & 0 deletions modules/core/misc/objc/common/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ CV_EXPORTS @interface Range : NSObject

@property int start;
@property int end;
#ifdef __cplusplus
@property(readonly) cv::Range& nativeRef;
#endif

#pragma mark - Constructors

- (instancetype)init;
- (instancetype)initWithStart:(int)start end:(int)end;
- (instancetype)initWithVals:(NSArray<NSNumber*>*)vals;

#ifdef __cplusplus
+ (instancetype)fromNative:(cv::Range&)range;
#endif

#pragma mark - Methods

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -29,6 +51,10 @@ - (instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
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;
Expand Down
4 changes: 3 additions & 1 deletion modules/core/misc/objc/gen_dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand Down

0 comments on commit 617d7ff

Please sign in to comment.