Skip to content

Commit

Permalink
feat: the constructors of the struct classes are now const (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Jul 26, 2023
1 parent d8446e2 commit c0ec409
Show file tree
Hide file tree
Showing 57 changed files with 85 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:windows_foundation/windows_foundation.dart';

/// Represents the package version info.
final class PackageVersion implements WinRTStruct {
PackageVersion(this.major, this.minor, this.build, this.revision);
const PackageVersion(this.major, this.minor, this.build, this.revision);

final int major;
final int minor;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_data/lib/src/text/textsegment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// by AlternateWordForm, SelectableWordSegment, WordSegment, or
/// SemanticTextQuery.
final class TextSegment implements WinRTStruct {
TextSegment(this.startPosition, this.length);
const TextSegment(this.startPosition, this.length);

final int startPosition;
final int length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// Describes an overall presentation rate composed of a rational refresh
/// rate and a divider.
final class DisplayPresentationRate implements WinRTStruct {
DisplayPresentationRate(
const DisplayPresentationRate(
this.verticalSyncRate, this.verticalSyncsPerPresentation);

final Rational verticalSyncRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:windows_foundation/windows_foundation.dart';

/// The basic information to describe a geographic position.
final class BasicGeoposition implements WinRTStruct {
BasicGeoposition(this.latitude, this.longitude, this.altitude);
const BasicGeoposition(this.latitude, this.longitude, this.altitude);

final double latitude;
final double longitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'gpiopinedge.dart';
/// change, and whether the pin transitioned from low to high or from high
/// to low.
final class GpioChangeRecord implements WinRTStruct {
GpioChangeRecord(this.relativeTime, this.edge);
const GpioChangeRecord(this.relativeTime, this.edge);

final Duration relativeTime;
final GpioPinEdge edge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// Identifies the Human Interface Device (HID) usage details for the input
/// device.
final class PointerDeviceUsage implements WinRTStruct {
PointerDeviceUsage(
const PointerDeviceUsage(
this.usagePage,
this.usage,
this.minLogical,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:windows_foundation/windows_foundation.dart';

/// Defines the height and width of an object in a two-dimensional plane.
final class SizeUInt32 implements WinRTStruct {
SizeUInt32(this.width, this.height);
const SizeUInt32(this.width, this.height);

final int width;
final int height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../winrt_struct.dart';

/// Describes a 3*2 floating point matrix.
final class Matrix3x2 implements WinRTStruct {
Matrix3x2(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32);
const Matrix3x2(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32);

final double m11;
final double m12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../winrt_struct.dart';

/// Describes a 4*4 floating point matrix.
final class Matrix4x4 implements WinRTStruct {
Matrix4x4(
const Matrix4x4(
this.m11,
this.m12,
this.m13,
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/numerics/plane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'vector3.dart';

/// Describes a plane (a flat, two-dimensional surface).
final class Plane implements WinRTStruct {
Plane(this.normal, this.d);
const Plane(this.normal, this.d);

final Vector3 normal;
final double d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import '../winrt_struct.dart';
/// Describes a quaternion, which is an abstract representation of an
/// orientation in space that is based on complex numbers.
final class Quaternion implements WinRTStruct {
Quaternion(this.x, this.y, this.z, this.w);
const Quaternion(this.x, this.y, this.z, this.w);

final double x;
final double y;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/numerics/rational.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../winrt_struct.dart';

/// Describes a number that can be created by the division of 2 integers.
final class Rational implements WinRTStruct {
Rational(this.numerator, this.denominator);
const Rational(this.numerator, this.denominator);

final int numerator;
final int denominator;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/numerics/vector2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../winrt_struct.dart';

/// Describes a vector of two floating-point components.
final class Vector2 implements WinRTStruct {
Vector2(this.x, this.y);
const Vector2(this.x, this.y);

final double x;
final double y;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/numerics/vector3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../winrt_struct.dart';

/// Describes a vector of three floating-point components.
final class Vector3 implements WinRTStruct {
Vector3(this.x, this.y, this.z);
const Vector3(this.x, this.y, this.z);

final double x;
final double y;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/numerics/vector4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../winrt_struct.dart';

/// Describes a vector of four floating-point components.
final class Vector4 implements WinRTStruct {
Vector4(this.x, this.y, this.z, this.w);
const Vector4(this.x, this.y, this.z, this.w);

final double x;
final double y;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'winrt_struct.dart';
/// Represents an x- and y-coordinate pair in two-dimensional space. Can
/// also represent a logical point for certain property usages.
final class Point implements WinRTStruct {
Point(this.x, this.y);
const Point(this.x, this.y);

final double x;
final double y;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/rect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'winrt_struct.dart';

/// Describes the width, height, and point origin of a rectangle.
final class Rect implements WinRTStruct {
Rect(this.x, this.y, this.width, this.height);
const Rect(this.x, this.y, this.width, this.height);

final double x;
final double y;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/lib/src/size.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'winrt_struct.dart';

/// Describes the width and height of an object.
final class Size implements WinRTStruct {
Size(this.width, this.height);
const Size(this.width, this.height);

final double width;
final double height;
Expand Down
24 changes: 12 additions & 12 deletions packages/windows_foundation/test/collections_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void main() {
..insert('key6', const Duration(seconds: 30))
..insert('key7', guid)
..insert('key8', 259)
..insert('key9', Point(3, -3))
..insert('key10', Rect(2, -2, 200, 100))
..insert('key11', Size(300, 1500))
..insert('key9', const Point(3, -3))
..insert('key10', const Rect(2, -2, 200, 100))
..insert('key11', const Size(300, 1500))
..insert('key12', 'strVal')
..insert('key13', [true, false])
..insert('key14',
Expand All @@ -45,9 +45,9 @@ void main() {
..insert('key17', [guid])
..insert('key18', [StringMap()])
..insert('key19', [2022, -2022])
..insert('key20', [Point(3, -3)])
..insert('key21', [Rect(2, -2, 200, 100)])
..insert('key22', [Size(300, 1500)])
..insert('key20', [const Point(3, -3)])
..insert('key21', [const Rect(2, -2, 200, 100)])
..insert('key22', [const Size(300, 1500)])
..insert('key23', ['str1', 'str2']);
}

Expand Down Expand Up @@ -302,9 +302,9 @@ void main() {
..insert('key6', const Duration(seconds: 30))
..insert('key7', guid)
..insert('key8', 259)
..insert('key9', Point(3, -3))
..insert('key10', Rect(2, -2, 200, 100))
..insert('key11', Size(300, 1500))
..insert('key9', const Point(3, -3))
..insert('key10', const Rect(2, -2, 200, 100))
..insert('key11', const Size(300, 1500))
..insert('key12', 'strVal')
..insert('key13', [true, false])
..insert('key14',
Expand All @@ -313,9 +313,9 @@ void main() {
..insert('key16', const [Duration(hours: 1), Duration(minutes: 60)])
..insert('key17', [guid])
..insert('key18', [2022, -2022])
..insert('key19', [Point(3, -3)])
..insert('key20', [Rect(2, -2, 200, 100)])
..insert('key21', [Size(300, 1500)])
..insert('key19', [const Point(3, -3)])
..insert('key20', [const Rect(2, -2, 200, 100)])
..insert('key21', [const Size(300, 1500)])
..insert('key22', ['str1', 'str2']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void main() {

group("IPropertyValue's value extension getter returns", () {
test('Point', () {
final pv = PropertyValue.createPoint(Point(-1, 1));
final pv = PropertyValue.createPoint(const Point(-1, 1));
final value = pv.value;
expect(value, isA<Point>());
expect(value, equals(Point(-1, 1)));
expect(value, equals(const Point(-1, 1)));
});

test('String', () {
Expand Down Expand Up @@ -48,10 +48,11 @@ void main() {
});

test('List<Point>', () {
final pv = PropertyValue.createPointArray([Point(1, -1), Point(-1, 1)]);
final pv = PropertyValue.createPointArray(
[const Point(1, -1), const Point(-1, 1)]);
final value = pv.value;
expect(value, isA<List<Point>>());
expect(value, orderedEquals([Point(1, -1), Point(-1, 1)]));
expect(value, orderedEquals([const Point(1, -1), const Point(-1, 1)]));
});

test('List<String>', () {
Expand Down
6 changes: 3 additions & 3 deletions packages/windows_foundation/test/ireference_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ void main() {
});

test('Point?', () {
final reference = Point(50, 100).toReference();
final reference = const Point(50, 100).toReference();
expect(reference.value, isNotNull);
expect(reference.value?.x, equals(50));
expect(reference.value?.y, equals(100));
});

test('Rect?', () {
final reference = Rect(50, 100, 200, 100).toReference();
final reference = const Rect(50, 100, 200, 100).toReference();
expect(reference.value, isNotNull);
expect(reference.value?.height, equals(100));
expect(reference.value?.width, equals(200));
Expand All @@ -113,7 +113,7 @@ void main() {
});

test('Size?', () {
final reference = Size(100, 200).toReference();
final reference = const Size(100, 200).toReference();
expect(reference.value, isNotNull);
expect(reference.value?.height, equals(200));
expect(reference.value?.width, equals(100));
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_foundation/test/propertyvalue_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void main() {
});

test('Point', () {
final point = Point(10, 20);
const point = Point(10, 20);
final pv = PropertyValue.createPoint(point);
expect(pv.type, equals(PropertyType.point));
expect(pv.getPoint(), equals(point));
Expand Down
10 changes: 5 additions & 5 deletions packages/windows_foundation/test/struct_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ void main() {
..y = 2;

final point = nativePoint.toDart();
expect(point, equals(Point(1, 2)));
expect(point, equals(const Point(1, 2)));

free(nativePoint);
});
});

group('Point', () {
test('toNative', () {
final point = Point(1, -2);
const point = Point(1, -2);
final nativePointPtr = point.toNative();
final nativePoint = nativePointPtr.ref;
expect(nativePoint.x, equals(1));
Expand All @@ -52,9 +52,9 @@ void main() {

final list = nativePointPtr.toList(length: 3);
expect(list.length, equals(3));
expect(list[0], equals(Point(1, 2)));
expect(list[1], equals(Point(3, 4)));
expect(list[2], equals(Point(5, 6)));
expect(list[0], equals(const Point(1, 2)));
expect(list[1], equals(const Point(3, 4)));
expect(list[2], equals(const Point(5, 6)));

free(nativePointPtr);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_gaming/lib/src/input/gamepadreading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'gamepadbuttons.dart';

/// Represents the current state of the gamepad.
final class GamepadReading implements WinRTStruct {
GamepadReading(
const GamepadReading(
this.timestamp,
this.buttons,
this.leftTrigger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:windows_foundation/windows_foundation.dart';

/// Describes the gamepad motor speed.
final class GamepadVibration implements WinRTStruct {
GamepadVibration(
const GamepadVibration(
this.leftMotor, this.rightMotor, this.leftTrigger, this.rightTrigger);

final double leftMotor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// This is a Windows Runtime equivalent of the Desktop DXGI_SAMPLE_DESC
/// structure.
final class Direct3DMultisampleDescription implements WinRTStruct {
Direct3DMultisampleDescription(this.count, this.quality);
const Direct3DMultisampleDescription(this.count, this.quality);

final int count;
final int quality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'direct3dmultisampledescription.dart';
/// This is a Windows Runtime equivalent of the Desktop DXGI_SURFACE_DESC
/// structure. Describes an IDirect3DSurface.
final class Direct3DSurfaceDescription implements WinRTStruct {
Direct3DSurfaceDescription(
const Direct3DSurfaceDescription(
this.width, this.height, this.format, this.multisampleDescription);

final int width;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_graphics/lib/src/display/nitrange.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// Describes the minimum, maximum, and step size you can use when using
/// nits to describe brightness on a device.
final class NitRange implements WinRTStruct {
NitRange(this.minNits, this.maxNits, this.stepSizeNits);
const NitRange(this.minNits, this.maxNits, this.stepSizeNits);

final double minNits;
final double maxNits;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_graphics/lib/src/displayadapterid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// Corresponds to the LUID (Locally Unique Identifier) associated with a
/// graphics adapter.
final class DisplayAdapterId implements WinRTStruct {
DisplayAdapterId(this.lowPart, this.highPart);
const DisplayAdapterId(this.lowPart, this.highPart);

final int lowPart;
final int highPart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'package:windows_foundation/windows_foundation.dart';
/// transform is for the left display, and the other is for the right
/// display.
final class HolographicStereoTransform implements WinRTStruct {
HolographicStereoTransform(this.left, this.right);
const HolographicStereoTransform(this.left, this.right);

final Matrix4x4 left;
final Matrix4x4 right;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:windows_foundation/windows_foundation.dart';

/// Specifies a bounding rectangle.
final class BitmapBounds implements WinRTStruct {
BitmapBounds(this.x, this.y, this.width, this.height);
const BitmapBounds(this.x, this.y, this.width, this.height);

final int x;
final int y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import 'package:windows_foundation/windows_foundation.dart';

/// Defines the format of a bitmap plane.
final class BitmapPlaneDescription implements WinRTStruct {
BitmapPlaneDescription(this.startIndex, this.width, this.height, this.stride);
const BitmapPlaneDescription(
this.startIndex, this.width, this.height, this.stride);

final int startIndex;
final int width;
Expand Down
2 changes: 1 addition & 1 deletion packages/windows_graphics/lib/src/imaging/bitmapsize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'package:windows_foundation/windows_foundation.dart';

/// Represents the size of a bitmap, in pixels.
final class BitmapSize implements WinRTStruct {
BitmapSize(this.width, this.height);
const BitmapSize(this.width, this.height);

final int width;
final int height;
Expand Down

0 comments on commit c0ec409

Please sign in to comment.