2001-08-06 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Tue, 7 Aug 2001 00:11:48 +0000 (00:11 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Tue, 7 Aug 2001 00:11:48 +0000 (00:11 -0000)
* IntPtr.cs: Added and Completed implementation.

svn path=/trunk/mcs/; revision=419

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/IntPtr.cs

index 1f5e5850c2a50a84e7089f9ad5d4b9ce465842b0..adc8f2c7c40c0815559772bfbc40d92bc8af8e52 100644 (file)
@@ -1,6 +1,6 @@
 2001-08-06  Miguel de Icaza  <miguel@ximian.com>
 
-       * IntPtr.cs: Added.
+       * IntPtr.cs: Added and Completed implementation.
 
        * Uri.cs: Add a note.
 
index e06ba13832e32e3019b92cf470e910945d509456..47c6e245351db810cd7db42bb325e6a3706b38f0 100644 (file)
@@ -15,28 +15,33 @@ namespace System {
        
        public struct IntPtr : ISerializable {
 
-               public int value;
+               unsafe public void *value;
 
-               public static int Zero = 0;
+               public static IntPtr Zero;
+
+               unsafe static IntPtr ()
+               {
+                       Zero.value = (void *) 0;
+               }
                
-               public IntPtr (int i32)
+               unsafe public IntPtr (int i32)
                {
-                       value = i32;
+                       value = (void *) i32;
                }
 
-               public IntPtr (long i64)
+               unsafe public IntPtr (long i64)
                {
-                       value = (int) i64;
+                       value = (void *) i64;
                }
 
                unsafe public IntPtr (void *ptr)
                {
-                       value = (int) ptr;
+                       value = ptr;
                }
 
                unsafe public static int Size {
                        get {
-                               return sizeof (int);
+                               return sizeof (void *);
                        }
                }
 
@@ -44,5 +49,81 @@ namespace System {
                {
                        // FIXME: Implement me.
                }
+
+               unsafe public override bool Equals (object o)
+               {
+                       if (!(o is System.IntPtr))
+                               return false;
+
+                       return ((IntPtr) o).value == value;
+               }
+
+               unsafe public override int GetHashCode ()
+               {
+                       return (int) value;
+               }
+
+               unsafe public int ToInt32 ()
+               {
+                       return (int) value;
+               }
+
+               unsafe public long ToInt64 ()
+               {
+                       return (long) value;
+               }
+
+               unsafe public void *ToPointer ()
+               {
+                       return value;
+               }
+
+               unsafe override public string ToString ()
+               {
+                       if (Size == 4)
+                               return ((int) value).ToString ();
+                       else
+                               return ((long) value).ToString ();
+               }
+
+               unsafe public static bool operator == (IntPtr a, IntPtr b)
+               {
+                       return (a.value == b.value);
+               }
+
+               unsafe public static bool operator != (IntPtr a, IntPtr b)
+               {
+                       return (a.value != b.value);
+               }
+
+               unsafe public static explicit operator IntPtr (int value)
+               {
+                       return new IntPtr (value);
+               }
+
+               unsafe public static explicit operator IntPtr (long value)
+               {
+                       return new IntPtr (value);
+               }
+               
+               unsafe public static explicit operator IntPtr (void *value)
+               {
+                       return new IntPtr (value);
+               }
+
+               unsafe public static explicit operator int (IntPtr value)
+               {
+                       return (int) value.value;
+               }
+
+               unsafe public static explicit operator long (IntPtr value)
+               {
+                       return (long) value.value;
+               }
+
+               unsafe public static explicit operator void * (IntPtr value)
+               {
+                       return value.value;
+               }
        }
 }