Implement Ownable Generatable type.

* cairo/Context.cs: add ctor (IntPtr, bool owned)
* cairo/cairo-api.xml: expose cairo_t as new ownable symbol type
* generator/HandleBase.cs: implement IOwnable
* generator/IOwnable.cs: new interface for wrapping ownable types
* generator/Makefile.am: add new files to build
* generator/OwnableGen.cs: SimpleBase subclass to expose IOwnable
* generator/Parameters.cs: use IOwnable.FromNative instead of HandleBase
* generator/Parser.cs: parse ownable symbol type
* generator/ReturnValue.cs: use IOwnable.FromNative instead of HandleBase
This commit is contained in:
Mike Kestner 2011-04-21 18:04:47 -05:00
parent 6647c2609c
commit 0fc5126228
9 changed files with 91 additions and 10 deletions

View File

@ -184,9 +184,11 @@ namespace Cairo {
state = NativeMethods.cairo_create (surface.Handle);
}
public Context (IntPtr state)
public Context (IntPtr state) : this (state, true) {}
public Context (IntPtr state, bool owned)
{
this.state = NativeMethods.cairo_reference (state);
this.state = owned ? state : NativeMethods.cairo_reference (state);
}
~Context ()

View File

@ -3,7 +3,7 @@
<namespace name="Cairo">
<enum cname="cairo_content_t" name="Content" type="enum" />
</namespace>
<symbol type="manual" cname="cairo_t" name="Cairo.Context"/>
<symbol type="ownable" cname="cairo_t" name="Cairo.Context"/>
<symbol type="manual" cname="cairo_font_options_t" name="Cairo.FontOptions"/>
<symbol type="manual" cname="cairo_region_t" name="Cairo.Region"/>
<symbol type="marshal" cname="cairo_pattern_t" name="Cairo.Pattern" marshal_type="IntPtr" call_fmt="{0}.Handle" from_fmt="Cairo.Pattern.Lookup ({0})" />

View File

@ -25,7 +25,7 @@ namespace GtkSharp.Generation {
using System.IO;
using System.Xml;
public abstract class HandleBase : ClassBase, IAccessor {
public abstract class HandleBase : ClassBase, IAccessor, IOwnable {
protected HandleBase (XmlElement ns, XmlElement elem) : base (ns, elem) {}

24
generator/IOwnable.cs Normal file
View File

@ -0,0 +1,24 @@
// Copyright (c) 2011 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GtkSharp.Generation {
public interface IOwnable {
string FromNative (string var, bool owned);
}
}

View File

@ -31,6 +31,7 @@ sources = \
IManualMarshaler.cs \
InterfaceGen.cs \
InterfaceVM.cs \
IOwnable.cs \
LogWriter.cs \
LPGen.cs \
LPUGen.cs \
@ -44,6 +45,7 @@ sources = \
ObjectBase.cs \
ObjectGen.cs \
OpaqueGen.cs \
OwnableGen.cs \
Parameters.cs \
Parser.cs \
Property.cs \

51
generator/OwnableGen.cs Normal file
View File

@ -0,0 +1,51 @@
// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GtkSharp.Generation {
using System;
public class OwnableGen : SimpleBase, IOwnable {
public OwnableGen (string ctype, string type) : base (ctype, type, "null") {}
public override string MarshalType {
get { return "IntPtr"; }
}
public override string CallByName (string var_name)
{
return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle";
}
public override string FromNative (string var)
{
return String.Format ("new {0} ({1})", QualifiedName, var);
}
public string FromNative (string var, bool owned)
{
return String.Format ("new {0} ({1}, {2})", QualifiedName, var, owned ? "true" : "false");
}
}
}

View File

@ -283,8 +283,8 @@ namespace GtkSharp.Generation {
result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";";
return result;
} else if (PassAs != String.Empty && MarshalType != CSType)
if (gen is HandleBase)
return new string [] { CallName + " = " + (gen as HandleBase).FromNative ("native_" + CallName, Owned) + ";" };
if (gen is IOwnable)
return new string [] { CallName + " = " + (gen as IOwnable).FromNative ("native_" + CallName, Owned) + ";" };
else
return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" };
return new string [0];
@ -295,8 +295,8 @@ namespace GtkSharp.Generation {
{
if (Generatable == null)
return String.Empty;
else if (Generatable is HandleBase)
return ((HandleBase)Generatable).FromNative (var, Owned);
else if (Generatable is IOwnable)
return ((IOwnable)Generatable).FromNative (var, Owned);
else
return Generatable.FromNative (var);
}

View File

@ -169,6 +169,8 @@ namespace GtkSharp.Generation {
}
} else if (type == "manual")
result = new ManualGen (cname, name);
else if (type == "ownable")
result = new OwnableGen (cname, name);
else if (type == "alias")
result = new AliasGen (cname, name);
else if (type == "marshal") {

View File

@ -129,8 +129,8 @@ namespace GtkSharp.Generation {
return String.Format ("({0}[]) GLib.Marshaller.PtrArrayToArray ({1}, {2}, typeof({0}))", ElementType, var, args);
else
return String.Format ("({0}[]) GLib.Marshaller.ListPtrToArray ({1}, typeof({2}), {3}, typeof({4}))", ElementType, var, IGen.QualifiedName, args, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType);
} else if (IGen is HandleBase)
return ((HandleBase)IGen).FromNative (var, owned);
} else if (IGen is IOwnable)
return ((IOwnable)IGen).FromNative (var, owned);
else if (is_null_term)
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
else