2001-09-27 17:17:33 +00:00
|
|
|
// GLib.Value.cs - GLib Value class implementation
|
2001-09-19 11:37:15 +00:00
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
|
|
|
namespace GLib {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Value Class
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
|
|
|
/// An arbitrary data type similar to a CORBA Any which is used
|
|
|
|
/// to get and set properties on Objects.
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
public class Value {
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
IntPtr _val;
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
// We use g_malloc0 and g_free to put the GValue on the
|
|
|
|
// heap to avoid some marshalling pain.
|
|
|
|
[DllImport("glib-1.3.dll")]
|
|
|
|
static extern IntPtr g_malloc0 (long n_bytes);
|
|
|
|
[DllImport("glib-1.3.dll")]
|
|
|
|
static extern void g_free (IntPtr mem);
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
[DllImport("gobject-1.3.dll")]
|
|
|
|
static extern void g_value_init (IntPtr val,
|
|
|
|
TypeFundamentals type);
|
2001-09-19 11:37:15 +00:00
|
|
|
/// <summary>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// Value Constructor
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// Constructs a Value from a spectified string.
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
[DllImport("gobject-1.3.dll")]
|
|
|
|
static extern void g_value_set_string (IntPtr val,
|
2001-09-19 11:37:15 +00:00
|
|
|
String data);
|
2001-09-27 17:17:33 +00:00
|
|
|
[DllImport("gobject-1.3.dll")]
|
|
|
|
static extern void g_value_set_boolean (IntPtr val,
|
|
|
|
bool data);
|
|
|
|
|
|
|
|
public Value (bool val)
|
|
|
|
{
|
|
|
|
_val = g_malloc0 (5 * IntPtr.Size);
|
|
|
|
g_value_init (_val, TypeFundamentals.TypeBoolean);
|
|
|
|
g_value_set_boolean (_val, val);
|
|
|
|
}
|
2001-09-19 11:37:15 +00:00
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
public Value (String str)
|
2001-09-19 11:37:15 +00:00
|
|
|
{
|
2001-09-27 17:17:33 +00:00
|
|
|
_val = g_malloc0 (5 * IntPtr.Size);
|
|
|
|
g_value_init (_val, TypeFundamentals.TypeString);
|
|
|
|
g_value_set_string (_val, str);
|
2001-09-19 11:37:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// GetString Method
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// Extracts a string from a Value. Note, this method
|
|
|
|
/// will produce an exception if the Value does not hold a
|
2001-09-19 11:37:15 +00:00
|
|
|
/// string value.
|
|
|
|
/// </remarks>
|
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
[DllImport("gobject-1.3.dll")]
|
|
|
|
static extern String g_value_get_string (IntPtr val);
|
2001-09-19 11:37:15 +00:00
|
|
|
|
|
|
|
public String GetString ()
|
|
|
|
{
|
|
|
|
// FIXME: Insert an appropriate exception here if
|
|
|
|
// _val.type indicates an error.
|
2001-09-27 17:17:33 +00:00
|
|
|
return g_value_get_string (_val);
|
2001-09-19 11:37:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// RawValue Property
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <remarks>
|
2001-09-27 17:17:33 +00:00
|
|
|
/// Read only. Accesses a pointer to the Raw GValue.
|
2001-09-19 11:37:15 +00:00
|
|
|
/// </remarks>
|
|
|
|
|
2001-09-27 17:17:33 +00:00
|
|
|
public IntPtr RawValue {
|
2001-09-19 11:37:15 +00:00
|
|
|
get {
|
|
|
|
return _val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|