Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #region --- License --- |
| 2 | /* Licensed under the MIT/X11 license. |
||
| 3 | * Copyright (c) 2006-2008 the OpenTK Team. |
||
| 4 | * This notice may not be removed from any source distribution. |
||
| 5 | * See license.txt for licensing detailed licensing details. |
||
| 6 | */ |
||
| 7 | #endregion |
||
| 8 | |||
| 9 | using System; |
||
| 10 | using System.Collections.Generic; |
||
| 11 | using System.Text; |
||
| 12 | |||
| 13 | namespace OpenTK |
||
| 14 | { |
||
| 15 | /// <summary> |
||
| 16 | /// Represents a handle to an OpenGL or OpenAL context. |
||
| 17 | /// </summary> |
||
| 18 | public struct ContextHandle : IComparable<ContextHandle>, IEquatable<ContextHandle> |
||
| 19 | { |
||
| 20 | #region Fields |
||
| 21 | |||
| 22 | IntPtr handle; |
||
| 23 | |||
| 24 | /// <summary> |
||
| 25 | /// Gets a System.IntPtr that represents the handle of this ContextHandle. |
||
| 26 | /// </summary> |
||
| 27 | public IntPtr Handle { get { return handle; } } |
||
| 28 | |||
| 29 | /// <summary>A read-only field that represents a handle that has been initialized to zero.</summary> |
||
| 30 | public static readonly ContextHandle Zero = new ContextHandle(IntPtr.Zero); |
||
| 31 | |||
| 32 | #endregion |
||
| 33 | |||
| 34 | #region Constructors |
||
| 35 | |||
| 36 | /// <summary> |
||
| 37 | /// Constructs a new instance with the specified handle. |
||
| 38 | /// </summary> |
||
| 39 | /// <param name="h">A System.IntPtr containing the value for this instance.</param> |
||
| 40 | public ContextHandle(IntPtr h) { handle = h; } |
||
| 41 | |||
| 42 | #endregion |
||
| 43 | |||
| 44 | #region Public Members |
||
| 45 | |||
| 46 | #region ToString |
||
| 47 | |||
| 48 | /// <summary> |
||
| 49 | /// Converts this instance to its equivalent string representation. |
||
| 50 | /// </summary> |
||
| 51 | /// <returns>A System.String that contains the string representation of this instance.</returns> |
||
| 52 | public override string ToString() |
||
| 53 | { |
||
| 54 | return Handle.ToString(); |
||
| 55 | } |
||
| 56 | |||
| 57 | #endregion |
||
| 58 | |||
| 59 | #region Equals |
||
| 60 | |||
| 61 | /// <summary> |
||
| 62 | /// Compares this instance to the specified object. |
||
| 63 | /// </summary> |
||
| 64 | /// <param name="obj">The System.Object to compare to.</param> |
||
| 65 | /// <returns>True if obj is a ContextHandle that is equal to this instance; false otherwise.</returns> |
||
| 66 | public override bool Equals(object obj) |
||
| 67 | { |
||
| 68 | if (obj is ContextHandle) |
||
| 69 | return this.Equals((ContextHandle)obj); |
||
| 70 | return false; |
||
| 71 | } |
||
| 72 | |||
| 73 | #endregion |
||
| 74 | |||
| 75 | #region GetHashCode |
||
| 76 | |||
| 77 | /// <summary> |
||
| 78 | /// Returns the hash code for this instance. |
||
| 79 | /// </summary> |
||
| 80 | /// <returns>A System.Int32 with the hash code of this instance.</returns> |
||
| 81 | public override int GetHashCode() |
||
| 82 | { |
||
| 83 | return Handle.GetHashCode(); |
||
| 84 | } |
||
| 85 | |||
| 86 | #endregion |
||
| 87 | |||
| 88 | #region public static explicit operator IntPtr(ContextHandle c) |
||
| 89 | |||
| 90 | /// <summary> |
||
| 91 | /// Converts the specified ContextHandle to the equivalent IntPtr. |
||
| 92 | /// </summary> |
||
| 93 | /// <param name="c">The ContextHandle to convert.</param> |
||
| 94 | /// <returns>A System.IntPtr equivalent to the specified ContextHandle.</returns> |
||
| 95 | public static explicit operator IntPtr(ContextHandle c) |
||
| 96 | { |
||
| 97 | return c != ContextHandle.Zero ? c.handle : IntPtr.Zero; |
||
| 98 | } |
||
| 99 | |||
| 100 | #endregion |
||
| 101 | |||
| 102 | #region public static explicit operator ContextHandle(IntPtr p) |
||
| 103 | |||
| 104 | /// <summary> |
||
| 105 | /// Converts the specified IntPtr to the equivalent ContextHandle. |
||
| 106 | /// </summary> |
||
| 107 | /// <param name="p">The System.IntPtr to convert.</param> |
||
| 108 | /// <returns>A ContextHandle equivalent to the specified IntPtr.</returns> |
||
| 109 | public static explicit operator ContextHandle(IntPtr p) |
||
| 110 | { |
||
| 111 | return new ContextHandle(p); |
||
| 112 | } |
||
| 113 | |||
| 114 | #endregion |
||
| 115 | |||
| 116 | #region public static bool operator ==(ContextHandle left, ContextHandle right) |
||
| 117 | |||
| 118 | /// <summary> |
||
| 119 | /// Compares two ContextHandles for equality. |
||
| 120 | /// </summary> |
||
| 121 | /// <param name="left">The ContextHandle to compare.</param> |
||
| 122 | /// <param name="right">The ContextHandle to compare to.</param> |
||
| 123 | /// <returns>True if left is equal to right; false otherwise.</returns> |
||
| 124 | public static bool operator ==(ContextHandle left, ContextHandle right) |
||
| 125 | { |
||
| 126 | return left.Equals(right); |
||
| 127 | } |
||
| 128 | |||
| 129 | #endregion |
||
| 130 | |||
| 131 | #region public static bool operator !=(ContextHandle left, ContextHandle right) |
||
| 132 | |||
| 133 | /// <summary> |
||
| 134 | /// Compares two ContextHandles for inequality. |
||
| 135 | /// </summary> |
||
| 136 | /// <param name="left">The ContextHandle to compare.</param> |
||
| 137 | /// <param name="right">The ContextHandle to compare to.</param> |
||
| 138 | /// <returns>True if left is not equal to right; false otherwise.</returns> |
||
| 139 | public static bool operator !=(ContextHandle left, ContextHandle right) |
||
| 140 | { |
||
| 141 | return !left.Equals(right); |
||
| 142 | } |
||
| 143 | |||
| 144 | #endregion |
||
| 145 | |||
| 146 | #endregion |
||
| 147 | |||
| 148 | #region IComparable<ContextHandle> Members |
||
| 149 | |||
| 150 | /// <summary> |
||
| 151 | /// Compares the numerical value of this instance to the specified ContextHandle and |
||
| 152 | /// returns a value indicating their relative order. |
||
| 153 | /// </summary> |
||
| 154 | /// <param name="other">The ContextHandle to compare to.</param> |
||
| 155 | /// <returns>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.</returns> |
||
| 156 | public int CompareTo(ContextHandle other) |
||
| 157 | { |
||
| 158 | unsafe { return (int)((int*)other.handle.ToPointer() - (int*)this.handle.ToPointer()); } |
||
| 159 | } |
||
| 160 | |||
| 161 | #endregion |
||
| 162 | |||
| 163 | #region IEquatable<ContextHandle> Members |
||
| 164 | |||
| 165 | /// <summary> |
||
| 166 | /// Compares this instance to the specified ContextHandle for equality. |
||
| 167 | /// </summary> |
||
| 168 | /// <param name="other">The ContextHandle to compare to.</param> |
||
| 169 | /// <returns>True if this instance is equal to other; false otherwise.</returns> |
||
| 170 | public bool Equals(ContextHandle other) |
||
| 171 | { |
||
| 172 | return Handle == other.Handle; |
||
| 173 | } |
||
| 174 | |||
| 175 | #endregion |
||
| 176 | } |
||
| 177 | } |