2002-05-23 23:43:25 +00:00
|
|
|
// GtkSharp.Generation.GenBase.cs - The Generatable base class.
|
|
|
|
//
|
2004-12-26 19:33:34 +00:00
|
|
|
// Author: Mike Kestner <mkestner@novell.com>
|
2002-05-23 23:43:25 +00:00
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// Copyright (c) 2001-2002 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.
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
|
|
|
|
namespace GtkSharp.Generation {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public abstract class GenBase : IGeneratable {
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2002-06-21 20:25:43 +00:00
|
|
|
private XmlElement ns;
|
2002-05-23 23:43:25 +00:00
|
|
|
private XmlElement elem;
|
|
|
|
|
2002-06-21 20:25:43 +00:00
|
|
|
protected GenBase (XmlElement ns, XmlElement elem)
|
2002-05-23 23:43:25 +00:00
|
|
|
{
|
|
|
|
this.ns = ns;
|
|
|
|
this.elem = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string CName {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute ("cname");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public XmlElement Elem {
|
|
|
|
get {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-21 20:25:43 +00:00
|
|
|
public string LibraryName {
|
|
|
|
get {
|
|
|
|
return ns.GetAttribute ("library");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public virtual string MarshalReturnType {
|
|
|
|
get {
|
|
|
|
return MarshalType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract string MarshalType { get; }
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public string Name {
|
|
|
|
get {
|
|
|
|
return elem.GetAttribute ("name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-21 20:25:43 +00:00
|
|
|
public string NS {
|
2002-05-23 23:43:25 +00:00
|
|
|
get {
|
2002-06-21 20:25:43 +00:00
|
|
|
return ns.GetAttribute ("name");
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string QualifiedName {
|
|
|
|
get {
|
2002-06-21 20:25:43 +00:00
|
|
|
return NS + "." + Name;
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public virtual string ToNativeReturnType {
|
|
|
|
get {
|
|
|
|
return MarshalType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void AppendCustom (StreamWriter sw, string custom_dir)
|
2002-06-10 12:34:09 +00:00
|
|
|
{
|
|
|
|
char sep = Path.DirectorySeparatorChar;
|
2003-10-05 00:20:17 +00:00
|
|
|
string custom = custom_dir + sep + Name + ".custom";
|
2002-06-10 12:34:09 +00:00
|
|
|
if (File.Exists(custom)) {
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#region Customized extensions");
|
2003-07-02 18:13:24 +00:00
|
|
|
sw.WriteLine ("#line 1 \"" + Name + ".custom\"");
|
2002-06-10 12:34:09 +00:00
|
|
|
FileStream custstream = new FileStream(custom, FileMode.Open, FileAccess.Read);
|
|
|
|
StreamReader sr = new StreamReader(custstream);
|
|
|
|
sw.WriteLine (sr.ReadToEnd ());
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#endregion");
|
2002-06-10 12:34:09 +00:00
|
|
|
sr.Close ();
|
|
|
|
}
|
|
|
|
}
|
2004-12-26 19:33:34 +00:00
|
|
|
|
|
|
|
public abstract string CallByName (string var);
|
|
|
|
|
|
|
|
public abstract string FromNative (string var);
|
|
|
|
|
|
|
|
public virtual string FromNativeReturn (string var)
|
|
|
|
{
|
|
|
|
return FromNative (var);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual string ToNativeReturn (string var)
|
|
|
|
{
|
|
|
|
return CallByName (var);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Generate ()
|
|
|
|
{
|
|
|
|
GenerationInfo geninfo = new GenerationInfo (ns);
|
|
|
|
Generate (geninfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void Generate (GenerationInfo geninfo);
|
2002-05-23 23:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|