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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a struct declaration in the C code.
28 public class Vala
.CCodeStruct
: CCodeNode
{
32 public string name
{ get; set; }
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
) {
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
);
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 ();
78 writer
.write_string (" G_GNUC_DEPRECATED");
80 writer
.write_string (";");
81 writer
.write_newline ();
82 writer
.write_newline ();