aboutsummaryrefslogtreecommitdiffstatsci
path: root/vulkan/Utf8StringPointer.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-12-04 04:13:56 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-12-04 04:13:56 +0100
commitba592ca9099fe4e378692bd2e8c953de90a4beb5 (patch)
tree766a1bf12e789bf37b86818584b5ed1998e01cb0 /vulkan/Utf8StringPointer.cs
parent0bbba34c81f356da8e00e04d0f61c6b9a66337c9 (diff)
Utf8StringPointer
Diffstat (limited to 'vulkan/Utf8StringPointer.cs')
-rw-r--r--vulkan/Utf8StringPointer.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/vulkan/Utf8StringPointer.cs b/vulkan/Utf8StringPointer.cs
new file mode 100644
index 0000000..93ae3d3
--- /dev/null
+++ b/vulkan/Utf8StringPointer.cs
@@ -0,0 +1,33 @@
+// Copyright (c) 2022 Bruyère Jean-Philippe jp_bruyere@hotmail.com
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Vulkan
+{
+ public struct Utf8StringPointer : IDisposable
+ {
+ IntPtr handle;
+ Utf8StringPointer (IntPtr ptr) {
+ handle = ptr;
+ }
+ public Utf8StringPointer (string str) {
+ handle = str.PinPointer();
+ }
+ public static implicit operator string (Utf8StringPointer pt)
+ => pt.ToString();
+ public static implicit operator IntPtr (Utf8StringPointer pt)
+ => pt.handle;
+ public static implicit operator Utf8StringPointer (IntPtr ptr)
+ => new Utf8StringPointer (ptr);
+ public static implicit operator Utf8StringPointer (string s)
+ => new Utf8StringPointer (s);
+ public override string ToString()
+ => handle == IntPtr.Zero ? "" : System.Runtime.InteropServices.Marshal.PtrToStringUTF8 (handle);
+ public void Dispose()
+ {
+ handle.Unpin();
+ }
+ }
+} \ No newline at end of file