00001 #region --- License ---
00002
00003
00004
00005
00006
00007 #endregion
00008
00009 using System;
00010 using System.Collections.Generic;
00011 using System.Text;
00012
00013 namespace OpenTK
00014 {
00018 public struct ContextHandle : IComparable<ContextHandle>, IEquatable<ContextHandle>
00019 {
00020 #region Fields
00021
00022 IntPtr handle;
00023
00027 public IntPtr Handle { get { return handle; } }
00028
00030 public static readonly ContextHandle Zero = new ContextHandle(IntPtr.Zero);
00031
00032 #endregion
00033
00034 #region Constructors
00035
00040 public ContextHandle(IntPtr h) { handle = h; }
00041
00042 #endregion
00043
00044 #region Public Members
00045
00046 #region ToString
00047
00052 public override string ToString()
00053 {
00054 return Handle.ToString();
00055 }
00056
00057 #endregion
00058
00059 #region Equals
00060
00066 public override bool Equals(object obj)
00067 {
00068 if (obj is ContextHandle)
00069 return this.Equals((ContextHandle)obj);
00070 return false;
00071 }
00072
00073 #endregion
00074
00075 #region GetHashCode
00076
00081 public override int GetHashCode()
00082 {
00083 return Handle.GetHashCode();
00084 }
00085
00086 #endregion
00087
00088 #region public static explicit operator IntPtr(ContextHandle c)
00089
00095 public static explicit operator IntPtr(ContextHandle c)
00096 {
00097 return c != ContextHandle.Zero ? c.handle : IntPtr.Zero;
00098 }
00099
00100 #endregion
00101
00102 #region public static explicit operator ContextHandle(IntPtr p)
00103
00109 public static explicit operator ContextHandle(IntPtr p)
00110 {
00111 return new ContextHandle(p);
00112 }
00113
00114 #endregion
00115
00116 #region public static bool operator ==(ContextHandle left, ContextHandle right)
00117
00124 public static bool operator ==(ContextHandle left, ContextHandle right)
00125 {
00126 return left.Equals(right);
00127 }
00128
00129 #endregion
00130
00131 #region public static bool operator !=(ContextHandle left, ContextHandle right)
00132
00139 public static bool operator !=(ContextHandle left, ContextHandle right)
00140 {
00141 return !left.Equals(right);
00142 }
00143
00144 #endregion
00145
00146 #endregion
00147
00148 #region IComparable<ContextHandle> Members
00149
00156 public int CompareTo(ContextHandle other)
00157 {
00158 unsafe { return (int)((int*)other.handle.ToPointer() - (int*)this.handle.ToPointer()); }
00159 }
00160
00161 #endregion
00162
00163 #region IEquatable<ContextHandle> Members
00164
00170 public bool Equals(ContextHandle other)
00171 {
00172 return Handle == other.Handle;
00173 }
00174
00175 #endregion
00176 }
00177 }