2002-01-05 12:45:55 +00:00
|
|
|
// GtkSharp.Generation.EnumGen.cs - The Enumeration Generatable.
|
2002-01-04 02:02:28 +00:00
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
namespace GtkSharp.Generation {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public class EnumGen : GenBase, IGeneratable {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
2002-06-21 20:25:43 +00:00
|
|
|
public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem) {}
|
2002-01-05 12:45:55 +00:00
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
public String MarshalType {
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "int";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String CallByName (String var_name)
|
|
|
|
{
|
|
|
|
return "(int) " + var_name;
|
|
|
|
}
|
|
|
|
|
2002-02-08 23:56:27 +00:00
|
|
|
public String FromNative(String var)
|
|
|
|
{
|
|
|
|
return "(" + QualifiedName + ")" + var;
|
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public void Generate ()
|
2002-01-04 02:02:28 +00:00
|
|
|
{
|
2002-05-23 23:43:25 +00:00
|
|
|
StreamWriter sw = CreateWriter ();
|
|
|
|
|
|
|
|
if (Elem.GetAttribute("type") == "flags") {
|
2002-01-04 02:02:28 +00:00
|
|
|
sw.WriteLine ("\tusing System;");
|
|
|
|
sw.WriteLine ();
|
|
|
|
}
|
2002-06-24 22:04:10 +00:00
|
|
|
|
|
|
|
sw.WriteLine("\t\t/// <summary> " + Name + " enumeration </summary>");
|
|
|
|
sw.WriteLine("\t\t/// <remarks>");
|
|
|
|
sw.WriteLine("\t\t/// </remarks>");
|
|
|
|
|
|
|
|
if (Elem.GetAttribute("type") == "flags")
|
|
|
|
sw.WriteLine ("\t[Flags]");
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
sw.WriteLine ("\tpublic enum " + Name + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
foreach (XmlNode node in Elem.ChildNodes) {
|
2002-01-04 02:02:28 +00:00
|
|
|
if (node.Name != "member") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlElement member = (XmlElement) node;
|
2002-06-24 22:04:10 +00:00
|
|
|
|
|
|
|
sw.WriteLine("\t\t/// <summary />");
|
|
|
|
sw.WriteLine("\t\t/// <remarks>");
|
|
|
|
sw.WriteLine("\t\t/// </remarks>");
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
sw.Write ("\t\t" + member.GetAttribute("name"));
|
|
|
|
if (member.HasAttribute("value")) {
|
|
|
|
sw.WriteLine (" = " + member.GetAttribute("value") + ",");
|
|
|
|
} else {
|
|
|
|
sw.WriteLine (",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sw.WriteLine ("\t}");
|
2002-05-23 23:43:25 +00:00
|
|
|
CloseWriter (sw);
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.EnumCount++;
|
2002-01-04 02:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|