#region --- License --- /* Licensed under the MIT/X11 license. * Copyright (c) 2006-2008 the OpenTK Team. * This notice may not be removed from any source distribution. * See license.txt for licensing detailed licensing details. */ #endregion using System; using System.Collections.Generic; using System.Text; namespace OpenTK { /// /// Represents a handle to an OpenGL or OpenAL context. /// public struct ContextHandle : IComparable, IEquatable { #region Fields IntPtr handle; /// /// Gets a System.IntPtr that represents the handle of this ContextHandle. /// public IntPtr Handle { get { return handle; } } /// A read-only field that represents a handle that has been initialized to zero. public static readonly ContextHandle Zero = new ContextHandle(IntPtr.Zero); #endregion #region Constructors /// /// Constructs a new instance with the specified handle. /// /// A System.IntPtr containing the value for this instance. public ContextHandle(IntPtr h) { handle = h; } #endregion #region Public Members #region ToString /// /// Converts this instance to its equivalent string representation. /// /// A System.String that contains the string representation of this instance. public override string ToString() { return Handle.ToString(); } #endregion #region Equals /// /// Compares this instance to the specified object. /// /// The System.Object to compare to. /// True if obj is a ContextHandle that is equal to this instance; false otherwise. public override bool Equals(object obj) { if (obj is ContextHandle) return this.Equals((ContextHandle)obj); return false; } #endregion #region GetHashCode /// /// Returns the hash code for this instance. /// /// A System.Int32 with the hash code of this instance. public override int GetHashCode() { return Handle.GetHashCode(); } #endregion #region public static explicit operator IntPtr(ContextHandle c) /// /// Converts the specified ContextHandle to the equivalent IntPtr. /// /// The ContextHandle to convert. /// A System.IntPtr equivalent to the specified ContextHandle. public static explicit operator IntPtr(ContextHandle c) { return c != ContextHandle.Zero ? c.handle : IntPtr.Zero; } #endregion #region public static explicit operator ContextHandle(IntPtr p) /// /// Converts the specified IntPtr to the equivalent ContextHandle. /// /// The System.IntPtr to convert. /// A ContextHandle equivalent to the specified IntPtr. public static explicit operator ContextHandle(IntPtr p) { return new ContextHandle(p); } #endregion #region public static bool operator ==(ContextHandle left, ContextHandle right) /// /// Compares two ContextHandles for equality. /// /// The ContextHandle to compare. /// The ContextHandle to compare to. /// True if left is equal to right; false otherwise. public static bool operator ==(ContextHandle left, ContextHandle right) { return left.Equals(right); } #endregion #region public static bool operator !=(ContextHandle left, ContextHandle right) /// /// Compares two ContextHandles for inequality. /// /// The ContextHandle to compare. /// The ContextHandle to compare to. /// True if left is not equal to right; false otherwise. public static bool operator !=(ContextHandle left, ContextHandle right) { return !left.Equals(right); } #endregion #endregion #region IComparable Members /// /// Compares the numerical value of this instance to the specified ContextHandle and /// returns a value indicating their relative order. /// /// The ContextHandle to compare to. /// Less than 0, if this instance is less than other; 0 if both are equal; Greater than 0 if other is greater than this instance. public int CompareTo(ContextHandle other) { unsafe { return (int)((int*)other.handle.ToPointer() - (int*)this.handle.ToPointer()); } } #endregion #region IEquatable Members /// /// Compares this instance to the specified ContextHandle for equality. /// /// The ContextHandle to compare to. /// True if this instance is equal to other; false otherwise. public bool Equals(ContextHandle other) { return Handle == other.Handle; } #endregion } }