2004-11-17 17:00:00 +01:00
|
|
|
// GtkSharp.Generation.ReturnValue.cs - The ReturnValue Generatable.
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@novell.com>
|
|
|
|
//
|
2005-06-24 00:28:06 +02:00
|
|
|
// Copyright (c) 2004-2005 Novell, Inc.
|
2004-11-17 17:00:00 +01:00
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class ReturnValue {
|
2005-06-24 00:28:06 +02:00
|
|
|
|
2004-11-17 17:00:00 +01:00
|
|
|
|
|
|
|
private XmlElement elem;
|
|
|
|
|
|
|
|
public ReturnValue (XmlElement elem)
|
|
|
|
{
|
|
|
|
this.elem = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string CType {
|
|
|
|
get {
|
|
|
|
return elem == null ? String.Empty : elem.GetAttribute("type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string CSType {
|
|
|
|
get {
|
2005-03-07 16:54:49 +01:00
|
|
|
if (IGen == null)
|
|
|
|
return String.Empty;
|
2005-06-08 18:53:12 +02:00
|
|
|
|
|
|
|
if (ElementType != String.Empty)
|
|
|
|
return ElementType + "[]";
|
|
|
|
|
2005-03-07 16:54:49 +01:00
|
|
|
return IGen.QualifiedName + (IsArray ? "[]" : String.Empty);
|
2004-11-17 17:00:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 00:28:06 +02:00
|
|
|
string ElementCType {
|
|
|
|
get {
|
|
|
|
if (elem != null && elem.HasAttribute ("element_type"))
|
|
|
|
return elem.GetAttribute ("element_type");
|
|
|
|
|
|
|
|
return String.Empty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ElementsOwned {
|
|
|
|
get {
|
|
|
|
if (elem != null && elem.GetAttribute ("elements_owned") == "true")
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-07 16:54:49 +01:00
|
|
|
string ElementType {
|
2004-11-17 17:00:00 +01:00
|
|
|
get {
|
2005-06-24 00:28:06 +02:00
|
|
|
if (ElementCType.Length > 0)
|
|
|
|
return SymbolTable.Table.GetCSType (ElementCType);
|
|
|
|
|
|
|
|
return String.Empty;
|
2004-11-17 17:00:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-07 16:54:49 +01:00
|
|
|
IGeneratable igen;
|
|
|
|
IGeneratable IGen {
|
|
|
|
get {
|
|
|
|
if (igen == null)
|
|
|
|
igen = SymbolTable.Table [CType];
|
|
|
|
return igen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsArray {
|
2004-11-17 17:00:00 +01:00
|
|
|
get {
|
|
|
|
return elem == null ? false : elem.HasAttribute ("array");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-04 17:02:44 +01:00
|
|
|
public bool IsVoid {
|
|
|
|
get {
|
|
|
|
return CSType == "void";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 17:00:00 +01:00
|
|
|
public string MarshalType {
|
|
|
|
get {
|
2005-03-07 16:54:49 +01:00
|
|
|
if (IGen == null)
|
|
|
|
return String.Empty;
|
|
|
|
return IGen.MarshalReturnType + (IsArray ? "[]" : String.Empty);
|
2004-11-17 17:00:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-07 16:54:49 +01:00
|
|
|
bool Owned {
|
2005-01-19 03:58:42 +01:00
|
|
|
get {
|
|
|
|
return elem.GetAttribute ("owned") == "true";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-17 17:00:00 +01:00
|
|
|
public string ToNativeType {
|
|
|
|
get {
|
2005-03-07 16:54:49 +01:00
|
|
|
if (IGen == null)
|
|
|
|
return String.Empty;
|
|
|
|
return IGen.ToNativeReturnType + (IsArray ? "[]" : String.Empty);
|
2004-11-17 17:00:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-04 17:02:44 +01:00
|
|
|
public string FromNative (string var)
|
|
|
|
{
|
2005-03-07 16:54:49 +01:00
|
|
|
if (IGen == null)
|
|
|
|
return String.Empty;
|
2005-06-24 00:28:06 +02:00
|
|
|
|
|
|
|
if (ElementType != String.Empty) {
|
2005-06-08 18:53:12 +02:00
|
|
|
string type_str = "typeof (" + ElementType + ")";
|
2005-06-24 00:28:06 +02:00
|
|
|
string args = type_str + ", " + (Owned ? "true" : "false") + ", " + (ElementsOwned ? "true" : "false");
|
|
|
|
return String.Format ("({0}[]) GLib.Marshaller.ListToArray ({1}, {2})", ElementType, IGen.FromNativeReturn (var + ", " + args), type_str);
|
|
|
|
} else if (Owned)
|
|
|
|
var += ", true";
|
2005-03-07 16:54:49 +01:00
|
|
|
return IGen.FromNativeReturn (var);
|
2005-03-04 17:02:44 +01:00
|
|
|
}
|
|
|
|
|
2004-11-17 17:00:00 +01:00
|
|
|
public bool Validate ()
|
|
|
|
{
|
|
|
|
if (MarshalType == "" || CSType == "") {
|
|
|
|
Console.Write("rettype: " + CType);
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-08 18:53:12 +02:00
|
|
|
|
2004-11-17 17:00:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|