1
// GtkSharp.Generation.EnumGen.cs - The Enumeration Generatable.
3
// Author: Mike Kestner <mkestner@speakeasy.net>
5
// Copyright (c) 2001 Mike Kestner
7
// This program is free software; you can redistribute it and/or
8
// modify it under the terms of version 2 of the GNU General Public
9
// License as published by the Free Software Foundation.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this program; if not, write to the
18
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
// Boston, MA 02111-1307, USA.
22
namespace GtkSharp.Generation {
25
using System.Collections;
29
public class EnumGen : GenBase {
31
string enum_type = String.Empty;
32
ArrayList members = new ArrayList ();
34
public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem)
36
foreach (XmlElement member in elem.ChildNodes) {
37
if (member.Name != "member")
40
string result = "\t\t" + member.GetAttribute("name");
41
if (member.HasAttribute("value")) {
42
string value = member.GetAttribute("value");
43
if (value.EndsWith("U")) {
44
enum_type = " : uint";
45
value = value.TrimEnd('U');
47
result += " = " + value;
49
members.Add (result + ",");
53
public override bool Validate ()
58
public override string DefaultValue {
60
return "(" + QualifiedName + ") 0";
64
public override string MarshalType {
70
public override string CallByName (string var_name)
72
return "(int) " + var_name;
75
public override string FromNative(string var)
77
return "(" + QualifiedName + ") " + var;
80
public override void Generate (GenerationInfo gen_info)
82
StreamWriter sw = gen_info.OpenStream (Name);
84
sw.WriteLine ("namespace " + NS + " {");
86
sw.WriteLine ("\tusing System;");
87
sw.WriteLine ("\tusing System.Runtime.InteropServices;");
90
sw.WriteLine ("#region Autogenerated code");
92
if (Elem.GetAttribute("type") == "flags")
93
sw.WriteLine ("\t[Flags]");
94
if (Elem.HasAttribute("gtype"))
95
sw.WriteLine ("\t[GLib.GType (typeof (" + NS + "." + Name + "GType))]");
97
string access = IsInternal ? "internal" : "public";
98
sw.WriteLine ("\t" + access + " enum " + Name + enum_type + " {");
101
foreach (string member in members)
102
sw.WriteLine (member);
104
sw.WriteLine ("\t}");
106
if (Elem.HasAttribute ("gtype")) {
108
sw.WriteLine ("\tinternal class " + Name + "GType {");
109
sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\")]");
110
sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
112
sw.WriteLine ("\t\tpublic static GLib.GType GType {");
113
sw.WriteLine ("\t\t\tget {");
114
sw.WriteLine ("\t\t\t\treturn new GLib.GType (" + Elem.GetAttribute ("gtype") + " ());");
115
sw.WriteLine ("\t\t\t}");
116
sw.WriteLine ("\t\t}");
117
sw.WriteLine ("\t}");
120
sw.WriteLine ("#endregion");
123
Statistics.EnumCount++;