Fix gtk_text_iter_forward_find_char binding, patch by Nicolas Joseph,
[vala-lang.git] / vala / valatypesymbol.vala
blobccb3820a2d390b190f7c2882971da8d0bc8c1e66
1 /* valatypesymbol.vala
3 * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
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>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
24 using GLib;
25 using Gee;
27 /**
28 * Represents a runtime data type. This data type may be defined in Vala source
29 * code or imported from an external library with a Vala API file.
31 public abstract class Vala.TypeSymbol : Symbol {
32 private Gee.List<string> cheader_filenames = new ArrayList<string> ();
34 public TypeSymbol (string? name, SourceReference? source_reference = null) {
35 base (name, source_reference);
38 /**
39 * Returns the name of this data type as it is used in C code.
41 * @return the name to be used in C code
43 public abstract string get_cname (bool const_type = false);
45 /**
46 * Checks whether this data type has value or reference type semantics.
48 * @return true if this data type has reference type semantics
50 public virtual bool is_reference_type () {
51 return false;
54 /**
55 * Returns the C function name that duplicates instances of this data
56 * type. The specified C function must accept one argument referencing
57 * the instance of this data type and return a reference to the
58 * duplicate.
60 * @return the name of the C function if supported or null otherwise
62 public virtual string? get_dup_function () {
63 return null;
66 /**
67 * Returns the C function name that frees instances of this data type.
68 * The specified C function must accept one argument pointing to the
69 * instance to be freed.
71 * @return the name of the C function if supported or null otherwise
73 public virtual string? get_free_function () {
74 return null;
77 /**
78 * Returns the C function name that copies contents of instances of
79 * this data type. This is only applicable to structs. The specified
80 * C function must accept two arguments, the first is the source value
81 * and the second is the destination value.
83 * @return the name of the C function if supported or null otherwise
85 public virtual string? get_copy_function () {
86 return null;
89 /**
90 * Returns the C function name that destroys the contents of instances
91 * of this data type. This is only applicable to structs. The specified
92 * C function must accept one argument pointing to the instance to be
93 * destroyed.
95 * @return the name of the C function if supported or null otherwise
97 public virtual string? get_destroy_function () {
98 return null;
102 * Checks whether this data type supports reference counting. This is
103 * only valid for reference types.
105 * @return true if this data type supports reference counting
107 public virtual bool is_reference_counting () {
108 return false;
112 * Returns the C function name that increments the reference count of
113 * instances of this data type. This is only valid for data types
114 * supporting reference counting. The specified C function must accept
115 * one argument referencing the instance of this data type and return
116 * the reference.
118 * @return the name of the C function or null if this data type does not
119 * support reference counting
121 public virtual string? get_ref_function () {
122 return null;
126 * Returns the C function name that decrements the reference count of
127 * instances of this data type. This is only valid for data types
128 * supporting reference counting. The specified C function must accept
129 * one argument referencing the instance of this data type.
131 * @return the name of the C function or null if this data type does not
132 * support reference counting
134 public virtual string? get_unref_function () {
135 return null;
139 * Returns the C symbol representing the runtime type id for this data
140 * type. The specified symbol must express a registered GType.
142 * @return the name of the GType name in C code or null if this data
143 * type is not registered with GType
145 public virtual string? get_type_id () {
146 return null;
150 * Returns the name of this data type as used in C code marshallers
152 * @return type name for marshallers
154 public virtual string? get_marshaller_type_name () {
155 return null;
159 * Returns the cname of the GValue parameter spec function.
161 public virtual string? get_param_spec_function () {
162 return null;
166 * Returns the cname of the GValue getter function.
168 public virtual string? get_get_value_function () {
169 return null;
173 * Returns the cname of the GValue setter function.
175 public virtual string? get_set_value_function () {
176 return null;
180 * Returns the C name of this data type in upper case. Words are
181 * separated by underscores. The upper case C name of the namespace is
182 * prefix of the result.
184 * @param infix a string to be placed between namespace and data type
185 * name or null
186 * @return the upper case name to be used in C code
188 public virtual string? get_upper_case_cname (string? infix = null) {
189 return null;
193 * Returns the default value for the given type. Returning null means
194 * there is no default value (i.e. not that the default name is NULL).
196 * @return the name of the default value
198 public virtual string? get_default_value () {
199 return null;
202 public override Gee.List<string> get_cheader_filenames () {
203 // parent_symbol can be null on incremental parsing
204 if (cheader_filenames.size == 0 && parent_symbol != null) {
205 /* default to header filenames of the namespace */
206 foreach (string filename in parent_symbol.get_cheader_filenames ()) {
207 add_cheader_filename (filename);
210 if (cheader_filenames.size == 0 && source_reference != null && !external_package) {
211 // don't add default include directives for VAPI files
212 cheader_filenames.add (source_reference.file.get_cinclude_filename ());
215 return new ReadOnlyList<string> (cheader_filenames);
219 * Adds a filename to the list of C header filenames users of this data
220 * type must include.
222 * @param filename a C header filename
224 public void add_cheader_filename (string filename) {
225 cheader_filenames.add (filename);
229 * Checks whether this data type is equal to or a subtype of the
230 * specified data type.
232 * @param t a data type
233 * @return true if t is a supertype of this data type, false otherwise
235 public virtual bool is_subtype_of (TypeSymbol t) {
236 return (this == t);
240 * Return the index of the specified type parameter name.
242 public virtual int get_type_parameter_index (string name) {
243 return -1;
247 * Returns type signature as used for GVariant and D-Bus
249 public virtual string? get_type_signature () {
250 return null;