]> git.draconx.ca Git - gob-dx.git/blob - doc/gob2.1.in
Add support for simple dynamic types.
[gob-dx.git] / doc / gob2.1.in
1 .\"
2 .\" gob manual page
3 .\" (C) 1999-2011 Jiri (George) Lebl <jirka@5z.com>
4 .\" 
5 .\" This manual page is covered by the terms of the GNU General
6 .\" Public License.  
7 .\"
8 .TH GOB2 1 "GOB2 @VERSION@" 
9 .SH NAME
10 GOB2 \- The GObject Builder
11 .SH SYNOPSIS
12 .PP
13 .B gob2
14 [ option ] ...
15 file
16
17 .SH DESCRIPTION
18 .PP
19 GObject Builder is a simple preprocessor for easily creating
20 GObject objects.  It does not parse any C code and ignores any C errors.  It
21 is in spirit similar to things like lex or yacc.  In some ways it
22 also resembles java.  But it is really just a simple preprocessor
23 for creating GObjects for use in C or C++ and it is not a programming
24 language.
25
26 .SH OPTIONS
27 .PP
28 .TP
29 .B \-? \-h \-\-help
30 Display a simple help screen.
31 .TP
32 .B \-\-version
33 Display version information
34 .TP
35 .B \-w \-\-exit\-on\-warn
36 Exit with an error code even when you encounter a warning.
37 .TP
38 .B \-\-no\-exit\-on\-warn
39 Exit with an error only on errors, not on warnings, this is the default.
40 .TP
41 .B \-\-for\-cpp
42 Generate C++ code.
43 .TP
44 .B \-\-no\-extern\-c
45 Never add the extern "C" to the header.
46 .TP
47 .B \-\-no\-gnu
48 Never generate any code with GNU C extensions.  However all the GNU C
49 extensions are always wrapped in #ifdef __GNUC__, so code using them compiles
50 correctly even on non-GNU compilers.  This option is for purists only.
51 (using GNU extensions some warnings are eliminated, some ugly hacks and there
52 is better argument type safety, so it\'s good to use them)
53 .TP
54 .B \-\-no\-touch
55 Don\'t touch output files unless they really
56 changed (implies \-\-no\-touch\-headers).  Be careful with automake, see section
57 PREVENTING SPURIOUS BUILDS.
58 .TP
59 .B \-\-no\-touch\-headers
60 Don\'t touch the generated header file unless it really changed, this avoids
61 spurious rebuilds, but can confuse some make systems (automake in particular),
62 so it is not enabled by default.  Private header is still touched even if
63 unchanged however.
64 .TP
65 .B \-\-always\-private\-header
66 Always create a \fB<basename>-private.h\fR file, even if it would be empty.
67 .TP
68 .B \-\-ondemand\-private\-header
69 Create the private header only if it would have something in it, that is,
70 if there are some private data members or protected methods.
71 This is the default.
72 .TP
73 .B \-\-no\-private\-header
74 Never create a private header file.  If we use any private data members,
75 define the private data structure at the point in the .c source where
76 the class definition begins.
77 .TP
78 .B \-\-m4
79 Preprocess source with m4. Following args will be passed to m4.
80 .TP
81 .B \-\-m4\-dir
82 Print directory that will be searched for m4 files.
83 .TP
84 .B \-n \-\-no\-write
85 Do not write any output files, just check syntax of the input file.
86 .TP
87 .B \-\-no\-lines
88 Do not print out the \'#line\' statements into the output.  Useful for debugging
89 the auto-generated generated code.
90 .TP
91 .B \-\-no\-self\-alias
92 Do not create the Self and SelfClass type aliases and the SELF, IS_SELF
93 and SELF_CLASS macros.
94 .TP
95 .B \-\-no\-kill\-underscores
96 Do not remove the initial underscore from method names.
97 .TP
98 .B \-\-always\-private\-struct
99 Always include the private pointer in the public header file.  This is useful
100 for files which are part of a library and you want to reserve the right to add
101 some private data members without breaking binary compatibility.
102 .TP
103 .B \-o \-\-output\-dir
104 The directory into which output should be placed.
105 .TP
106 .B \-\-file\-sep[=c]
107 Replace default \'\-\' file name separator.  If no separator character
108 is given then none is used.  Only one character can be used.
109 .TP
110 .B \-\-gtk3
111 Use gtk3.
112
113 .SH TYPENAMES
114 .PP
115 Because we need to parse out different parts of the typename, sometimes you
116 need to specify the typename with some special syntax.  Types are specified in
117 capitalized form and words are separated by \':\'.  The first word of the type
118 (which can be empty) is the "namespace".  This fact is for example used for the
119 type checking macro and the type macro.  For "Gtk:New:Button", the macros will
120 be GTK_IS_NEW_BUTTON and GTK_TYPE_NEW_BUTTON.  This colon separated format of
121 typenames is used in the class declaration header and for method argument
122 types.
123
124 .SH OUTPUT FILES
125 .PP
126 The filenames are created from the typename.  The words are
127 separated by \'\-\' (this can be changed with
128 \fB\-\-file\-sep\fR option) and all in lower case.  For example for an object named
129 "Gtk:New:Button", the files are \fBgtk\-new\-button.c\fR and
130 \fBgtk\-new\-button.h\fR.
131 If you are using C++ mode, the output .c file will in fact be a .cc file.
132 If you have any private data members, a private header file will also
133 be created, called \fB<basename>\-private.h\fR (for the example above it
134 would be gtk\-new\-button\-private.h).
135 The public header file is created to be human readable and to be used as a
136 reference to the object.  The .c source file is not created as a human
137 readable source and is littered with #line statements, which make the
138 compiler attempt to point you to the right line in your .gob file in
139 case of parsing errors.  The output should not be edited by hand, and
140 you should only edit the .gob file.
141
142 .SH INCLUDING NORMAL C CODE IN THE OUTPUT FILES
143 .PP
144 To include some code directly in the output C file begin with \'%{\'
145 on an empty line and end the code with a \'%}\' on an empty line.  These
146 sections will appear in the output files in the order they are given.
147 There are several other \fIsections\fR to which you can put code.  You can
148 put it in the \'header\' section (which can be abbreviated \'h\') and it will
149 go into the public header file.  You can also put it in the \'privateheader\'
150 section (abbreviated \'ph\') which will make the code go into the private
151 header file.  Sometimes you want some code (other includes) to appear before
152 the extern "C" and the protecting define.  To do this you can put them
153 into the \'headertop\' (or \'ht\') section.  You may wish to include code or
154 comments in all the files, which you can do by putting them into the \'all\'
155 (or \'a\') section.  Similarly, code you wish to appear at the top of all
156 files go in the \'alltop\' (or \'at\') section.  When you want code
157 to appear as in alltop but only in the cfile you use the \'ctop\' (or \'ct\')
158 section.  Note that ctop requires 2.0.18.   Finally,
159 \'afterdecls\' includes code between the declarations and the method
160 implementations, but note that \'afterdecls\' requires version 2.0.16.
161 For example:
162 .nf
163
164   %alltop{
165         /* this will be at the very top of all output files */
166   %}
167
168   %ctop{
169         /* this will be at the very top of the C file */
170         /* Requires 2.0.18 */
171   %}
172
173   %headertop{
174         /* this will be on top of the public header */
175   %}
176
177   %privateheader{
178         /* this will go into the private header file */
179   %}
180
181   %h{
182         /* will be included in the header */
183         void somefunc(int i);
184   %}
185
186   %a{
187         /* will be included in all files */
188   %}
189
190   %afterdecls{
191         /* between the declarations and the method implementations */
192         /* Requires gob version 2.0.16 */
193   %}
194
195   %{
196         /* will be included in the C file */
197         void somefunc(int i)
198         {
199               /* some code */
200         }
201   %}
202
203 .fi
204
205 .SH INCLUDE FILES
206 .PP
207 Gob will automatically include the class header file at the top of the .c 
208 source file.  If you wish to include it somewhere else, put the include
209 into some %{ %} section above the class definition, and gob will not include
210 it automatically.  This way you can avoid circular includes and control
211 where in the file do you want to include the header.
212 .PP
213 If you made any data members private, gob will also create a source file
214 that will be called \fB<basename>\-private.h\fR.  Same rule as above applies
215 for this just as it does for the regular header file.  If you do explicitly
216 include the regular header file, you should always include this private
217 header file below it.  That is, if you use any private data members.  If you
218 don\'t, the private header file automatically includes the public header file,
219 and thus the public header file will be indirectly included at the very top
220 of the file.
221
222 .SH THE CLASS HEADER
223 .PP
224 There can be only one class per input file.  Defining a class
225 is sort of like in Java, you define the class and write inline code
226 directly into the class definition.  To define a class you need to specify
227 the new object name and the name of the object from which it is derived
228 from, such as this "class <new type> from <parent type> { <class code> }".
229 For example:
230 .nf
231
232   class Gtk:New:Button from Gtk:Button {
233           <class code>
234   }
235
236 .fi
237 .PP
238 To make an abstract class (to pass G_TYPE_FLAG_ABSTRACT) add \'(abstract)\'
239 before the curly braces above.  This works since version 2.0.13.
240
241 .PP
242 To make a simple dynamic class which can be registered with a GTypeModule,
243 add \`(dynamic)\' to the class header.
244 This will cause a type registration method to be defined, which you would
245 normally call from the load method of a GTypeModule.
246 In the above example, the registration function will look like
247 .nf
248
249   void gtk_new_button_register_type(GTypeModule *type_module)
250
251 .fi
252 .SH DATA MEMBERS
253 .PP
254 There are five types of data members.  Three of them are normal data members,
255 one is class wide (global) in scope and one is a virtual one, usually linked to
256 a normal data member or a class wide data member.  The three normal data
257 members are public, protected and private.  Public and protected are basically
258 just entries in the object structure, while private has it\'s own dynamically
259 allocated private structure.  Protected members are always put after the public
260 one in the structure and are marked protected in the header file.  There is
261 only one identifier allowed per typename unlike in normal C.  Example:
262 .nf
263
264   public int i;
265   private GtkWidget *h;
266   protected long k;
267
268 .fi
269 .PP
270 Public and protected data members are accessed normally as members of
271 the object struct.  Example where \'i\' is as above a public data member:
272 .nf
273
274   object\->i = 1;
275
276 .fi
277 .PP
278 The private data members are defined in a structure which is only available
279 inside the .c file, or by including a private header file.  You must access
280 them using the structure _priv.  Example
281 where \'h\' is the private data member (as in the above example):
282 .nf
283
284   object\->_priv\->h = NULL;
285
286 .fi
287 The _priv structure is defined in the \fB<basename>\-private.h\fR.
288 This file is automatically included if you don\'t include it yourself.  You
289 should always explicitly include it in your .gob file if you explicitly also
290 include the main header file.  The reason it is a separate header file is
291 that you can also include it in other places that need to access this objects
292 private data, such as if you have the majority of functionality of an object
293 in a separate .c file.  Or if a derived object needs to access the protected
294 methods.
295 .PP
296 In case you use the \fB\-\-no\-private\-header\fR option, no
297 private header file is created and you can only access the _priv pointer
298 below the class definition in the .gob file.
299 .PP
300 Also note that this structure is dynamically allocated, and is freed in the
301 finalize handler.  If you override the finalized handler, your code will be
302 run first and only then will the _priv structure be freed.
303 .PP
304 .B "Classwide data members:"
305 .PP
306 Sometimes you want a datamember to be shared by all objects.  You then need
307 the "classwide" scope keyword.  So for example the following adds a global
308 member foo:
309 .nf
310
311   classwide int foo;
312
313 .fi
314 To access the member you can use the SELF_GET_CLASS macro (or
315 YOUR_OBJECT_NAME_GET_CLASS) to get at the class.
316 Thus the following would work:
317 .nf
318
319   SELF_GET_CLASS(object)\->foo = 20;
320
321 .fi
322 .PP
323 .B "Automatic Initialization:"
324 .PP
325 You can automatically initialize the public private and protected data members
326 without having to add an init method.  The advantage here is that
327 initialization is kept close to the definition of the data member and thus
328 it\'s easier to check.  To do this, just add a \'=\' followed by a number or
329 a token.  It is also possible to include arbitrary C code for more elaborate
330 initializations by putting it all in curly braces.  Note that the curly braces
331 will not be printed into the output, but since gob does not C parsing it needs
332 them to figure out where the C code ends.  The code will be inserted into the
333 init method, above the user defined body.  So for example the following
334 will initialize an integer to \-1 and a string with a newly allocated string
335 of "hello".
336 .nf
337
338   public int foo = \-1;
339   private char *bar = {g_strdup("hello")};
340
341 .fi
342 .PP
343 .B "Automatic Destruction:"
344 .PP
345 Most data stored as pointers needs to have a function called when the object
346 is finalized to either free the data.  Gob will let you
347 define a function to be called on the data the object is finalized.  This is
348 achieved by putting \'destroywith\' followed by a function name after the
349 variable definition.  It is only called if the data you defined this on
350 is not NULL, so you cans specify functions which do not handle NULL.  It
351 is very much like the GDestroyNotify function used in GTK+ and glib in many
352 places.  Unlike many other places, gob will not enforce any kind of type
353 safety here so be a little bit more careful.  Any function you give it will
354 be called as a "void function(void *)".  It will in fact be cast into such
355 a form before called.  This is to avoid spurious warnings for gtk calls to
356 subclass methods.  The function needs not be of that form exactly, it just has
357 to take one argument which is the pointer to the data.  You should also not
358 define this on any non-pointer data as the results may be undefined.
359 Example:
360 .nf
361
362   public char *foo = {g_strdup("bar")}
363           destroywith g_free;
364
365 .fi
366 Note that the function name you give must be a real function and not macro.
367 Also note that this is always called in the "finalize" method of GObject.
368 It is always called after any user defined body of the finalize handler.
369 .PP
370 Sometimes you may want to run arbitrary code on destruction.  While this can
371 be perfectly well done in the finalize handler.  Depending on the style you
372 may want to include all destruction/initialization code together with the
373 definition of the data member.  Thus you may want to put arbitrary code which
374 will then be inserted into the "finalize" method of GObject.  This can be
375 done with the "destroy" keyword followed by arbitrary code in curly braces.  
376 Inside this code a macro called VAR will be define which refers to your
377 variable.  So for example destroying a GString can be either done with
378 a helper routine or the following code:
379 .nf
380
381   public GString *string = {g_string_new(NULL)}
382           destroy {
383                   if(VAR) g_string_free(VAR, TRUE);
384           };
385
386 .fi
387 The thing to remember with these is that there are many ways to do this
388 and you\'d better be consistent in your code in how you use the above things.
389 Also defining a helper routine that will do the destruction will be a nicer
390 thing to do if that\'s a possibility.  The "destroy" keyword with code does
391 take up more space in the file and it may become more cluttered.
392 .PP
393 The data is zeroed out after being destroyed.  This is to make debugging easier
394 in case your code might try to access an already finalized object.  In case
395 you have overridden the finalize method, your code will be run first and
396 only then will the destructors be called.  You should not however make any
397 assumptions about the order at which the destructors are called.  If you have
398 interdependencies between destructors for different data members, you will
399 have to do this in your own finalize override function.
400 .PP
401 .B "Automatic Unreffing:"
402 .PP
403 This is very much like the automatic destruction, but is instead run in the
404 dispose method (it is among other places called from the "destroy" method of
405 GtkObject).  All data and other objects that you need to unref should be
406 done here, and not at finalize time.  The semantics are otherwise the same
407 as for the "destroywith" and "destroy" keywords, except that you use
408 "unrefwith" and "unref".
409 .nf
410
411   public G:Object *foo = NULL
412           unrefwith g_object_unref;
413   public G:Object *bar = NULL
414           unref {
415                 g_object_unref (VAR);
416           };
417
418 .fi
419
420 .SH GOBJECT PROPERTIES
421 .PP
422 The fourth type of a data member a property type.  It is a named data member
423 which is one of the features of the GObject system.  It just defines a way to
424 get and set some data, but you have to take care of storing that data
425 somewhere.  So it is normal to also have a normal private (or public)
426 data member where you store the real data.
427 You normally need to define a
428 get and a set handler.  They are fragments of C code that will be used to get
429 the value or set the value of the argument.  Inside them you can use the define
430 VAL to which you assign the data or get the data.  You should treat this VAL
431 as a GValue which stores the data of the correct type.
432 You can also use the
433 identifier "self" as pointer to the object instance.  The type is defined as
434 one of the GObject type enums, but without the G_TYPE_ prefix.  There are
435 also some attributes of a property which you can set.  For example the
436 following is a definition of an integer property \'height\' which will
437 be synchronized with a private integer data member also of the name \'height\'.
438 .nf
439
440   private int height;
441   property INT height
442          (
443           name = "height",
444           nick = _("Short nickname"),
445           blurb = _("Long description"),
446           minimum = 10,
447           maximum = 200,
448           default_value = 100)
449         set { self\->_priv\->height = g_value_get_int (VAL); }
450         get { g_value_set_int (VAL, self\->_priv\->height); };
451
452 .fi
453 .PP
454 The attributes are really optional though you should at least set some
455 of them.
456 All property types have a \'nick\' and a \'blurb\' attribute and you should
457 set those accordingly.  This will make runtime querying the object
458 nicer as things such as gui editors and class browsers can be more
459 verbose about the class itself.
460 .PP
461 The \'name\' property is canonical name of property. It is useful when you try to
462 implement properties with no C names like \'vertical-scroll\'. The \'name\'
463 property can be omitted.
464 .PP
465 You can use the \'_("string")\' notation
466 instead of just "string", and that will mark the string for translation.
467 .PP
468 Almost all types also have a \'default_value\' attribute which sets the initial
469 value of this property (on object initialization, the set handler will be run
470 automatically with this value).  This value will be overridden if the user 
471 sets a value of this property on the call to g_object_new.
472 .PP
473 All the numeric types (including CHAR) have \'minimum\' and \'maximum\'
474 attributes which can restrict the range.  If you do not specify these
475 the range will be the full range that the data type can handle.
476 .PP
477 Types such as UNICHAR and BOOLEAN only have the \'nick\', \'blurb\' and
478 \'default_value\' attributes.
479 .PP
480 The ENUM type has an \'enum_type\' attribute which is the exact
481 type of the enum.  This is so that the property knows which exact
482 type you can set, rather then just knowing it is an enum.  You should
483 always create an enum type specific for the enum itself (see section
484 on the enum types)
485 .PP
486 Similarly FLAGS type has a \'flags_type\' which again you should set to
487 the specific type of this flags data member.
488 .PP
489 There is a STRING type which has only the extra \'default_value\' attribute.
490 .PP
491 The OBJECT type is one of the types that doesn\'t have a \'default_value\' and it
492 only has an \'object_type\' attribute (in addition to nick and blurb of course)
493 that is the exact object type that this property accepts.  The object_type
494 should be as a type, that is for example \'Gtk:Button\'.
495 .PP
496 There is a BOXED type which is a pointer which has a boxed type defined
497 (such that GObject knows how to copy and destroy this pointer).  Here
498 you will need to specify the \'boxed_type\' attribute with the specific
499 type of the boxed pointer.
500 .PP
501 There is also a POINTER type, which has only the \'nick\' and \'blurb\'
502 attributes.  This is for storing arbitrary pointers.  You should be
503 careful with this one, as GObject knows nothing about the data
504 stored at this pointer.  It is somewhat like a \'void *\' type.
505 .PP
506 There is also the PARAM type for storing parameters with a \'param_type\'
507 attribute.
508 .PP
509 You should notice that this list is pretty much like the list of g_param_spec_*
510 functions from gobject/gparamspecs.h, and the attributes are like the
511 arguments of those functions.  Note however that value array is NOT supported
512 yet.
513 .PP
514 You can also specify extra flags, such as CONSTRUCT or CONSTRUCT_ONLY using the
515 \'flags\' attribute.  You can specify multiple flags by oring them together with
516 \'|\'.  These flags correspond to the GParamFlags enumeration except do not
517 include the G_PARAM_ prefix.  So for example to define an enumeration property,
518 which is a CONSTRUCT_ONLY property, we could do the following:
519 .nf
520
521   private SomeEnumerationType foo;
522   property ENUM foo
523          (nick = _("Short nickname"),
524           blurb = _("Long description"),
525           enum_type = Some:Enumeration:Type
526           default_value = SOME_ENUMERATION_VALUE,
527           flags = CONSTRUCT_ONLY,
528           link);
529
530 .fi
531 .PP
532 The above example also gives an example of automatic linking to a standard data
533 memember.  By including the attribute \'link\' a get and set handlers will be
534 automatically added without having to type them by hand.  This is useful for a
535 vast majority data types that are just linked to some standard data member and
536 do not need to do anything extra on get or set.
537 .PP
538 Another extra feature of properties is the possibility of automatically
539 exporing methods to get and set the property.  That is without having to
540 use g_object_set and g_object_get.  This is achieved by adding an
541 \'export\' attribute to the list of property attributes.
542 .PP
543 If you do not define a set or get handler, the property will automatically
544 be only readable or writable as appropriate.
545 .PP
546 Gob2 also creates macros which can be used for type safe access to
547 properties through g_object_set and g_object_get.
548 The macros are called <type>_PROP_<argument name>(x) and
549 <type>_GET_PROP_<argument name>(x).  They define both the string and the
550 value part of the argument.  So for setting an argument of height, one would
551 use (for object type My:Object):
552 .nf
553
554   g_object_set (G_OBJECT (object),
555                 MY_OBJECT_PROP_HEIGHT (7),
556                 NULL);
557
558 .fi
559 And for getting, you would use:
560 .nf
561
562   int height;
563   g_object_get (G_OBJECT (object),
564                 MY_OBJECT_GET_PROP_HEIGHT (&height),
565                 NULL);
566
567 .fi
568 Note however that the type safety only works completely on GNU C compilers.
569 The code will compile on other compilers but with minimal type safety.
570 For complete type safety it is useful to use the get/set methods that
571 are defined by using the \'export\' attribute.
572 .PP
573 To get bettery type safety on some of the property types, you can specify
574 the \'type\' attribute which will add casts where appropriate in code dealing
575 with this property.  This is especially useful for POINTER and OBJECT types.
576 But even for others.
577 .PP
578 You can also override properties from parent objects (that is override their
579 implementation, not their attributes).  Do this by adding the
580 special \'override\' attribute.  For example if the parent object
581 had a \'height\' property then you could override it by
582 .nf
583
584   private int height;
585   property INT height
586          (override)
587         set { self\->_priv\->height = g_value_get_int (VAL); }
588         get { g_value_set_int (VAL, self\->_priv\->height); };
589
590 .fi
591 Overriding is supported since gob 2.0.10.
592
593 .SH METHODS
594 .PP
595 There is a whole array of possible methods.  The three normal,
596 "familiar" method types are private, protected and public.  Public are
597 defined as normal functions with a prototype in the header file.  
598 Protected methods are defined as normal methods (which you can call from other
599 files), but their prototype is placed in the private header file.  Private
600 methods
601 are defined as static functions with prototypes at the top of the .c
602 file.  Then there are signal, virtual and override methods.  More on those
603 later.  You can also
604 define init and class_init methods with a special definition if you want
605 to add code to the constructors or you can just leave them out.
606 You can also not define a body for a method, by just using \';\' instead of a
607 body.  This will define an empty function.  You can\'t do this for non-void
608 regular public, private or protected methods, however it is acceptable for
609 non-void virtual, signal and override methods.
610 .PP
611 .B "Function argument lists:"
612 .PP
613 For all but the init and class_init methods, you use the
614 following syntax for arguments.  The first argument can be just "self",
615 which gob will translate into a pointer to the object instance.  The rest
616 of the arguments are very similar to normal C arguments.  If the
617 typename is an object pointer you should use the syntax defined above
618 with the words separated by \':\'
619 .nf
620 <type> <argument id>
621 or
622 <type> <argument id> (check <list of checks>)
623 .fi
624 .PP
625 The checks are glib type preconditions, and can be the following:
626 "null", which tests pointers for being NULL, "type" which checks GTK+
627 object pointers for being the right type, "<test> <number>" which tests
628 numeric arguments for being a certain value.  The test can be a <,>,<=,>=
629 != or ==.  Example:
630 .nf
631   
632   public int
633   foo (self,
634        int h (check > 0 < 11),
635        Gtk:Widget *w (check null type))
636
637 .fi
638 .PP
639 This will be the prototype of a function which has a self pointer
640 as the first argument, an integer argument which will be checked and has
641 to be more then 0 and less then 11, and a pointer to a GtkWidget object
642 instance and it is checked for being null and the type will also be
643 checked.
644 .PP
645 .B "Function attributes:"
646 .PP
647 For method that aren't virtual, signal or override methods, and aren't
648 init or class_init, GLib function attribute macros G_GNUC_PRINTF,
649 G_GNUC_SCANF, and G_GNUC_FORMAT can optionally be included after the
650 argument list.  Simply include an \'attr\' keyword and the C code to include
651 in the file.  You have to include braces and anything inside the braces
652 will be printed into the header file after the function declaration and
653 before the trailing semicolon.  The braces themselves are not printed.
654 For example:
655 .nf
656
657   public void
658   print (self, const char *format (check null), ...)
659     attr {G_GNUC_PRINTF(2, 3)}
660
661 .fi
662 .PP
663 This will produce a prototype which will generate a warning at compile
664 time if the contents of the format argument (argument number 2) aren't
665 consistent with the types and number of the subsequent variadic
666 arguments (the first of which is argument number 3).  Only one \'attr\'
667 keyword per method is allowed.
668 If you have more than one attribute to include, you should
669 put them all within the braces.
670 Note that function attributes were aded in version 2.0.16.
671 .PP
672 .B "Error return:"
673 .PP
674 Methods which have a return value, there also has to be something
675 returned if there is an error, such as if a precondition is not met.
676 The default is 0, casted to the type of the method.  If you need to
677 return something else then you can specify an \'onerror\' keyword after
678 the prototype and any optional function attribute macros, and after
679 that a number, a token (an identifier) or a bit of C code enclosed in
680 braces {}.  The braces will not be printed into the output, they just
681 delimit the string.  For example:
682 .nf
683
684   public void * get_something (self, int i (check >= 0)) onerror NULL {
685           ...
686   }
687
688 .fi
689 The onerror value is also used in overrides that have a return value, in
690 case there isn\'t a parent method, PARENT_HANDLER will return it.  More about
691 this later.
692 .PP
693 .B "Default return:"
694 .PP
695 Some signal and virtual methods have a return type.  But what happens if
696 there is no default handler and no one connects to a signal.  GOB2 will
697 normally have the wrappers return whatever you specify with onerror or \'0\'
698 if you haven\'t specified anything.  You can also specify a default
699 return value with the keyword \'defreturn\'.  It\'s use is identical to the
700 use of onerror, and you can in fact use both at the same time.  Example
701 .nf
702
703   virtual int get_some_int (self) onerror \-1 defreturn 10 ;
704
705 .fi
706 That is an empty virtual method (in C++ terms a pure virtual).  If you never
707 specify any handler for it in the derived children it will just return 10.
708 .PP
709 .B "Constructor methods:"
710 .PP
711 There are two methods that handle the construction of an object, init and
712 class_init.  You define them by just using the init or class_init keyword 
713 with an untyped argument in the argument list.  The argument will be
714 usable in your function as a pointer to your object or class depending if
715 it\'s init or class_init.
716 For example:
717 .nf
718
719   init (self) {
720           /* initialize the object here */
721           self\->a = 9;
722           self\->b = 9;
723   }
724
725   class_init (class) {
726           /* initialize the class, this is rarely needed */
727           class\->blah = NULL;
728   }
729
730 .fi
731 The class_init function is very rarely needed as all standard class
732 initialization is taken care of for you by gob itself.  The init function
733 should on the other hand be used whenever you need to construct or initialize
734 anything in the object to put it into a sane state.
735 .PP
736 .B "Constructor, dispose, finalize methods:"
737 .PP
738 Since 2.0.16, you can also easily add code to the object's constructor,
739 dispose, and finalize methods.  See GObject documentation on how these are
740 run.  The code you add will be run before calling the parents function
741 for dispose and finalize, and after the parent function for constructor.
742 The syntax is just like init and class_init.
743 For example:
744 .nf
745
746   constructor (self) {
747         /* constructor method */
748   }
749
750   dispose (self) {
751         /* dispose method */
752   }
753
754   finalize (self) {
755         /* finalize method */
756   }
757
758 .fi
759 You can also just override those methods as usual, but the above is much easier and nearly as flexible.
760 .PP
761 .B "Virtual methods:"
762 .PP
763 Virtual methods are basically pointers in the class structure,
764 so that one can override the method in derived methods.  That is to implement
765 the method in a derived class, you must then use an override method (more
766 on those later).
767 They can be empty
768 (if you put \';\' instead of the C code).  A wrapper will also be defined
769 which makes calling the methods he same as public methods.  This type of
770 method is just a little bit "slower" then normal functions, but not as
771 slow as signals.  You define them by using "virtual" keyword before the
772 prototype.  If you put the keyword "private" right after the "virtual"
773 keyword, the wrapper will not be a public method, but a private one.
774 You can do the same with "protected" to make a protected wrapper.
775 .PP
776 .B "Signals:"
777 .PP
778 Signals are methods to which the user can bind other handlers
779 and override the default handler.  The default handler is basically the
780 method body.  This is the most versatile and flexible type of a method
781 and also the slowest.  You need to specify a whole bunch of things when
782 you define a signal.  One thing is when the default handler will be run,
783 first or last.  You specify that by "first" or "last" right after the
784 "signal" keyword.  Then you need to define the GObject enum types (again
785 without the G_TYPE_ prefix).  For that you define the return types
786 and the types of arguments after the "self" pointer (not including the
787 "self" pointer).  You put it in the following syntax "<return type> (<list
788 of arguments>)".  If the return type is void, the type should be "NONE",
789 the same should be for the argument list.  The rest of the prototype is
790 the same as for other method types.  The body can also be empty, and
791 also there is a public method wrapper which you can use for calling the
792 signal just like a public method.  Example:
793 .nf
794
795   signal first INT (POINTER, INT)
796   int do_something (self, Gtk:Widget *w (check null type), int length)
797   {
798           ...
799   }
800   
801 .fi
802 or
803 .nf
804
805   signal last NONE (NONE) void foo (self);
806
807 .fi
808 .PP
809 You can include name of signal, if this name is not a C variable name. Example:
810 .nf
811
812   signal first INT "do-something" (POINTER, INT)
813   int do_something (self, Gtk:Widget *w (check null type), int length)
814   {
815           ...
816   }
817   
818 .fi
819 .PP
820 If you don\'t want the wrapper that emits the signal to be public, you can
821 include the keyword "private" after the "signal" keyword.  This will make
822 the wrapper a normal private method.  You can also make a protected wrapper
823 by using "protected" instead of "private".
824 .PP
825 If you don\'t define a "first" or a "last", the default will be taken as
826 "last".
827 .PP
828 You can also add additional flags.  You do this just like with the argument
829 flags, although this is probably very rare.  These are the G_SIGNAL_* flags,
830 and you can add them without the G_SIGNAL_ prefix into a parenthesis, just
831 after the "signal" keyword.  By default all public signals are G_SIGNAL_ACTION.
832 .PP
833 Also gob2 creates a wrapper macros for typesafe signal connection.  That is
834 you will be warned by the compiler if you pass a callback that is not the
835 correct prototype.  This will again only warn you on gcc, but it will
836 compile without warning on another compiler.  So as with all the typesafety
837 hacks in gob, it is better to test your objects under gcc to get any warnings
838 even if you are using a different compiler in the end.
839 .PP
840 The methods that are created for you are:
841 .nf
842
843   <class_name>_connect__<signal_name> (<object>, <callback>, <data>)
844   <class_name>_connect_after__<signal_name> (<object>, <callback>, <data>)
845   <class_name>_connect_data__<signal_name> (<object>, <callback>, <data>,
846                                             <destroy_notify>, <flags>)
847
848 .fi
849 .PP
850 These three functions correspond to the g_signal_connect,
851 g_signal_connect_after and g_signal_connect_data functions that you would
852 normally use, except they are for a specific signal.  Also do note
853 the two underscores between the method name and the signal name.  For
854 example to connect the signal "foo" on the object "Test:Object" you
855 would do:
856 .nf
857
858   test_object_connect__foo (object, callback, data);
859
860 .fi
861 .PP
862 To use BOXED in the signal arguments you need to tell gob which type of boxed
863 argument you want to use.  For this you can just add BOXED_GTK_TYPE_STRING
864 instead of BOXED.  For example BOXED_GTK_TYPE_TREE_ITER for GtkTreeIter.
865 This works since version 2.0.13.
866 .PP
867 .B "Override methods:"
868 .PP
869 If you need to override some method (a signal or a virtual method
870 of some class in the parent tree of the new object), you can define and
871 override method.  After the "override" keyword, you should put the
872 typename of the class you are overriding a method from.  Other then that
873 it is the same as for other methods.  The "self" pointer in this case
874 should be the type of the method you are overriding so that you don\'t
875 get warnings during compilation.  Also to call the method of the parent
876 class, you can use the PARENT_HANDLER macro with your arguments.  Example:
877 .nf
878
879   override (Gtk:Container) void
880   add (Gtk:Container *self (check null type), Gtk:Widget *wid (check null type))
881   {
882           /* some code here */
883           PARENT_HANDLER(self, wid);
884   }
885
886 .fi
887 If the function has a return value, then PARENT_HANDLER is an expression that
888 you can use.  It will return whatever the parent handler returned, or the
889 "onerror" expression if there was no parent handler.
890 .PP
891 .B "Method names:"
892 .PP
893 Inside the code, aliases are set for the methods, so that you don\'t
894 have to type the class name before each call, just type \fBself_\fR instead
895 of the name of the class.  So to call a method called \fBblah\fR, you
896 would use the name \fBself_blah\fR.
897 Example:
898 .nf
899
900   private int
901   foo (self)
902   {
903           return self\->len;
904   }
905   
906   private int
907   bar (self, int i)
908   {
909           return self_foo (self) + i;
910   }
911
912 .fi
913
914 .SH MAKING NEW OBJECTS
915 .PP
916 You should define a new method which should be a normal public method.  Inside
917 this method, you can use the GET_NEW macro that is defined for you and that
918 will fetch a new object, so a fairly standard new method would look like:
919 .nf
920
921   public GObject *
922   new (void) {
923           GObject *ret = GET_NEW;
924           return G_OBJECT (ret);
925   }
926
927 .fi
928 .PP
929 You should not a subtle peculiarity of the GObject system here.  If there is
930 any code inside the G_OBJECT macro argument, it will get executed multiple
931 times.  This means that things such as G_OBJECT(GET_NEW) would actually create
932 4 objects, leaking 3 of them.  A good rule (as with anywhere in C) is to be
933 careful with all macros.
934
935 .SH SELF REFERENCES
936 .PP
937 .B "Self alias casts:"
938 .PP
939 There are some standard casts defined for you.  Instead of using the full
940 macros inside the .c file, you can use SELF, IS_SELF and SELF_CLASS.  Using
941 these makes it easier to for example change class names around.
942 .PP
943 .B "Self alias types:"
944 .PP
945 There are also the Self and SelfClass types inside
946 your .c file.  These serve the same function as the above, they make it easier
947 to type and easier to change typenames around which can help a lot during
948 prototyping stage.  However you should note that the Self type should not be
949 used in function prototypes as one of the arguments or as a return value type.
950 This is because this is a simple C typedef which is only available inside your
951 \&.c file and not in the header files.  You can disable both the self casting
952 macros and the self type aliases by passing \-\-no\-self\-alias to gob.
953
954 .SH DEALING WITH DIFFERENT GOB VERSIONS
955 .PP
956 .B "Defines:"
957 .PP
958 In your generated C file, you can use the defines GOB_VERSION_MAJOR
959 GOB_VERSION_MINOR and GOB_VERSION_PATCHLEVEL if you wish to for example
960 use a feature that is only available in some newer gob version.  Note however
961 that you can only use these defines in the C code portions of your .gob file,
962 and #ifdef\'s cannot span multiple functions.  Check the BUGS section
963 for more on using the C preprocessor and gob.
964 .PP
965 .B "Minimum version requires:"
966 .PP
967 You can also make your .gob file require at least certain version of gob.  You
968 do this by putting \'requires x.y.z\' (where x.y.z is the version number)
969 outside of any C block, comment or class, usually you should make this the
970 first line in the file or close to the top.  If gob finds this and the version
971 of gob used to compile the code is lower then that listed in the require, gob
972 will generate an error and exit.  For example to require that gob2 version
973 2.0.0 or higher be used to compile a file, put this at the top of that file:
974 .nf
975
976   requires 2.0.0
977
978 .fi
979
980 .SH CREATING NEW ENUM, FLAGS and ERROR TYPES
981 .PP
982 You can create new GObject ENUM, FLAGS and GError types for use in your
983 classes easily.  Glib includes some utilities for handling these, however
984 it may be cleaner to use the below specified way in your classes.  It also
985 then doesn\'t require any Makefile setup.  Make sure this is defined in the
986 same section as the class, that is not in any of the \'%?{\' \'%}\' sections.
987 .PP
988 You use the keywords \'enum\' \'flags\' and \'error\' as you would use the
989 \'class\' keyword.  Then you give a prefix for the values in the enumeration.
990 Then you define a list of values just like in C.  For \'enum\' types you can
991 also specify the values assigned to each string.  Then you specify the type in
992 the standard gob style of specifying types.  Here are a few examples
993 of all of these:
994 .nf
995
996   enum LAME_CLIENT {
997         IS_CONNECTED,
998         NONE = 9,
999         LAST
1000   } Test:Enum;
1001
1002   flags BUGA_BUGA {
1003         ONE,
1004         TWO,
1005         MANY,
1006   } Some:Flags;
1007
1008   error TEST_OBJECT_ERROR {
1009         BAD_THIS,
1010         BAD_THAT
1011   } Test:Object:Error;
1012
1013 .fi
1014 .PP
1015 This will for example define an enum that is equivalent to the following
1016 C code:
1017 .nf
1018
1019   typedef enum {
1020         LAME_CLIENT_IS_CONNECTED,
1021         LAME_CLIENT_NONE = 9,
1022         LAME_CLIENT_LAST
1023   } TestEnum;
1024
1025 .fi
1026
1027 .SH C++ MODE
1028 .PP
1029 There is a C++ mode so that gob creates C++ compiler friendly files.  You need
1030 to use the \-\-for\-cpp argument to gob.  This will make the generated file have
1031 a .cc instead of a .c extension, and several things will be adjusted to
1032 make it all work for a C++ compiler.  One thing that will be missing is an
1033 alias to the new method, as that clashes with C++, so instead you\'ll have to
1034 use the full name of the method inside your code.  Also note that gob does
1035 not use any C++ features, this option will just make the generated code
1036 compile with a C++ compiler.
1037
1038 .SH OVERRIDING THE GET_TYPE METHOD
1039 .PP
1040 The get_type is not really a method, but a function which initializes your
1041 object.  Recently objects appeared which require you to make a custom
1042 get_type function.  So it is possible
1043 to override this function.  To do so, just define a new public method called
1044 get_type, with no arguments.  Example:
1045 .nf
1046
1047   public GType
1048   get_type (void)
1049   {
1050         /* code goes here */
1051         return some_type;
1052   }
1053
1054 .fi
1055
1056 .SH INTERFACES
1057 .PP
1058 Currently gob will only allow you to implement interfaces (that is, define new
1059 classes which implement an interface) and doesn\'t yet have support for making
1060 new interfaces, but this will be coming at some point in the future.
1061 .PP
1062 To define a class that implements an interface add a class flag \'interface\'
1063 with the type name of the interface as an argument.  Then to implement
1064 a specific method of the interface, just add \'interface <typename>\'
1065 before the method definition.  The method can, and probably should be,
1066 private.
1067 .PP
1068 The following example implements a new object, that implements the
1069 Gtk:Tree:Model interface and implements the get_flags method of that
1070 interface.  Do note that except for standard (GTK+ and glib) specific
1071 interfaces which seem
1072 to have a non-standard name for the interface structure, the structure
1073 should end with and Iface, if you are implementing an interface.  That
1074 is for example for the Gtk:Tree:Model, the structure containing the
1075 table of methods should be named GtkTreeModelIface.
1076 .nf
1077   class Some:Object from G:Object
1078           (interface Gtk:Tree:Model)
1079   {
1080           /* function implemented for the Gtk:Tree:Model interface */
1081           interface Gtk:Tree:Model
1082           private GtkTreeModelFlags
1083           get_flags (Gtk:Tree:Model *self (check null type))
1084           {
1085                 /* Here would be the implementation */
1086                 return (GtkTreeModelFlags)0;
1087           }
1088   }
1089
1090 .fi
1091 .PP
1092 If you want to implement multiple interfaces just list more class flag lines
1093 as follows:
1094 .nf
1095
1096   class Some:Object from G:Object
1097           (interface Gtk:Tree:Model)
1098           (interface Gtk:Editable)
1099   {
1100           /* ... */
1101   }
1102
1103 .fi
1104
1105 .SH DIRECT BonoboObject SUPPORT
1106 .PP
1107 If you want to build a BonoboObject class gob2 has direct support for these.
1108 Just create a new object that derives from
1109 Bonobo:Object.
1110 Then use a "BonoboObject" class flag with the interface name as an
1111 argument.  The interface name should be as you would type it in C, that is with
1112 underscores as namespace separators.  Then you add the methods (using exact
1113 same names as in the idl file) and prepend those methods with a BonoboObject
1114 keyword.  For example imagine you have an interface GNOME/Foo/SomeInterface,
1115 with a method fooBar that takes a single string:
1116 .nf
1117
1118   class Foo:Some:Interface from Bonobo:Object
1119     (BonoboObject GNOME_Foo_SomeInterface) {
1120
1121           BonoboObject
1122           private void
1123           fooBar (PortableServer_Servant servant,
1124                   const CORBA_char *string,
1125                   CORBA_Environment *ev)
1126           {
1127                   Self *self = SELF (bonobo_object_from_servant (servant));
1128
1129                   /* your code here */
1130           }
1131
1132           /* rest of class */
1133   }
1134
1135 .fi
1136 Note that the implementation method can be private, in fact that\'s probably
1137 a good idea to do.  It won\'t work to make this a signal, it can however
1138 be a virtual.  Note that the method prototype must match the one from the
1139 interface header file, or you will get a bad assignment warning.  You should
1140 check the header file generated by orbit\-idl and see the epv structure
1141 for the correct prototypes if you can\'t figure them out from the idl itself.
1142 Also note that the first argument is not "self", but the servant and you must
1143 use bonobo_object_from_servant function to get the actual object pointer.
1144
1145 .SH DIRECT LIBGLADE SUPPORT
1146 .PP
1147 Gob can simplify writing a libglade class.  Just create a new object that
1148 derives from a GtkContainer widget.  Then use a "GladeXML" class flag
1149 with the glade file name, root widget and optional domain  as arguments
1150 between double quotes.  For example:
1151 .nf
1152
1153 class My:Glade from Gtk:Window (GladeXML "gob\-libglade.glade" "root")
1154 {
1155   ....
1156 }
1157
1158 .fi
1159 Note however that then "gob\-libglade.glade" would have to be in the current
1160 directory.  You could specify a path, but that may not work for all
1161 installations.  You can replace the glade filename with a token to be used
1162 in the generated .c file and you can then have a macro with the filename,
1163 as follows:
1164 .nf
1165
1166 class My:Glade from Gtk:Window (GladeXML GLADE_FILE "root")
1167 {
1168   ....
1169 }
1170
1171 .fi
1172 And somewhere in your header files you would have
1173 .nf
1174
1175 #define GLADE_FILE "/path/to/file.glade"
1176
1177 .fi
1178
1179 You can declare widgets as data members by adding a 'GladeXML' to
1180 the definition.
1181 .nf
1182
1183 private Gtk:Button * button1 GladeXML;
1184
1185 .fi
1186 This will automatically set the "button1" from the GladeXML file.
1187
1188 All signals created with glade are automatically connected if you defined
1189 those class methods in your class.  For example suppose in glade that
1190 we set the "connect" signal on button1 to go to on_button1_clicked, then
1191 in our gob file we can just write:
1192 .nf
1193
1194 public void
1195 on_button1_clicked(self, GtkButton * button)
1196 {
1197 }
1198
1199 .fi
1200
1201 See the examples directory for a full example.  Note that this feature
1202 requires version at least 2.0.12.
1203
1204
1205 .SH IDENTIFIER CONFLICTS
1206 .PP
1207 Gob will need to define some local variables and functions in the generated
1208 files, so you need to take some precaution not to conflict with these.  The
1209 general rule of thumb is that all of these start with three underscores.  There
1210 is one, "parent_class" which doesn\'t because it\'s intended for use in your
1211 code.  For virtuals or signals, you cannot use the identifier __parent__
1212 which is used for the parent of the object.  You should actually never access
1213 __parent__ either as it not guaranteed that it will stay named this way.
1214 Data members cannot be named __parent__ nor _priv.  For methods, you cannot
1215 use the identifiers "init" or "class_init" unless you mean the constructor
1216 methods.  You shouldn\'t generally use 3 underscores even in override method
1217 argument lists and virtual and signal method names as it might confuse the
1218 PARENT_HANDLER macro.  In fact avoiding all names with three underscores is
1219 the best policy when working with gob.
1220 .PP
1221 There are a couple of defines which you shouldn\'t be redefining in the code
1222 or other headers.  These are SELF, IS_SELF, SELF_CLASS, SELF_TYPE, ARG, VAR,
1223 PARENT_HANDLER, GET_NEW, GOB_VERSION_MAJOR, GOB_VERSION_MINOR and
1224 GOB_VERSION_PATCHLEVEL.
1225 .PP
1226 As for types, there are Self and SelfClass types which are only defined in your
1227 source files.  Their generation (just like the generation of the SELF macros)
1228 can be turned off, see command line options.
1229
1230 .SH USING GTK\-DOC STYLE INLINE DOCUMENTATION
1231 .PP
1232 If you want to use gtk\-doc style inline documentation for your objects, you
1233 can do one of two things.  First, you could include the inline documentation
1234 comments in your %{ %} section which will then be put verbatim into the
1235 output source file.  This is the way you should use for functions you define
1236 outside of the class.
1237 .PP
1238 For class methods, you should use a gtk+ style comment, however it can be
1239 indented any number of tabs or spaces and you can use the short method name
1240 without the type prefix.  Gob will automatically try to extract these and
1241 translate to full names and put them in the output source file.  An example
1242 would be:
1243 .nf
1244
1245   class Gtk:Button:Example from Gtk:Button {
1246           /**
1247            * new:
1248            *
1249            * Makes a new #GtkButtonExample widget
1250            *
1251            * Returns: a new widget
1252            **/
1253           public
1254           GtkWidget *
1255           new(void)
1256           {
1257                   return (GtkWidget *)GET_NEW;
1258           }
1259   } 
1260
1261 .fi
1262 If the function you are documenting is a signal or a virtual then it will
1263 be documenting the wrapper that starts that virtual function or emits
1264 that signal.
1265
1266 .SH DEALING WITH CIRCULAR HEADERS
1267 .PP
1268 Sometimes you may need to use an object of type MyObjectA in the MyObjectB
1269 class and vice versa.  Obviously you can\'t include headers for both.  So you
1270 need to just declare the typedef in the header of A for B, and the other way
1271 around as well.  The headers generated include a protecting
1272 define before it declares the typedef.  This define is the
1273 __TYPEDEF_<upper case object name>__.  So inside my\-object\-a.h there will be
1274 this:
1275 .nf
1276
1277   #ifndef __TYPEDEF_MY_OBJECT_A__
1278   #define __TYPEDEF_MY_OBJECT_A__
1279   typedef struct _MyObjectA MyObjectA;
1280   #endif
1281
1282 .fi
1283 Now instead of including my\-object\-a.h in the header section of
1284 my\-object\-b.gob, just copy the above code there and you\'re set for using
1285 MyObjectA as a type in the method parameters and public types.
1286 .PP
1287 Another way to get out of this problem is if you can use those types only
1288 in the private members, in which case they won\'t be in the generated public
1289 header.
1290
1291 .SH BUILDING WITH MAKE
1292 .PP
1293 If you are using normal makefiles, what you need to do is to add a generic
1294 rule for .gob files.  So you would include the following in the Makefile
1295 and then just use the .c and .h files as usual (make sure the space
1296 before the \'gob2\' is a tab, not spaces):
1297 .nf
1298
1299   %.c %.h %\-private.h: %.gob
1300           gob2 $<
1301
1302 .fi
1303
1304 .SH BUILDING WITH AUTOCONF and AUTOMAKE
1305 .PP
1306 This is a little bit more involved.  Basically the first thing to do is to
1307 check for GOB2 in your configure.in file.  You can use the supplied m4 macro
1308 which will also check the version of gob.  Basically you include this:
1309 .nf
1310
1311   GOB2_CHECK([2.0.0])
1312
1313 .fi
1314 This will replace @GOB2@ in your makefiles with the full path of gob2.  Thus
1315 when adding the generic rule to your Makefile.am file, it should look like:
1316 .nf
1317
1318   %.c %.h %\-private.h: %.gob
1319           @GOB2@ $<
1320
1321 .fi
1322 .PP
1323 For Makefile.am you have to set up a couple more things.  First you have to
1324 include the generated .c and .h files into BUILT_SOURCES variable.  You
1325 have to include both the .gob and the .c and .h files in the SOURCES for your
1326 program.
1327
1328 .SH PREVENTING SPURIOUS BUILDS
1329 .PP
1330 When nothing has changed you might not really want to rebuild everything and
1331 gob provides options \-\-no\-touch (since 2.0.13) and \-\-no\-touch\-headers to avoid
1332 this.  When working with build systems such as automake you have to be more
1333 careful as just using those options can cause automake to get confused and you
1334 will need to use something like the following:
1335 .nf
1336
1337   foo_SOURCES = foo.gob foo.gob.stamp foo.c foo.h foo\-private.h
1338   BUILT_SOURCES = foo.gob.stamp
1339   MAINTAINERCLEANFILES = foo.gob.stamp
1340
1341   %.gob.stamp: %.gob
1342           @GOB2@ \-\-no\-touch $<
1343           @touch $@
1344
1345 .fi 
1346
1347 .SH DEBUGGING
1348 .PP
1349 GOB does several things to make debugging the code easier.  First it adds
1350 preprocessor commands into the output c file that point to the correct places
1351 in your .gob input file.  However sometimes there might be some bigger
1352 confusion and this is just not helpful.  In this case you will probably want
1353 to have gcc point you directly at the generated files.  For this use
1354 the \-\-no\-lines command line option.  You should also note that these commands
1355 are not generated for the public header file at all.  If there is an error which
1356 points you to the public header file, make sure you fix this error in the .gob
1357 file, otherwise your changes will not have any effect after gob recompiles the
1358 sources again.
1359 .PP
1360 Sometimes you might want to know which method you are in for some debugging
1361 output.  GOB will define __GOB_FUNCTION__ macro, which is just a string constant
1362 with a pretty name of the method.
1363
1364 .SH M4 SUPPORT
1365 .PP
1366 It is possible to have your .gob file also preprocessed by m4.  This is useful
1367 if you have a lot of files and you\'d like to have some preprocessor put in
1368 some common features.  All you have to do is add \-\-m4 to the command line
1369 of gob2 and gob2 will first run your file through m4.  You can print the
1370 directory that is searched for m4 files by running "gob2 \-\-m4\-dir"
1371 .PP
1372 All the arguments after \-\-m4 will be passed to m4 itself, so it has to be the
1373 last gob2 argument on the command line.  This way you can specify arbitrary
1374 options to pass to m4.
1375
1376 .SH BUGS
1377 .PP
1378 The lexer does not actually parse the C code, so I\'m sure that some corner
1379 cases or maybe even some not so corner cases of C syntax might confuse gob
1380 completely.  If you find any, send me the source that makes it go gaga and
1381 I\'ll try to make the lexer try to handle it properly, but no promises.
1382 .PP
1383 Another thing is that gob ignores preprocessor macros.  Since gob counts
1384 braces, the following code won\'t work:
1385 .nf
1386
1387   #ifdef SOME_DEFINE
1388   if(foo) {
1389   #else
1390   if(bar) {
1391   #endif
1392           blah();
1393   }
1394
1395 .fi
1396 To make this work, you\'d have to do this:
1397 .nf
1398
1399   #ifdef SOME_DEFINE
1400   if(foo)
1401   #else
1402   if(bar)
1403   #endif
1404   {
1405           blah();
1406   }
1407
1408 .fi
1409 There is no real good way we can handle this without parsing C code, so we
1410 probably never will.  In the future, I might add #if 0 as a comment but
1411 that\'s about as far as I can really take it and even that is problematic.
1412 Basically, if you use gob, just don\'t use the C preprocessor too extensively.
1413 And if you use it make sure that you do not cross the boundaries of the C
1414 code segments.
1415 .PP
1416 Comments will not get through to the generated files unless inside C code.
1417 This is not the case for gtk\-doc style comments which are supported.
1418 .PP
1419 The short name aliases are actually implemented as pointers to functions.  Thus
1420 if you want to get the pointer of a function using the short name alias you
1421 can\'t use the \'&\'.  Thus:
1422 .nf
1423
1424   void (*foo)(Self *);
1425
1426   /* this will NOT work */
1427   foo = &self_short_name;
1428
1429   /* this will work */
1430   foo = self_short_name;
1431
1432   /* Both of these will work */
1433   foo = &my_class_long_name;
1434   foo = my_class_long_name;
1435
1436 .fi
1437
1438 .SH AUTHOR
1439 .PP
1440 George Lebl <jirka@5z.com>
1441 .PP
1442 GOB2 Homepage: http://www.jirka.org/gob.html