mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-09 00:13:20 +02:00
2003-10-27 Daniel Kornhauser Eisenberg <dkor@alum.mit.edu>
* glib/ListBase.cs : Added Indexer to allow [] based adressing * glib/List.cs : Added DllImport for Indexer * glib/SList.cs : Added DllImport for Indexer svn path=/trunk/gtk-sharp/; revision=19420
This commit is contained in:
parent
9925ac1e6f
commit
737717e5a5
@ -76,6 +76,15 @@ namespace GLib {
|
|||||||
return g_list_prepend (list, raw);
|
return g_list_prepend (list, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
|
static extern IntPtr g_list_nth_data (IntPtr l, uint n);
|
||||||
|
|
||||||
|
internal override IntPtr NthData (uint n)
|
||||||
|
{
|
||||||
|
return g_list_nth_data (Handle, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List (IntPtr raw) : base (raw)
|
public List (IntPtr raw) : base (raw)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace GLib {
|
|||||||
private bool managed = false;
|
private bool managed = false;
|
||||||
protected System.Type element_type = null;
|
protected System.Type element_type = null;
|
||||||
|
|
||||||
|
abstract internal IntPtr NthData (uint index);
|
||||||
abstract internal IntPtr GetData (IntPtr current);
|
abstract internal IntPtr GetData (IntPtr current);
|
||||||
abstract internal IntPtr Next (IntPtr current);
|
abstract internal IntPtr Next (IntPtr current);
|
||||||
abstract internal int Length (IntPtr list);
|
abstract internal int Length (IntPtr list);
|
||||||
@ -106,6 +107,15 @@ namespace GLib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object this [int index] {
|
||||||
|
get {
|
||||||
|
IntPtr data = NthData ((uint) index);
|
||||||
|
object ret = null;
|
||||||
|
ret = DataMarshal (data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Synchronization could be tricky here. Hmm.
|
// Synchronization could be tricky here. Hmm.
|
||||||
public bool IsSynchronized {
|
public bool IsSynchronized {
|
||||||
get { return false; }
|
get { return false; }
|
||||||
@ -125,6 +135,26 @@ namespace GLib {
|
|||||||
orig.CopyTo (array, index);
|
orig.CopyTo (array, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal object DataMarshal (IntPtr data)
|
||||||
|
{
|
||||||
|
object ret = null;
|
||||||
|
if (element_type != null) {
|
||||||
|
if (element_type == typeof (string))
|
||||||
|
ret = Marshal.PtrToStringAnsi (data);
|
||||||
|
else if (element_type == typeof (int))
|
||||||
|
ret = (int) data;
|
||||||
|
else if (element_type.IsValueType)
|
||||||
|
ret = Marshal.PtrToStructure (data, element_type);
|
||||||
|
else
|
||||||
|
ret = Activator.CreateInstance (element_type, new object[] {data});
|
||||||
|
|
||||||
|
} else if (Object.IsObject (data))
|
||||||
|
ret = GLib.Object.GetObject (data, false);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private class ListEnumerator : IEnumerator
|
private class ListEnumerator : IEnumerator
|
||||||
{
|
{
|
||||||
private IntPtr current = IntPtr.Zero;
|
private IntPtr current = IntPtr.Zero;
|
||||||
@ -139,20 +169,7 @@ namespace GLib {
|
|||||||
get {
|
get {
|
||||||
IntPtr data = list.GetData (current);
|
IntPtr data = list.GetData (current);
|
||||||
object ret = null;
|
object ret = null;
|
||||||
if (list.element_type != null)
|
ret = list.DataMarshal (data);
|
||||||
{
|
|
||||||
if (list.element_type == typeof (string))
|
|
||||||
ret = Marshal.PtrToStringAnsi (data);
|
|
||||||
else if (list.element_type == typeof (int))
|
|
||||||
ret = (int) data;
|
|
||||||
else if (list.element_type.IsValueType)
|
|
||||||
ret = Marshal.PtrToStructure (data, list.element_type);
|
|
||||||
else
|
|
||||||
ret = Activator.CreateInstance (list.element_type, new object[] {data});
|
|
||||||
}
|
|
||||||
else if (Object.IsObject (data))
|
|
||||||
ret = GLib.Object.GetObject (data, false);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,15 @@ namespace GLib {
|
|||||||
return g_slist_prepend (list, raw);
|
return g_slist_prepend (list, raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0-0.dll")]
|
||||||
|
static extern IntPtr g_slist_nth_data (IntPtr l, uint n);
|
||||||
|
|
||||||
|
internal override IntPtr NthData (uint n)
|
||||||
|
{
|
||||||
|
return g_slist_nth_data (Handle, n);
|
||||||
|
}
|
||||||
|
|
||||||
public SList (IntPtr raw) : base (raw)
|
public SList (IntPtr raw) : base (raw)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user