Skip to content

fix equatable #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/src/core/array.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'dart:ffi' as ffi;

import 'package:equatable/equatable.dart';
import 'package:ffi/ffi.dart';

import 'base.dart';

// Dart does not support multiple upper bounds for T now, if they implement it, this can be simplified.
// https://github.com/dart-lang/language/issues/2709
abstract class NativeArray<T extends ffi.NativeType, P extends num>
with EquatableMixin
with ComparableMixin
implements ffi.Finalizable, INativeArray<P> {
NativeArray([this.length = 0]);

Expand Down
16 changes: 9 additions & 7 deletions lib/src/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,25 @@ final CFFI = cvg.CvNative(loadNativeLibrary());
// base structures
abstract class CvObject<T extends ffi.NativeType> implements ffi.Finalizable {}

abstract class ICvStruct<T extends ffi.Struct> extends CvObject<T> {
ICvStruct.fromPointer(this.ptr);

ffi.Pointer<T> ptr;
T get ref;

mixin ComparableMixin {
List<Object?> get props;

@override
// ignore: hash_and_equals
bool operator ==(Object other) {
if (other is! ICvStruct) return false;
if (other is! ComparableMixin) return false;
if (props.length != other.props.length) return false;
return props.indexed.every((e) => other.props[e.$1] == e.$2);
}
}

abstract class ICvStruct<T extends ffi.Struct> extends CvObject<T> with ComparableMixin {
ICvStruct.fromPointer(this.ptr);

ffi.Pointer<T> ptr;
T get ref;
}

abstract class CvStruct<T extends ffi.Struct> extends ICvStruct<T> {
CvStruct.fromPointer(super.ptr) : super.fromPointer();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/error_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
LICENSE: Apache-2.0
*/

import 'package:equatable/equatable.dart';
import 'base.dart';

class ErrorCode with EquatableMixin {
class ErrorCode with ComparableMixin {
/// @brief everithing is ok CV_StsOk
static final ErrorCode StsOk = ErrorCode(0);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/mat_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

library cv;

import 'package:equatable/equatable.dart';
import 'base.dart';
import 'exception.dart';

class MatType extends Equatable {
class MatType with ComparableMixin {
final int value;

const MatType(this.value);
Expand Down
3 changes: 1 addition & 2 deletions lib/src/core/vec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import 'dart:convert';
import 'dart:ffi' as ffi;
import 'dart:typed_data';

import 'package:equatable/equatable.dart';
import 'package:ffi/ffi.dart';

import '../opencv.g.dart' as cvg;
import 'base.dart';

abstract class Vec<T> with IterableMixin<T>, EquatableMixin implements ffi.Finalizable {
abstract class Vec<T> with IterableMixin<T>, ComparableMixin implements ffi.Finalizable {
@override
int get length;

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.8
ffi: ^2.1.0
ffi: ^2.1.2
path: ^1.9.0
args: ^2.5.0
archive: ^3.5.1
archive: ^3.6.1
stack_trace: ^1.11.1

dev_dependencies:
Expand Down
Loading