~ubuntu-branches/debian/sid/docky/sid

« back to all changes in this revision

Viewing changes to lib/gio-sharp/generator/EnumGen.cs

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2012-01-19 19:03:38 UTC
  • mfrom: (1.1.14) (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20120119190338-n44q7tmqsrkudvk7
Tags: 2.1.3-2
* Upload to unstable
* debian/watch:
  + Look for xz tarballs from now on

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// GtkSharp.Generation.EnumGen.cs - The Enumeration Generatable.
2
 
//
3
 
// Author: Mike Kestner <mkestner@speakeasy.net>
4
 
//
5
 
// Copyright (c) 2001 Mike Kestner
6
 
//
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.
10
 
//
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.
15
 
//
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.
20
 
 
21
 
 
22
 
namespace GtkSharp.Generation {
23
 
 
24
 
        using System;
25
 
        using System.Collections;
26
 
        using System.IO;
27
 
        using System.Xml;
28
 
 
29
 
        public class EnumGen : GenBase {
30
 
                
31
 
                string enum_type = String.Empty;
32
 
                ArrayList members = new ArrayList ();
33
 
 
34
 
                public EnumGen (XmlElement ns, XmlElement elem) : base (ns, elem) 
35
 
                {
36
 
                        foreach (XmlElement member in elem.ChildNodes) {
37
 
                                if (member.Name != "member")
38
 
                                        continue;
39
 
 
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');
46
 
                                        }
47
 
                                        result += " = " + value;
48
 
                                }
49
 
                                members.Add (result + ",");
50
 
                        }
51
 
                }
52
 
 
53
 
                public override bool Validate ()
54
 
                {
55
 
                        return true;
56
 
                }
57
 
 
58
 
                public override string DefaultValue {
59
 
                        get {
60
 
                                return "(" + QualifiedName + ") 0";
61
 
                        }
62
 
                }
63
 
 
64
 
                public override string MarshalType {
65
 
                        get {
66
 
                                return "int";
67
 
                        }
68
 
                }
69
 
 
70
 
                public override string CallByName (string var_name)
71
 
                {
72
 
                        return "(int) " + var_name;
73
 
                }
74
 
                
75
 
                public override string FromNative(string var)
76
 
                {
77
 
                        return "(" + QualifiedName + ") " + var;
78
 
                }
79
 
                
80
 
                public override void Generate (GenerationInfo gen_info)
81
 
                {
82
 
                        StreamWriter sw = gen_info.OpenStream (Name);
83
 
 
84
 
                        sw.WriteLine ("namespace " + NS + " {");
85
 
                        sw.WriteLine ();
86
 
                        sw.WriteLine ("\tusing System;");
87
 
                        sw.WriteLine ("\tusing System.Runtime.InteropServices;");
88
 
                        sw.WriteLine ();
89
 
 
90
 
                        sw.WriteLine ("#region Autogenerated code");
91
 
                                        
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))]");
96
 
 
97
 
                        string access = IsInternal ? "internal" : "public";
98
 
                        sw.WriteLine ("\t" + access + " enum " + Name + enum_type + " {");
99
 
                        sw.WriteLine ();
100
 
                                
101
 
                        foreach (string member in members)
102
 
                                sw.WriteLine (member);
103
 
 
104
 
                        sw.WriteLine ("\t}");
105
 
 
106
 
                        if (Elem.HasAttribute ("gtype")) {
107
 
                                sw.WriteLine ();
108
 
                                sw.WriteLine ("\tinternal class " + Name + "GType {");
109
 
                                sw.WriteLine ("\t\t[DllImport (\"" + LibraryName + "\")]");
110
 
                                sw.WriteLine ("\t\tstatic extern IntPtr " + Elem.GetAttribute ("gtype") + " ();");
111
 
                                sw.WriteLine ();
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}");
118
 
                        }
119
 
 
120
 
                        sw.WriteLine ("#endregion");
121
 
                        sw.WriteLine ("}");
122
 
                        sw.Close ();
123
 
                        Statistics.EnumCount++;
124
 
                }
125
 
        }
126
 
}
127