Skip to content

Commit e5a41f8

Browse files
committed
Added more operator overridings for pointer
1 parent 2719634 commit e5a41f8

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

DotnetNativeBase/DotnetNativeBase.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageProjectUrl>https://github.com/DotnetNative/DotnetNativeBase</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/DotnetNative/DotnetNativeBase</RepositoryUrl>
1212
<PackageTags>naot korn dnb native</PackageTags>
13-
<Version>1.0.3</Version>
13+
<Version>1.0.5</Version>
1414
<Platforms>x64</Platforms>
1515
<PackageReadmeFile>PACK.md</PackageReadmeFile>
1616
<IncludeContentInPack>true</IncludeContentInPack>

DotnetNativeBase/pointer.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,33 @@ public unsafe struct pointer
55

66
public nint Address;
77

8+
public byte this[nint index] => ((byte*)Address)[index];
9+
10+
public override string ToString() => $"0x{Address:X}";
11+
public override bool Equals(object? obj) => obj is null ? false : obj is pointer ? (((pointer)obj).Address == Address) : false;
12+
public override int GetHashCode() => ((int)Address) ^ ((int)(Address >> 32));
13+
814
#region Operators
9-
public static pointer operator +(pointer a, pointer b) => new(a.Address + b.Address);
10-
public static pointer operator -(pointer a, pointer b) => new(a.Address - b.Address);
15+
public static pointer operator +(pointer a, pointer b) => a.Address + b.Address;
16+
public static pointer operator -(pointer a, pointer b) => a.Address - b.Address;
1117
public static pointer operator ++(pointer self) => self.Address++;
1218
public static pointer operator --(pointer self) => self.Address--;
13-
public static pointer operator *(pointer a, pointer b) => new(a.Address * b.Address);
14-
public static pointer operator /(pointer a, pointer b) => new(a.Address / b.Address);
15-
public static pointer operator %(pointer a, pointer b) => new(a.Address % b.Address);
16-
public static pointer operator &(pointer a, pointer b) => new(a.Address & b.Address);
17-
public static pointer operator ^(pointer a, pointer b) => new(a.Address ^ b.Address);
18-
public static pointer operator |(pointer a, pointer b) => new(a.Address | b.Address);
19-
#endregion
20-
21-
#region Object
22-
public override string ToString() => $"0x{Address:X}";
19+
public static pointer operator ~(pointer self) => ~self.Address;
20+
public static pointer operator *(pointer a, pointer b) => a.Address * b.Address;
21+
public static pointer operator /(pointer a, pointer b) => a.Address / b.Address;
22+
public static pointer operator %(pointer a, pointer b) => a.Address % b.Address;
23+
public static pointer operator &(pointer a, pointer b) => a.Address & b.Address;
24+
public static pointer operator ^(pointer a, pointer b) => a.Address ^ b.Address;
25+
public static pointer operator |(pointer a, pointer b) => a.Address | b.Address;
26+
public static pointer operator >>(pointer a, int shift) => a.Address >> shift;
27+
public static pointer operator <<(pointer a, int shift) => a.Address << shift;
28+
public static pointer operator >>>(pointer a, int shift) => a.Address >>> shift;
29+
public static bool operator <(pointer a, pointer b) => a.Address < b.Address;
30+
public static bool operator <=(pointer a, pointer b) => a.Address <= b.Address;
31+
public static bool operator >(pointer a, pointer b) => a.Address > b.Address;
32+
public static bool operator >=(pointer a, pointer b) => a.Address >= b.Address;
33+
public static bool operator ==(pointer a, pointer b) => a.Address == b.Address;
34+
public static bool operator !=(pointer a, pointer b) => a.Address != b.Address;
2335
#endregion
2436

2537
#region Implicits

0 commit comments

Comments
 (0)