update for 0.3.3 release
[vala-lang.git] / ccode / valaccodeenum.vala
blob6701d7ee73847898de63c2de6d4a576ebb49017f
1 /* valaccodeenum.vala
3 * Copyright (C) 2006-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
24 using Gee;
26 /**
27 * Represents an enum in the C code.
29 public class Vala.CCodeEnum : CCodeNode {
30 /**
31 * The name of this enum.
33 public string name { get; set; }
35 private Gee.List<CCodeEnumValue> values = new ArrayList<CCodeEnumValue> ();
37 public CCodeEnum (string? name = null) {
38 this.name = name;
41 /**
42 * Adds the specified value to this enum.
44 * @param name enum value name
45 * @param value optional numerical value
47 public void add_value (CCodeEnumValue value) {
48 values.add (value);
51 public override void write (CCodeWriter writer) {
52 if (name != null) {
53 writer.write_string ("typedef ");
55 writer.write_string ("enum ");
56 writer.write_begin_block ();
57 bool first = true;
58 foreach (CCodeEnumValue value in values) {
59 if (!first) {
60 writer.write_string (",");
61 writer.write_newline ();
63 writer.write_indent ();
64 value.write (writer);
65 first = false;
67 if (!first) {
68 writer.write_newline ();
70 writer.write_end_block ();
71 if (name != null) {
72 writer.write_string (" ");
73 writer.write_string (name);
75 writer.write_string (";");
76 writer.write_newline ();