#region License // // The Open Toolkit Library License // // Copyright (c) 2006 - 2009 the Open Toolkit library. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // the Software, and to permit persons to whom the Software is furnished to do // so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // #endregion #if EXPERIMENTAL using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace OpenTK.Compute { #region struct Handle struct Handle : IEquatable>, IComparable> { #region Fields IntPtr handle; /// /// Gets a System.IntPtr that represents the handle of this ContextHandle. /// public IntPtr Value { get { return handle; } } /// A read-only field that represents a handle that has been initialized to zero. public static readonly Handle Zero = new Handle(IntPtr.Zero); #endregion #region Constructors /// /// Constructs a new instance with the specified handle. /// /// A System.IntPtr containing the value for this instance. public Handle(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 Value.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 Handle) return this.Equals((Handle)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 Value.GetHashCode(); } #endregion #region public static explicit operator IntPtr(Handle 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(Handle c) { return c != Handle.Zero ? c.Value : IntPtr.Zero; } #endregion #region public static explicit operator Handle(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 Handle(IntPtr p) { return new Handle(p); } #endregion /// /// Compares two instances for equality. /// /// The instance to compare. /// The instance to compare to. /// True if left is equal to right; false otherwise. public static bool operator ==(Handle left, Handle right) { return left.Equals(right); } /// /// Compares two instances for inequality. /// /// The instance to compare. /// The instance to compare to. /// True if left is not equal to right; false otherwise. public static bool operator !=(Handle left, Handle right) { return !left.Equals(right); } #endregion #region IComparable> Members /// /// Compares the numerical value of this instance to other and returns a value indicating their relative order. /// /// The instance 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(Handle other) { unsafe { return Value.ToInt64().CompareTo(other.Value.ToInt64()); } } #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(Handle other) { return Value == other.Value; } #endregion } #endregion } #endif