├── .gitignore
├── LICENSE
├── PointerToolkit.Generator
├── .gitignore
├── PointerToolkit.Generator.csproj
└── Program.cs
├── PointerToolkit.sln
├── PointerToolkit
├── .gitignore
├── CastPtr`1.Generated.cs
├── CastPtr`10.Generated.cs
├── CastPtr`11.Generated.cs
├── CastPtr`12.Generated.cs
├── CastPtr`13.Generated.cs
├── CastPtr`14.Generated.cs
├── CastPtr`15.Generated.cs
├── CastPtr`16.Generated.cs
├── CastPtr`17.Generated.cs
├── CastPtr`2.Generated.cs
├── CastPtr`3.Generated.cs
├── CastPtr`4.Generated.cs
├── CastPtr`5.Generated.cs
├── CastPtr`6.Generated.cs
├── CastPtr`7.Generated.cs
├── CastPtr`8.Generated.cs
├── CastPtr`9.Generated.cs
├── FodyWeavers.xml
├── FodyWeavers.xsd
├── InterlockedPtr.cs
├── PointerToolkit.csproj
├── Ptr.cs
├── PtrOperators.cs
├── PtrPtr.cs
├── PtrPtrPtr.cs
├── PtrPtrPtr`1.cs
├── PtrPtr`1.cs
├── Ptr`1.cs
├── UnsafePtr.cs
└── VolatilePtr.cs
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Rick Brewster
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/PointerToolkit.Generator/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | obj
3 | PointerToolkit.Generator.csproj.user
4 |
--------------------------------------------------------------------------------
/PointerToolkit.Generator/PointerToolkit.Generator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | enable
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/PointerToolkit.Generator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | public static class Program
7 | {
8 | public static int Main(string[] args)
9 | {
10 | try
11 | {
12 | MainImpl(args[0]);
13 | return 0;
14 | }
15 | catch (Exception ex)
16 | {
17 | Console.WriteLine();
18 | Console.WriteLine("*** Unhandled Exception: " + ex.ToString());
19 | return ex.HResult;
20 | }
21 | }
22 |
23 | public static void MainImpl(string outputDirPath)
24 | {
25 | Console.WriteLine($"PointerToolkit generator, outputting to {outputDirPath}");
26 |
27 | // This must be at least 1 plus the maximum number of base COM interfaces needed to support TerraFX.Interop.Windows
28 | // (currently 16 for 10.0.22621.2).
29 | const int maxBaseCount = 16;
30 |
31 | // CastPtr`N.Generated.cs
32 | for (int baseCount = 0; baseCount <= maxBaseCount; ++baseCount)
33 | {
34 | GenerateFile(
35 | Path.Combine(outputDirPath, $"CastPtr`{baseCount + 1}.Generated.cs"),
36 | delegate (TextWriter writer)
37 | {
38 | writer.WriteLine("#nullable enable");
39 | writer.WriteLine();
40 | writer.WriteLine("using System;");
41 | writer.WriteLine("using System.Runtime.CompilerServices;");
42 | writer.WriteLine();
43 | writer.WriteLine("namespace PointerToolkit;");
44 |
45 | string typeList;
46 | {
47 | StringBuilder builder = new();
48 | builder.Append("T");
49 | for (int i = 1; i <= baseCount; ++i)
50 | {
51 | builder.Append($", TBase{i}");
52 | }
53 |
54 | typeList = builder.ToString();
55 | }
56 |
57 | writer.WriteLine();
58 | writer.WriteLine($"public unsafe readonly ref struct CastPtr<{typeList}>");
59 | writer.WriteLine(" where T : unmanaged");
60 | for (int i = 1; i <= baseCount; ++i)
61 | {
62 | writer.WriteLine($" where TBase{i} : unmanaged");
63 | }
64 | writer.WriteLine("{");
65 | writer.WriteLine(" private readonly T* p;");
66 | writer.WriteLine();
67 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
68 | writer.WriteLine(" private CastPtr(T* p) => this.p = p;");
69 | writer.WriteLine();
70 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
71 | writer.WriteLine($" public static implicit operator CastPtr<{typeList}>(T* p) => *(CastPtr<{typeList}>*)&p;");
72 | writer.WriteLine();
73 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
74 | writer.WriteLine($" public static implicit operator T*(CastPtr<{typeList}> ptr) => ptr.p;");
75 | for (int i = 1; i <= baseCount; ++i)
76 | {
77 | writer.WriteLine();
78 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
79 | writer.WriteLine($" public static implicit operator TBase{i}*(CastPtr<{typeList}> ptr) => (TBase{i}*)ptr.p;");
80 | }
81 | writer.WriteLine();
82 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
83 | writer.WriteLine($" public static implicit operator void*(CastPtr<{typeList}> ptr) => ptr.p;");
84 |
85 | // Casts to Ptr. Commented out because I don't really have a good justification for including them yet.
86 | /*
87 | writer.WriteLine();
88 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
89 | writer.WriteLine($" public static implicit operator Ptr(CastPtr<{typeList}> ptr) => ptr.p;");
90 | for (int i = 1; i <= baseCount; ++i)
91 | {
92 | writer.WriteLine();
93 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
94 | writer.WriteLine($" public static implicit operator Ptr(CastPtr<{typeList}> ptr) => (TBase{i}*)ptr.p;");
95 | }
96 | writer.WriteLine();
97 | writer.WriteLine(" [MethodImpl(MethodImplOptions.AggressiveInlining)]");
98 | writer.WriteLine($" public static implicit operator Ptr(CastPtr<{typeList}> ptr) => ptr.p;");
99 | */
100 |
101 | // It could also be reasonable to add implicit casts from CastPtr to CastPtr etc.
102 | // But I'd rather wait until there's an actual need for something like that. Otherwise it's just adding code for the sake
103 | // of adding code.
104 |
105 | writer.WriteLine("}");
106 | });
107 | }
108 | }
109 |
110 | public static void GenerateFile(string filePath, Action writeCallback)
111 | {
112 | Console.Write($"{filePath} ... ");
113 |
114 | using MemoryStream stream = new MemoryStream();
115 | using (TextWriter writer = new StreamWriter(stream, Encoding.UTF8, leaveOpen: true))
116 | {
117 | writeCallback(writer);
118 | }
119 |
120 | byte[] newBytes = stream.GetBuffer();
121 | Array.Resize(ref newBytes, checked((int)stream.Length));
122 |
123 | if (File.Exists(filePath))
124 | {
125 | byte[] oldBytes = File.ReadAllBytes(filePath);
126 |
127 | if (oldBytes.SequenceEqual(newBytes))
128 | {
129 | // don't write anything
130 | Console.WriteLine("unchanged");
131 | return;
132 | }
133 | }
134 |
135 | File.WriteAllBytes(filePath, newBytes);
136 | Console.WriteLine();
137 | }
138 | }
--------------------------------------------------------------------------------
/PointerToolkit.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31912.275
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PointerToolkit", "PointerToolkit\PointerToolkit.csproj", "{66D535EB-2199-4A92-BFAB-CBE02CE72185}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {1D436E15-06D0-4F5B-8779-6C45910BD134} = {1D436E15-06D0-4F5B-8779-6C45910BD134}
9 | EndProjectSection
10 | EndProject
11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PointerToolkit.Generator", "PointerToolkit.Generator\PointerToolkit.Generator.csproj", "{1D436E15-06D0-4F5B-8779-6C45910BD134}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {66D535EB-2199-4A92-BFAB-CBE02CE72185}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {66D535EB-2199-4A92-BFAB-CBE02CE72185}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {66D535EB-2199-4A92-BFAB-CBE02CE72185}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {66D535EB-2199-4A92-BFAB-CBE02CE72185}.Release|Any CPU.Build.0 = Release|Any CPU
23 | {1D436E15-06D0-4F5B-8779-6C45910BD134}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {1D436E15-06D0-4F5B-8779-6C45910BD134}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {1D436E15-06D0-4F5B-8779-6C45910BD134}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {1D436E15-06D0-4F5B-8779-6C45910BD134}.Release|Any CPU.Build.0 = Release|Any CPU
27 | EndGlobalSection
28 | GlobalSection(SolutionProperties) = preSolution
29 | HideSolutionNode = FALSE
30 | EndGlobalSection
31 | GlobalSection(ExtensibilityGlobals) = postSolution
32 | SolutionGuid = {789C5031-8505-40E6-ABD9-2E73C30EA60A}
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/PointerToolkit/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | obj
3 | PointerToolkit.csproj.user
4 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`1.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | {
11 | private readonly T* p;
12 |
13 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
14 | private CastPtr(T* p) => this.p = p;
15 |
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
18 |
19 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
20 | public static implicit operator T*(CastPtr ptr) => ptr.p;
21 |
22 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
23 | public static implicit operator void*(CastPtr ptr) => ptr.p;
24 | }
25 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`10.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | {
20 | private readonly T* p;
21 |
22 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
23 | private CastPtr(T* p) => this.p = p;
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
27 |
28 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 | public static implicit operator T*(CastPtr ptr) => ptr.p;
30 |
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
36 |
37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
42 |
43 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
45 |
46 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
47 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
48 |
49 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
50 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
51 |
52 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
54 |
55 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
56 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
57 |
58 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
59 | public static implicit operator void*(CastPtr ptr) => ptr.p;
60 | }
61 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`11.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | {
21 | private readonly T* p;
22 |
23 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 | private CastPtr(T* p) => this.p = p;
25 |
26 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
27 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
28 |
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | public static implicit operator T*(CastPtr ptr) => ptr.p;
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
37 |
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
40 |
41 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
43 |
44 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
46 |
47 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
48 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
49 |
50 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
52 |
53 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
54 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
55 |
56 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
57 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
58 |
59 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
60 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
61 |
62 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 | public static implicit operator void*(CastPtr ptr) => ptr.p;
64 | }
65 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`12.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | where TBase11 : unmanaged
21 | {
22 | private readonly T* p;
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | private CastPtr(T* p) => this.p = p;
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
29 |
30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 | public static implicit operator T*(CastPtr ptr) => ptr.p;
32 |
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
35 |
36 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
37 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
38 |
39 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
41 |
42 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
43 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
44 |
45 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
46 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
47 |
48 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
50 |
51 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
52 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
53 |
54 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
56 |
57 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
58 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
59 |
60 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
62 |
63 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
64 | public static implicit operator TBase11*(CastPtr ptr) => (TBase11*)ptr.p;
65 |
66 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
67 | public static implicit operator void*(CastPtr ptr) => ptr.p;
68 | }
69 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`13.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | where TBase11 : unmanaged
21 | where TBase12 : unmanaged
22 | {
23 | private readonly T* p;
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | private CastPtr(T* p) => this.p = p;
27 |
28 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
30 |
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static implicit operator T*(CastPtr ptr) => ptr.p;
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
36 |
37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
42 |
43 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
45 |
46 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
47 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
48 |
49 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
50 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
51 |
52 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
54 |
55 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
56 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
57 |
58 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
59 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
60 |
61 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
62 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
63 |
64 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
65 | public static implicit operator TBase11*(CastPtr ptr) => (TBase11*)ptr.p;
66 |
67 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
68 | public static implicit operator TBase12*(CastPtr ptr) => (TBase12*)ptr.p;
69 |
70 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
71 | public static implicit operator void*(CastPtr ptr) => ptr.p;
72 | }
73 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`14.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | where TBase11 : unmanaged
21 | where TBase12 : unmanaged
22 | where TBase13 : unmanaged
23 | {
24 | private readonly T* p;
25 |
26 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
27 | private CastPtr(T* p) => this.p = p;
28 |
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public static implicit operator T*(CastPtr ptr) => ptr.p;
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
37 |
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
40 |
41 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
43 |
44 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
46 |
47 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
48 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
49 |
50 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
52 |
53 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
54 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
55 |
56 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
57 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
58 |
59 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
60 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
61 |
62 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
64 |
65 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
66 | public static implicit operator TBase11*(CastPtr ptr) => (TBase11*)ptr.p;
67 |
68 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
69 | public static implicit operator TBase12*(CastPtr ptr) => (TBase12*)ptr.p;
70 |
71 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
72 | public static implicit operator TBase13*(CastPtr ptr) => (TBase13*)ptr.p;
73 |
74 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
75 | public static implicit operator void*(CastPtr ptr) => ptr.p;
76 | }
77 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`15.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | where TBase11 : unmanaged
21 | where TBase12 : unmanaged
22 | where TBase13 : unmanaged
23 | where TBase14 : unmanaged
24 | {
25 | private readonly T* p;
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | private CastPtr(T* p) => this.p = p;
29 |
30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
32 |
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | public static implicit operator T*(CastPtr ptr) => ptr.p;
35 |
36 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
37 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
38 |
39 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
41 |
42 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
43 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
44 |
45 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
46 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
47 |
48 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
50 |
51 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
52 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
53 |
54 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
56 |
57 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
58 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
59 |
60 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
62 |
63 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
64 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
65 |
66 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
67 | public static implicit operator TBase11*(CastPtr ptr) => (TBase11*)ptr.p;
68 |
69 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
70 | public static implicit operator TBase12*(CastPtr ptr) => (TBase12*)ptr.p;
71 |
72 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
73 | public static implicit operator TBase13*(CastPtr ptr) => (TBase13*)ptr.p;
74 |
75 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
76 | public static implicit operator TBase14*(CastPtr ptr) => (TBase14*)ptr.p;
77 |
78 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
79 | public static implicit operator void*(CastPtr ptr) => ptr.p;
80 | }
81 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`16.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | where TBase11 : unmanaged
21 | where TBase12 : unmanaged
22 | where TBase13 : unmanaged
23 | where TBase14 : unmanaged
24 | where TBase15 : unmanaged
25 | {
26 | private readonly T* p;
27 |
28 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 | private CastPtr(T* p) => this.p = p;
30 |
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static implicit operator T*(CastPtr ptr) => ptr.p;
36 |
37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
42 |
43 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
45 |
46 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
47 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
48 |
49 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
50 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
51 |
52 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
54 |
55 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
56 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
57 |
58 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
59 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
60 |
61 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
62 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
63 |
64 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
65 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
66 |
67 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
68 | public static implicit operator TBase11*(CastPtr ptr) => (TBase11*)ptr.p;
69 |
70 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
71 | public static implicit operator TBase12*(CastPtr ptr) => (TBase12*)ptr.p;
72 |
73 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
74 | public static implicit operator TBase13*(CastPtr ptr) => (TBase13*)ptr.p;
75 |
76 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
77 | public static implicit operator TBase14*(CastPtr ptr) => (TBase14*)ptr.p;
78 |
79 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
80 | public static implicit operator TBase15*(CastPtr ptr) => (TBase15*)ptr.p;
81 |
82 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
83 | public static implicit operator void*(CastPtr ptr) => ptr.p;
84 | }
85 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`17.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | where TBase9 : unmanaged
19 | where TBase10 : unmanaged
20 | where TBase11 : unmanaged
21 | where TBase12 : unmanaged
22 | where TBase13 : unmanaged
23 | where TBase14 : unmanaged
24 | where TBase15 : unmanaged
25 | where TBase16 : unmanaged
26 | {
27 | private readonly T* p;
28 |
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | private CastPtr(T* p) => this.p = p;
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public static implicit operator T*(CastPtr ptr) => ptr.p;
37 |
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
40 |
41 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
43 |
44 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
46 |
47 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
48 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
49 |
50 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
52 |
53 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
54 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
55 |
56 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
57 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
58 |
59 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
60 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
61 |
62 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 | public static implicit operator TBase9*(CastPtr ptr) => (TBase9*)ptr.p;
64 |
65 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
66 | public static implicit operator TBase10*(CastPtr ptr) => (TBase10*)ptr.p;
67 |
68 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
69 | public static implicit operator TBase11*(CastPtr ptr) => (TBase11*)ptr.p;
70 |
71 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
72 | public static implicit operator TBase12*(CastPtr ptr) => (TBase12*)ptr.p;
73 |
74 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
75 | public static implicit operator TBase13*(CastPtr ptr) => (TBase13*)ptr.p;
76 |
77 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
78 | public static implicit operator TBase14*(CastPtr ptr) => (TBase14*)ptr.p;
79 |
80 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
81 | public static implicit operator TBase15*(CastPtr ptr) => (TBase15*)ptr.p;
82 |
83 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
84 | public static implicit operator TBase16*(CastPtr ptr) => (TBase16*)ptr.p;
85 |
86 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
87 | public static implicit operator void*(CastPtr ptr) => ptr.p;
88 | }
89 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`2.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | {
12 | private readonly T* p;
13 |
14 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
15 | private CastPtr(T* p) => this.p = p;
16 |
17 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
18 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
19 |
20 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
21 | public static implicit operator T*(CastPtr ptr) => ptr.p;
22 |
23 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
25 |
26 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
27 | public static implicit operator void*(CastPtr ptr) => ptr.p;
28 | }
29 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`3.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | {
13 | private readonly T* p;
14 |
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | private CastPtr(T* p) => this.p = p;
17 |
18 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | public static implicit operator T*(CastPtr ptr) => ptr.p;
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
29 |
30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 | public static implicit operator void*(CastPtr ptr) => ptr.p;
32 | }
33 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`4.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | {
14 | private readonly T* p;
15 |
16 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 | private CastPtr(T* p) => this.p = p;
18 |
19 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
20 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
21 |
22 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
23 | public static implicit operator T*(CastPtr ptr) => ptr.p;
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
27 |
28 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
30 |
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static implicit operator void*(CastPtr ptr) => ptr.p;
36 | }
37 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`5.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | {
15 | private readonly T* p;
16 |
17 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
18 | private CastPtr(T* p) => this.p = p;
19 |
20 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
21 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
22 |
23 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 | public static implicit operator T*(CastPtr ptr) => ptr.p;
25 |
26 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
27 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
28 |
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
37 |
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static implicit operator void*(CastPtr ptr) => ptr.p;
40 | }
41 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`6.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | {
16 | private readonly T* p;
17 |
18 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 | private CastPtr(T* p) => this.p = p;
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public static implicit operator T*(CastPtr ptr) => ptr.p;
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
29 |
30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
32 |
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
35 |
36 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
37 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
38 |
39 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
41 |
42 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
43 | public static implicit operator void*(CastPtr ptr) => ptr.p;
44 | }
45 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`7.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | {
17 | private readonly T* p;
18 |
19 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
20 | private CastPtr(T* p) => this.p = p;
21 |
22 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
23 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | public static implicit operator T*(CastPtr ptr) => ptr.p;
27 |
28 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
30 |
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
36 |
37 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
42 |
43 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
45 |
46 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
47 | public static implicit operator void*(CastPtr ptr) => ptr.p;
48 | }
49 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`8.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | {
18 | private readonly T* p;
19 |
20 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
21 | private CastPtr(T* p) => this.p = p;
22 |
23 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
25 |
26 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
27 | public static implicit operator T*(CastPtr ptr) => ptr.p;
28 |
29 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
30 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
37 |
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
40 |
41 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
43 |
44 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
46 |
47 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
48 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
49 |
50 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
51 | public static implicit operator void*(CastPtr ptr) => ptr.p;
52 | }
53 |
--------------------------------------------------------------------------------
/PointerToolkit/CastPtr`9.Generated.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | using System;
4 | using System.Runtime.CompilerServices;
5 |
6 | namespace PointerToolkit;
7 |
8 | public unsafe readonly ref struct CastPtr
9 | where T : unmanaged
10 | where TBase1 : unmanaged
11 | where TBase2 : unmanaged
12 | where TBase3 : unmanaged
13 | where TBase4 : unmanaged
14 | where TBase5 : unmanaged
15 | where TBase6 : unmanaged
16 | where TBase7 : unmanaged
17 | where TBase8 : unmanaged
18 | {
19 | private readonly T* p;
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | private CastPtr(T* p) => this.p = p;
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public static implicit operator CastPtr(T* p) => *(CastPtr*)&p;
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public static implicit operator T*(CastPtr ptr) => ptr.p;
29 |
30 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 | public static implicit operator TBase1*(CastPtr ptr) => (TBase1*)ptr.p;
32 |
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | public static implicit operator TBase2*(CastPtr ptr) => (TBase2*)ptr.p;
35 |
36 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
37 | public static implicit operator TBase3*(CastPtr ptr) => (TBase3*)ptr.p;
38 |
39 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
40 | public static implicit operator TBase4*(CastPtr ptr) => (TBase4*)ptr.p;
41 |
42 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
43 | public static implicit operator TBase5*(CastPtr ptr) => (TBase5*)ptr.p;
44 |
45 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
46 | public static implicit operator TBase6*(CastPtr ptr) => (TBase6*)ptr.p;
47 |
48 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 | public static implicit operator TBase7*(CastPtr ptr) => (TBase7*)ptr.p;
50 |
51 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
52 | public static implicit operator TBase8*(CastPtr ptr) => (TBase8*)ptr.p;
53 |
54 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 | public static implicit operator void*(CastPtr ptr) => ptr.p;
56 | }
57 |
--------------------------------------------------------------------------------
/PointerToolkit/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/PointerToolkit/FodyWeavers.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Defines if sequence points should be generated for each emitted IL instruction. Default value: Debug
12 |
13 |
14 |
15 |
16 |
17 | Insert sequence points in Debug builds only (this is the default).
18 |
19 |
20 |
21 |
22 | Insert sequence points in Release builds only.
23 |
24 |
25 |
26 |
27 | Always insert sequence points.
28 |
29 |
30 |
31 |
32 | Never insert sequence points.
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | Defines how warnings should be handled. Default value: Warnings
41 |
42 |
43 |
44 |
45 |
46 | Emit build warnings (this is the default).
47 |
48 |
49 |
50 |
51 | Do not emit warnings.
52 |
53 |
54 |
55 |
56 | Treat warnings as errors.
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.
68 |
69 |
70 |
71 |
72 | A comma-separated list of error codes that can be safely ignored in assembly verification.
73 |
74 |
75 |
76 |
77 | 'false' to turn off automatic generation of the XML Schema file.
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/PointerToolkit/InterlockedPtr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Threading;
4 |
5 | namespace PointerToolkit;
6 |
7 | public static unsafe class InterlockedPtr
8 | {
9 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
10 | public static void* CompareExchange(ref void* location1, void* value, void* comparand)
11 | {
12 | return (void*)Interlocked.CompareExchange(ref UnsafePtr.As(ref location1), (IntPtr)value, (IntPtr)comparand);
13 | }
14 |
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | public static void** CompareExchange(ref void** location1, void** value, void** comparand)
17 | {
18 | return (void**)Interlocked.CompareExchange(ref UnsafePtr.As(ref location1), (IntPtr)value, (IntPtr)comparand);
19 | }
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | public static void*** CompareExchange(ref void*** location1, void*** value, void*** comparand)
23 | {
24 | return (void***)Interlocked.CompareExchange(ref UnsafePtr.As(ref location1), (IntPtr)value, (IntPtr)comparand);
25 | }
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public static T* CompareExchange(ref T* location1, T* value, T* comparand)
29 | where T : unmanaged
30 | {
31 | return (T*)Interlocked.CompareExchange(ref UnsafePtr.As(ref location1), (IntPtr)value, (IntPtr)comparand);
32 | }
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static T** CompareExchange(ref T** location1, T** value, T** comparand)
36 | where T : unmanaged
37 | {
38 | return (T**)Interlocked.CompareExchange(ref UnsafePtr.As(ref location1), (IntPtr)value, (IntPtr)comparand);
39 | }
40 |
41 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
42 | public static T*** CompareExchange(ref T*** location1, T*** value, T*** comparand)
43 | where T : unmanaged
44 | {
45 | return (T***)Interlocked.CompareExchange(ref UnsafePtr.As(ref location1), (IntPtr)value, (IntPtr)comparand);
46 | }
47 |
48 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 | public static void* Exchange(ref void* location1, void* value)
50 | {
51 | return (void*)Interlocked.Exchange(ref UnsafePtr.As(ref location1), (IntPtr)value);
52 | }
53 |
54 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
55 | public static void** Exchange(ref void** location1, void** value)
56 | {
57 | return (void**)Interlocked.Exchange(ref UnsafePtr.As(ref location1), (IntPtr)value);
58 | }
59 |
60 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
61 | public static void*** Exchange(ref void*** location1, void*** value)
62 | {
63 | return (void***)Interlocked.Exchange(ref UnsafePtr.As(ref location1), (IntPtr)value);
64 | }
65 |
66 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
67 | public static T* Exchange(ref T* location1, T* value)
68 | where T : unmanaged
69 | {
70 | return (T*)Interlocked.Exchange(ref UnsafePtr.As(ref location1), (IntPtr)value);
71 | }
72 |
73 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
74 | public static T** Exchange(ref T** location1, T** value)
75 | where T : unmanaged
76 | {
77 | return (T**)Interlocked.Exchange(ref UnsafePtr.As(ref location1), (IntPtr)value);
78 | }
79 |
80 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
81 | public static T*** Exchange(ref T*** location1, T*** value)
82 | where T : unmanaged
83 | {
84 | return (T***)Interlocked.Exchange(ref UnsafePtr.As(ref location1), (IntPtr)value);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/PointerToolkit/PointerToolkit.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net6.0
4 | PointerToolkit
5 | enable
6 | strict
7 | true
8 | True
9 | OnOutputUpdated
10 | True
11 | Copyright ©️ Rick Brewster
12 | https://github.com/rickbrew/PointerToolkit
13 | https://github.com/rickbrew/PointerToolkit
14 | interlocked;pointer;pointers;unsafe;volatile
15 | 1.0.1
16 | $(VersionPrefix)
17 | README.md
18 |
19 |
20 | MIT
21 | Provides structs that wrap pointers, as well as Unsafe, Interlocked, and Volatile operations on ref pointers.
22 | Rick Brewster
23 |
24 |
25 | True
26 |
27 |
28 | True
29 |
30 |
31 |
32 | README.md
33 | True
34 | \
35 |
36 |
37 |
38 |
39 | all
40 | runtime; build; native; contentfiles; analyzers; buildtransitive
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/PointerToolkit/Ptr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace PointerToolkit;
5 |
6 | public unsafe readonly struct Ptr
7 | : IEquatable,
8 | IComparable,
9 | IFormattable
10 | {
11 | private readonly void* p;
12 |
13 | private Ptr(void* p) => this.p = p;
14 |
15 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
16 | public int CompareTo(Ptr other) => ((IntPtr)this.p).CompareTo(other);
17 |
18 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 | public override bool Equals(object? other) => (other is Ptr p) && (this.p == p.p);
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | public bool Equals(Ptr other) => this.p == other.p;
23 |
24 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 | public void* Get() => this.p;
26 |
27 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
28 | public override int GetHashCode() => ((IntPtr)this.p).GetHashCode();
29 |
30 | public override string ToString()
31 | {
32 | return ((UIntPtr)this.p).ToString(sizeof(IntPtr) == 4 ? "X8" : "X16");
33 | }
34 |
35 | public string ToString(string? format, IFormatProvider? formatProvider)
36 | {
37 | return ((UIntPtr)this.p).ToString(format, formatProvider);
38 | }
39 |
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | public static implicit operator Ptr(void* p) => UnsafePtr.As(ref p);
42 |
43 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 | public static implicit operator Ptr(void** p) => UnsafePtr.As(ref p);
45 |
46 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
47 | public static implicit operator Ptr(void*** p) => UnsafePtr.As(ref p);
48 |
49 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
50 | public static implicit operator Ptr(PtrPtr ptr) => Unsafe.As(ref ptr);
51 |
52 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
53 | public static implicit operator Ptr(PtrPtrPtr ptr) => Unsafe.As(ref ptr);
54 |
55 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
56 | public static implicit operator Ptr(IntPtr intPtr) => Unsafe.As(ref intPtr);
57 |
58 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
59 | public static implicit operator IntPtr(Ptr ptr) => Unsafe.As(ref ptr);
60 |
61 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
62 | public static implicit operator Ptr(UIntPtr intPtr) => Unsafe.As