From 1fa6ee6082416c32ca421093152b0e679d464a8e Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 18 Jan 2008 14:15:37 +0000 Subject: [PATCH] Moved ContextHandle to its own class. --- Source/OpenTK/ContextHandle.cs | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Source/OpenTK/ContextHandle.cs diff --git a/Source/OpenTK/ContextHandle.cs b/Source/OpenTK/ContextHandle.cs new file mode 100644 index 00000000..1c3fb27d --- /dev/null +++ b/Source/OpenTK/ContextHandle.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenTK +{ + internal class ContextHandle : /*System.Runtime.InteropServices.SafeHandle,*/ IComparable + { + IntPtr handle; + public IntPtr Handle { get { return handle; } } + + public ContextHandle() /*: base(IntPtr.Zero, true)*/ { } + public ContextHandle(IntPtr h) { handle = h; } + + #region IComparable Members + + public int CompareTo(ContextHandle other) + { + unsafe { return (int)((int*)other.handle.ToPointer() - (int*)this.handle.ToPointer()); } + } + + #endregion + + public override string ToString() + { + return Handle.ToString(); + } + + public override bool Equals(object obj) + { + if (obj is ContextHandle) + return this.Handle == ((ContextHandle)obj).Handle; + return false; + } + + public override int GetHashCode() + { + return Handle.GetHashCode(); + } + + /* + public override bool IsInvalid + { + get { return handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + throw new NotImplementedException(); + } + */ + + public static implicit operator IntPtr(ContextHandle c) + { + return c.handle; + } + + public static implicit operator ContextHandle(IntPtr p) + { + return new ContextHandle(p); + } + } +}