From ba592ca9099fe4e378692bd2e8c953de90a4beb5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Sat, 4 Dec 2021 04:13:56 +0100 Subject: Utf8StringPointer --- vulkan/Utf8StringPointer.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 vulkan/Utf8StringPointer.cs (limited to 'vulkan/Utf8StringPointer.cs') 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 -- cgit v1.3.1-4-g156e