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>
|
|
|
|
//
|
2004-06-25 16:35:15 +00:00
|
|
|
// Copyright (c) 2001 Mike Kestner
|
|
|
|
//
|
|
|
|
// 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-01-04 02:02:28 +00:00
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
namespace GtkSharp.Generation {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
using System;
|
2004-12-27 20:00:55 +00:00
|
|
|
using System.Collections;
|
2002-01-04 02:02:28 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public class EnumGen : GenBase {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
2004-12-27 20:00:55 +00:00
|
|
|
string enum_type = String.Empty;
|
|
|
|
ArrayList members = new ArrayList ();
|
|
|
|
|
|
|
|
public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
|
|
|
{
|
|
|
|
foreach (XmlElement member in elem.ChildNodes) {
|
|
|
|
if (member.Name != "member")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
string result = "\t\t" + member.GetAttribute("name");
|
|
|
|
if (member.HasAttribute("value")) {
|
|
|
|
string value = member.GetAttribute("value");
|
|
|
|
if (value.EndsWith("U")) {
|
|
|
|
enum_type = " : uint";
|
|
|
|
value = value.TrimEnd('U');
|
|
|
|
}
|
|
|
|
result += " = " + value;
|
|
|
|
}
|
|
|
|
members.Add (result + ",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-05 20:34:45 +00:00
|
|
|
public override bool Validate ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-21 16:37:04 +00:00
|
|
|
public override string DefaultValue {
|
|
|
|
get {
|
|
|
|
return "(" + QualifiedName + ") 0";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public override string MarshalType {
|
|
|
|
get {
|
2002-01-04 02:02:28 +00:00
|
|
|
return "int";
|
|
|
|
}
|
|
|
|
}
|
2004-11-18 22:19:31 +00:00
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public override string CallByName (string var_name)
|
2002-01-04 02:02:28 +00:00
|
|
|
{
|
|
|
|
return "(int) " + var_name;
|
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public override string FromNative(string var)
|
2002-02-08 23:56:27 +00:00
|
|
|
{
|
2004-12-26 19:33:34 +00:00
|
|
|
return "(" + QualifiedName + ") " + var;
|
2002-02-08 23:56:27 +00:00
|
|
|
}
|
|
|
|
|
2004-12-26 19:33:34 +00:00
|
|
|
public override void Generate (GenerationInfo gen_info)
|
2003-10-05 00:20:17 +00:00
|
|
|
{
|
|
|
|
StreamWriter sw = gen_info.OpenStream (Name);
|
|
|
|
|
|
|
|
sw.WriteLine ("namespace " + NS + " {");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tusing System;");
|
2005-05-04 16:54:24 +00:00
|
|
|
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ();
|
2002-05-23 23:43:25 +00:00
|
|
|
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#region Autogenerated code");
|
2003-02-18 17:28:51 +00:00
|
|
|
|
2005-05-04 16:54:24 +00:00
|
|
|
if (Elem.GetAttribute("type") == "flags")
|
|
|
|
sw.WriteLine ("\t[Flags]");
|
|
|
|
if (Elem.HasAttribute("gtype"))
|
|
|
|
sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]");
|
|
|
|
|
2004-12-27 20:00:55 +00:00
|
|
|
sw.WriteLine ("\tpublic enum " + Name + enum_type + " {");
|
2002-01-04 02:02:28 +00:00
|
|
|
sw.WriteLine ();
|
|
|
|
|
2004-12-27 20:00:55 +00:00
|
|
|
foreach (string member in members)
|
|
|
|
sw.WriteLine (member);
|
2003-01-05 23:51:37 +00:00
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
sw.WriteLine ("\t}");
|
2005-05-04 16:54:24 +00:00
|
|
|
|
|
|
|
if (Elem.HasAttribute ("gtype")) {
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\tinternal class " + Name + "GType {");
|
|
|
|
sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\")]");
|
|
|
|
sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
|
|
|
|
sw.WriteLine ();
|
|
|
|
sw.WriteLine ("\t\tpublic static GLib.GType GType {");
|
|
|
|
sw.WriteLine ("\t\t\tget {");
|
|
|
|
sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());");
|
|
|
|
sw.WriteLine ("\t\t\t}");
|
|
|
|
sw.WriteLine ("\t\t}");
|
|
|
|
sw.WriteLine ("\t}");
|
|
|
|
}
|
|
|
|
|
2003-01-05 23:51:37 +00:00
|
|
|
sw.WriteLine ("#endregion");
|
2003-10-05 00:20:17 +00:00
|
|
|
sw.WriteLine ("}");
|
|
|
|
sw.Close ();
|
2002-02-19 03:12:47 +00:00
|
|
|
Statistics.EnumCount++;
|
2002-01-04 02:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|