3 * Copyright (C) 2006-2007 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 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 flags declaration in the source code.
28 public class Vala
.Flags
: DataType
{
29 private List
<FlagsValue
> values
;
31 private string cprefix
;
34 * Creates a new flags.
36 * @param name type name
37 * @param source reference to source code
38 * @return newly created flags
40 public Flags (construct string! name
, construct SourceReference source_reference
= null) {
44 * Appends the specified flags value to the list of values.
46 * @param value a flags value
48 public void add_value (FlagsValue
! value
) {
49 values
.append (value
);
52 public override void accept (CodeVisitor
! visitor
) {
53 visitor
.visit_flags (this
);
56 public override void accept_children (CodeVisitor
! visitor
) {
57 foreach (FlagsValue value
in values
) {
58 value
.accept (visitor
);
62 public override string get_cname (bool const_type
= false) {
64 cname
= "%s%s".printf (@
namespace.get_cprefix (), name
);
69 public override string get_upper_case_cname (string infix
) {
70 return "%s%s".printf (@
namespace.get_lower_case_cprefix (), Namespace
.camel_case_to_lower_case (name
)).up ();
73 public override bool is_reference_type () {
77 private void set_cname (string! cname
) {
82 * Returns the string to be prepended to the name of members of this
83 * enum when used in C code.
85 * @return the prefix to be used in C code
87 public string! get_cprefix () {
88 if (cprefix
== null) {
89 cprefix
= "%s_".printf (get_upper_case_cname (null));
95 * Sets the string to be prepended to the name of members of this enum
96 * when used in C code.
98 * @param cprefix the prefix to be used in C code
100 public void set_cprefix (string! cprefix
) {
101 this
.cprefix
= cprefix
;
104 private void process_ccode_attribute (Attribute
! a
) {
105 if (a
.has_argument ("cname")) {
106 set_cname (a
.get_string ("cname"));
108 if (a
.has_argument ("cprefix")) {
109 set_cprefix (a
.get_string ("cprefix"));
111 if (a
.has_argument ("cheader_filename")) {
112 var val
= a
.get_string ("cheader_filename");
113 foreach (string filename
in val
.split (",")) {
114 add_cheader_filename (filename
);
120 * Process all associated attributes.
122 public void process_attributes () {
123 foreach (Attribute a
in attributes
) {
124 if (a
.name
== "CCode") {
125 process_ccode_attribute (a
);
130 public override string get_type_id () {
131 // FIXME: use GType-registered flags
135 public override string get_marshaller_type_name () {
139 public override string get_get_value_function () {
140 return "g_value_get_flags";
143 public override string get_set_value_function () {
144 return "g_value_set_flags";
147 public override string get_default_value () {