gedit-2.20: Make Window.create_tab_from_uri.encoding nullable.
[vala-lang.git] / ccode / valaccodestruct.vala
blob76f7679f24f2e96e9c1c285dc3861b143fb7321a
1 /* valaccodestruct.vala
3 * Copyright (C) 2006-2010 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;
25 /**
26 * Represents a struct declaration in the C code.
28 public class Vala.CCodeStruct : CCodeNode {
29 /**
30 * The struct name.
32 public string name { get; set; }
34 /**
35 * Whether the struct is deprecated.
37 public bool deprecated { get; set; default = false; }
39 public bool is_empty { get { return declarations.size == 0; } }
41 private List<CCodeDeclaration> declarations = new ArrayList<CCodeDeclaration> ();
43 public CCodeStruct (string name) {
44 this.name = name;
47 /**
48 * Adds the specified declaration as member to this struct.
50 * @param decl a variable declaration
52 public void add_declaration (CCodeDeclaration decl) {
53 declarations.add (decl);
56 /**
57 * Adds a variable with the specified type and name to this struct.
59 * @param type_name field type
60 * @param name member name
62 public void add_field (string type_name, string name, string? declarator_suffix = null) {
63 var decl = new CCodeDeclaration (type_name);
64 decl.add_declarator (new CCodeVariableDeclarator (name, null, declarator_suffix));
65 add_declaration (decl);
68 public override void write (CCodeWriter writer) {
69 writer.write_string ("struct ");
70 writer.write_string (name);
71 writer.write_begin_block ();
72 foreach (CCodeDeclaration decl in declarations) {
73 decl.write_declaration (writer);
76 writer.write_end_block ();
77 if (deprecated) {
78 writer.write_string (" G_GNUC_DEPRECATED");
80 writer.write_string (";");
81 writer.write_newline ();
82 writer.write_newline ();