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