diff options
Diffstat (limited to 'vulkan/Utf8StringPointer.cs')
| -rw-r--r-- | vulkan/Utf8StringPointer.cs | 33 |
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 |