2001-09-28 Mike Kestner <mkestner@speakeasy.net>
* glib/Value.cs (~Value): New destructor to release g_malloc'd space. (default ctor): New default ctor just mallocs without init. (String ctor): call default (bool ctor): call default (Init): New post construct initializer. (String exp cast): Replaces ToString method. (bool exp cast): New for bool extraction. (MarshalAs): Renamed prop was RawValue. svn path=/trunk/gtk-sharp/; revision=1017
This commit is contained in:
parent
4a2fa05bee
commit
f193cf3efe
2 changed files with 101 additions and 28 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2001-09-28 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
|
* glib/Value.cs (~Value): New destructor to release g_malloc'd space.
|
||||||
|
(default ctor): New default ctor just mallocs without init.
|
||||||
|
(String ctor): call default
|
||||||
|
(bool ctor): call default
|
||||||
|
(Init): New post construct initializer.
|
||||||
|
(String exp cast): Replaces ToString method.
|
||||||
|
(bool exp cast): New for bool extraction.
|
||||||
|
(MarshalAs): Renamed prop was RawValue.
|
||||||
|
|
||||||
2001-09-27 Mike Kestner <mkestner@speakeasy.net>
|
2001-09-27 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
* glib/Object.cs : Docs for everything. Made Objects hash private.
|
* glib/Object.cs : Docs for everything. Made Objects hash private.
|
||||||
|
|
118
glib/Value.cs
118
glib/Value.cs
|
@ -22,47 +22,109 @@ namespace GLib {
|
||||||
|
|
||||||
IntPtr _val;
|
IntPtr _val;
|
||||||
|
|
||||||
// We use g_malloc0 and g_free to put the GValue on the
|
|
||||||
// heap to avoid some marshalling pain.
|
// Destructor is required since we are allocating unmananged
|
||||||
[DllImport("glib-1.3.dll")]
|
// heap resources.
|
||||||
static extern IntPtr g_malloc0 (long n_bytes);
|
|
||||||
[DllImport("glib-1.3.dll")]
|
[DllImport("glib-1.3.dll")]
|
||||||
static extern void g_free (IntPtr mem);
|
static extern void g_free (IntPtr mem);
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
~Value ()
|
||||||
static extern void g_value_init (IntPtr val,
|
{
|
||||||
TypeFundamentals type);
|
g_free (_val);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Value Constructor
|
/// Value Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Constructs a Value from a spectified string.
|
/// Creates an uninitialized Value on the unmanaged heap.
|
||||||
|
/// Use the Init method prior to attempting to assign a
|
||||||
|
/// value to it.
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[DllImport("glib-1.3.dll")]
|
||||||
|
static extern IntPtr g_malloc0 (long n_bytes);
|
||||||
|
|
||||||
|
public Value ()
|
||||||
|
{
|
||||||
|
_val = g_malloc0 (5 * IntPtr.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value Constructor
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <remarks>
|
||||||
|
/// Constructs a Value from a specified boolean.
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[DllImport("gobject-1.3.dll")]
|
||||||
|
static extern void g_value_set_boolean (IntPtr val,
|
||||||
|
bool data);
|
||||||
|
public Value (bool val) : this ()
|
||||||
|
{
|
||||||
|
g_value_init (_val, TypeFundamentals.TypeBoolean);
|
||||||
|
g_value_set_boolean (_val, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value Constructor
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <remarks>
|
||||||
|
/// Constructs a Value from a specified string.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll")]
|
||||||
static extern void g_value_set_string (IntPtr val,
|
static extern void g_value_set_string (IntPtr val,
|
||||||
String data);
|
String data);
|
||||||
[DllImport("gobject-1.3.dll")]
|
public Value (String val) : this ()
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value (String str)
|
|
||||||
{
|
|
||||||
_val = g_malloc0 (5 * IntPtr.Size);
|
|
||||||
g_value_init (_val, TypeFundamentals.TypeString);
|
g_value_init (_val, TypeFundamentals.TypeString);
|
||||||
g_value_set_string (_val, str);
|
g_value_set_string (_val, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// GetString Method
|
/// Init Method
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <remarks>
|
||||||
|
/// Prepares a raw value to hold a specified type.
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[DllImport("gobject-1.3.dll")]
|
||||||
|
static extern void g_value_init (IntPtr val,
|
||||||
|
TypeFundamentals type);
|
||||||
|
|
||||||
|
public void Init (TypeFundamentals type)
|
||||||
|
{
|
||||||
|
g_value_init (_val, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value to Boolean Conversion
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <remarks>
|
||||||
|
/// Extracts a bool from a Value. Note, this method
|
||||||
|
/// will produce an exception if the Value does not hold a
|
||||||
|
/// boolean value.
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
[DllImport("gobject-1.3.dll")]
|
||||||
|
static extern bool g_value_get_boolean (IntPtr val);
|
||||||
|
|
||||||
|
public static explicit operator bool (Value val)
|
||||||
|
{
|
||||||
|
// FIXME: Insert an appropriate exception here if
|
||||||
|
// _val.type indicates an error.
|
||||||
|
return g_value_get_boolean (val._val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Value to String Conversion
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
@ -74,22 +136,22 @@ namespace GLib {
|
||||||
[DllImport("gobject-1.3.dll")]
|
[DllImport("gobject-1.3.dll")]
|
||||||
static extern String g_value_get_string (IntPtr val);
|
static extern String g_value_get_string (IntPtr val);
|
||||||
|
|
||||||
public String GetString ()
|
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 g_value_get_string (_val);
|
return g_value_get_string (val._val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// RawValue Property
|
/// MarshalAs Property
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Read only. Accesses a pointer to the Raw GValue.
|
/// Read only. Accesses a pointer to the raw GValue.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
|
||||||
public IntPtr RawValue {
|
public IntPtr MarshalAs {
|
||||||
get {
|
get {
|
||||||
return _val;
|
return _val;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue