2002-04-19 Mike Kestner <mkestner@speakeasy.net>

* glib/SList.cs : A more sane approach.
	* glib/Value.cs : Marshal strings directly with pinvoke

svn path=/trunk/gtk-sharp/; revision=3913
This commit is contained in:
Mike Kestner 2002-04-19 16:17:47 +00:00
parent e966ffb7f7
commit b5c0054787
3 changed files with 23 additions and 287 deletions

View file

@ -1,3 +1,8 @@
2002-04-19 Mike Kestner <mkestner@speakeasy.net>
* glib/SList.cs : A more sane approach.
* glib/Value.cs : Marshal strings directly with pinvoke
2002-04-18 Joe Shaw <joe@assbarn.com> 2002-04-18 Joe Shaw <joe@assbarn.com>
* */makefile: Allow a different MCS to be passed in on the make * */makefile: Allow a different MCS to be passed in on the make

View file

@ -18,297 +18,30 @@ namespace GLib {
/// Wrapper class for GSList. /// Wrapper class for GSList.
/// </remarks> /// </remarks>
public class SList : IList { public class SList : ArrayList {
// Private class and instance members
IntPtr _list;
int rev_cnt;
/// <summary>
/// Object Constructor
/// </summary>
///
/// <remarks>
/// Dummy constructor needed for derived classes.
/// </remarks>
public SList ()
{
_list = IntPtr.Zero;
rev_cnt = 0;
}
/// <summary> /// <summary>
/// Handle Property /// Handle Property
/// </summary> /// </summary>
/// ///
/// <remarks> /// <remarks>
/// The raw GSList reference. There should be no need to /// A raw GSList reference for marshaling situations.
/// use this other than marshaling situations.
/// </remarks> /// </remarks>
[DllImport("gobject-2.0")]
static extern IntPtr g_slist_append(IntPtr l, IntPtr d);
public IntPtr Handle { public IntPtr Handle {
get { get {
return _list; IntPtr l = IntPtr.Zero;
} foreach (object o in this) {
} IntPtr data = IntPtr.Zero;
if (o is GLib.Object)
// ------------------------------ l = g_slist_append (l, ((GLib.Object)o).Handle);
// ICollection Interface Implementation else
// ------------------------------ throw new Exception();
/// <summary>
/// Count Property
/// </summary>
///
/// <remarks>
/// The number of elements in the SList.
/// </remarks>
[DllImport("glib-2.0", CallingConvention=CallingConvention.Cdecl)]
static extern int g_slist_length(IntPtr raw);
public int Count {
get {
return g_slist_length(_list);
}
}
/// <summary>
/// IsSynchronized Property
/// </summary>
///
/// <remarks>
/// Returns false. GSLists are not threadsafe.
/// </remarks>
public bool IsSynchronized {
get {
return false;
}
}
/// <summary>
/// SyncRoot Property
/// </summary>
///
/// <remarks>
/// Throws not implemented exception. GSLists are not
/// thread safe.
/// </remarks>
public object SyncRoot {
get {
throw new NotImplementedException();
}
}
/// <summary>
/// CopyTo Method
/// </summary>
///
/// <remarks>
/// Copies the list to an Array.
/// </remarks>
public void CopyTo(Array target, int index)
{
foreach (IntPtr item in this) {
target.SetValue(item, index++);
}
}
// ------------------------------
// IEnumerable Interface Implementation
// ------------------------------
public IEnumerator GetEnumerator()
{
return new SListEnumerator(this);
}
// ------------------------------
// IList Interface Implementation
// ------------------------------
/// <summary>
/// IsFixedSize Property
/// </summary>
///
/// <remarks>
/// Returns false. Items can be added and removed from
/// an SList.
/// </remarks>
public bool IsFixedSize {
get {
return false;
}
}
/// <summary>
/// IsReadOnly Property
/// </summary>
///
/// <remarks>
/// Returns false. Items of an SList can be modified.
/// </remarks>
public bool IsReadOnly {
get {
return false;
}
}
/// <summary>
/// Item Property
/// </summary>
///
/// <remarks>
/// Indexer to access members of the SList.
/// </remarks>
[DllImport("glib-2.0", CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr g_slist_nth_data(IntPtr raw, int index);
public object this[int index] {
get {
return g_slist_nth_data(_list, index);
}
set {
// FIXME: Set a data element.
rev_cnt++;
}
}
// FIXME: Just a stub
public int Add(object o)
{
rev_cnt++;
return 0;
}
// FIXME: Just a stub
public void Clear()
{
rev_cnt++;
}
// FIXME: Just a stub
public bool Contains(object o)
{
return false;
}
// FIXME: Just a stub
public int IndexOf(object o)
{
return 0;
}
// FIXME: Just a stub
public void Insert(int index, object o)
{
rev_cnt++;
}
// FIXME: Just a stub
public void Remove(object o)
{
rev_cnt++;
}
// FIXME: Just a stub
public void RemoveAt(int index)
{
rev_cnt++;
}
// --------------
// object methods
// --------------
/// <summary>
/// Equals Method
/// </summary>
///
/// <remarks>
/// Checks equivalence of two SLists.
/// </remarks>
public override bool Equals (object o)
{
if (!(o is SList))
return false;
return (Handle == ((SList) o).Handle);
}
/// <summary>
/// GetHashCode Method
/// </summary>
///
/// <remarks>
/// Calculates a hashing value.
/// </remarks>
public override int GetHashCode ()
{
return Handle.GetHashCode ();
}
// Internal enumerator class
public class SListEnumerator : IEnumerator {
IntPtr _cursor;
int i_rev;
SList _list;
bool virgin;
public SListEnumerator (SList list)
{
_list = list;
i_rev = list.rev_cnt;
virgin = true;
}
public object Current {
get {
if (virgin || (i_rev != _list.rev_cnt)) {
throw new InvalidOperationException();
}
if (_cursor == IntPtr.Zero) {
return null;
}
return Marshal.ReadIntPtr(_cursor);
} }
} return l;
public bool MoveNext()
{
if (i_rev != _list.rev_cnt) {
throw new InvalidOperationException();
}
if (virgin) {
_cursor = _list.Handle;
} else if (_cursor != IntPtr.Zero) {
_cursor = Marshal.ReadIntPtr(_cursor, IntPtr.Size);
}
return (_cursor != IntPtr.Zero);
}
public void Reset()
{
if (i_rev != _list.rev_cnt) {
throw new InvalidOperationException();
}
virgin = true;
} }
} }

View file

@ -113,12 +113,11 @@ namespace GLib {
[DllImport("gobject-2.0", [DllImport("gobject-2.0",
CallingConvention=CallingConvention.Cdecl)] CallingConvention=CallingConvention.Cdecl)]
static extern void g_value_set_string (IntPtr val, static extern void g_value_set_string (IntPtr val,
IntPtr data); string data);
public Value (String val) : this () public Value (string val) : this ()
{ {
g_value_init (_val, TypeFundamentals.TypeString); g_value_init (_val, TypeFundamentals.TypeString);
g_value_set_string (_val, g_value_set_string (_val, val);
Marshal.StringToHGlobalAnsi (val));
} }
/// <summary> /// <summary>
@ -193,14 +192,13 @@ namespace GLib {
[DllImport("gobject-2.0", [DllImport("gobject-2.0",
CallingConvention=CallingConvention.Cdecl)] CallingConvention=CallingConvention.Cdecl)]
static extern IntPtr g_value_get_string (IntPtr val); static extern string g_value_get_string (IntPtr val);
public static explicit operator String (Value val) public static explicit operator String (Value val)
{ {
// FIXME: Insert an appropriate exception here if // FIXME: Insert an appropriate exception here if
// _val.type indicates an error. // _val.type indicates an error.
return Marshal.PtrToStringAnsi ( return g_value_get_string (val._val);
g_value_get_string (val._val));
} }
/// <summary> /// <summary>