]> git.draconx.ca Git - gob-dx.git/blob - doc/gob.1.in
a2724c6ead2359ae90eb435348534a8d5d47f73c
[gob-dx.git] / doc / gob.1.in
1 .\"
2 .\" gob manual page
3 .\" (C) 1999 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 GOB 1 "GOB @VERSION@" 
9 .SH NAME
10 GOB \- The GTK+ Object Builder
11 .SH SYNOPSIS
12 .PP
13 .B gob
14 [ option ] ...
15 file
16 .SH DESCRIPTION
17 .PP
18 GTK+ Object Builder is a simple preprocessor for easily creating
19 GTK+ objects.  It does not parse any C code and ignores any C errors.  It
20 is in spirit similar to things like lex or yacc.
21
22 .SH OPTIONS
23 .PP
24 .TP
25 .B -?
26 .TP
27 .B -h
28 .TP
29 .B --help
30 Display a simple help screen.
31 .TP
32 .B --version
33 Display version information (note, --version was not added until 0.92.0)
34 .TP
35 .B -w
36 .TP
37 .B --exit-on-warn
38 Exit with an error code even when you encounter a warning.
39 .TP
40 .B --no-exit-on-warn
41 Exit with an error only on errors, not on warnings, this is the default.
42 .TP
43 .B --for-cpp
44 Generate C++ code.
45 .TP
46 .B --no-extern-c
47 Never add the extern "C" to the header.
48 .TP
49 .B --no-gnu
50 Never generate any code with GNU C extensions.  However all the GNU C
51 extensions are always wrapped in #ifdef __GNUC__, so code using them compiles
52 correctly even on non-GNU compilers.  This option is for purists only.
53 (using GNU extensions some warnings are eliminated, some ugly hacks and there
54 is better argument type safety, so it's good to use them)
55 .TP
56 .B --no-touch-headers
57 Don't touch the generated header file unless it really changed, this avoids
58 spurious rebuilds, but can confuse some make systems (automake in particular),
59 so it is not enabled by default.  Private header is still touched even if
60 unchanged however.
61 .TP
62 .B --always-private-header
63 Always create a \fB<basename>-private.h\fR file, even if it would be empty.
64 Otherwise, it is only created when there are private data members in the class.
65 This option implicitly negates --no-private-header
66 .TP
67 .B --no-private-header
68 Never create a private header file.  If we use any private data members,
69 define the private data structure at the point in the .c source where
70 the class definition begins.  This option implicitly negates
71 --always-private-header
72 .TP
73 .B -n
74 .TP
75 .B --no-write
76 Do not write any output files, just check syntax of the input file.
77
78 .SH TYPENAMES
79 .PP
80 Because we need to parse out different parts of the typename, sometimes you
81 need to specify the typename with some special syntax.  Types are specified in
82 capitalized form and words are separated by ':'.  The first word of the type
83 (which can be empty) is the "namespace".  This fact is for example used for the
84 type checking macro and the type macro.  For "Gtk:New:Button", the macros will
85 be GTK_IS_NEW_BUTTON and GTK_TYPE_NEW_BUTTON.  This colon separated format of
86 typenames is used in the class declaration header and for method argument
87 types.
88
89 .SH OUTPUT FILES
90 .PP
91 The filenames are created from the typename.  The words are
92 separated by '-' and all in lower case.  For example for an object named
93 "Gtk:New:Button", the files are \fBgtk-new-button.c\fR and
94 \fBgtk-new-button.h\fR.
95 If you are using C++ mode, the output .c file will in fact be a .cc file.
96 If you have any private data members, a private header file will also
97 be created, called \fB<basename>-private.h\fR (for the example above it
98 would be gtk-new-button-private.h).
99 The public header file is created to be human readable and to be used as a
100 reference to the object.  The .c source file is not created as a human
101 readable source and is littered with #line statements, which make the
102 compiler attempt to point you to the right line in your .gob file in
103 case of parsing errors.  The output should not be edited by hand, and
104 you should only edit the .gob file.
105
106 .SH INCLUDING NORMAL C CODE IN THE OUTPUT FILES
107 .PP
108 To include some code directly in the output C file begin with '%{'
109 on an empty line and end the code with a '%}' on an empty line.  These
110 sections will appear in the output files in the order they are given.
111 There are several other \fIsections\fR to which you can put code.  You can
112 put it in the 'header' section (which can be abbreviated 'h') and it will
113 go into the public header file.  You can also put it in the 'privateheader'
114 section (abbreviated 'ph') which will make the code go into the private
115 header file.  Sometimes you want some code (other includes) to appear before
116 the extern "C" and the protecting define.  To do this you can put them
117 into the 'headertop' (or 'ht') section.  You may wish to include code or
118 comments in all the files, which you can do by putting them into the 'all'
119 (or 'a') section.  Similarly, code you wish to appear at the top of all
120 files go in the 'alltop' (or 'at') section.  For example:
121 .nf
122
123   %alltop{
124   /* this will be on top of all output files */
125   %}
126
127   %headertop{
128   /* this will be on top of the public header */
129   %}
130
131   %privateheader{
132   /* this will go into the private header file */
133   %}
134
135   %h{
136   /* will be included in the header */
137   void somefunc(int i);
138   %}
139
140   %a{
141   /* will be included in all files */
142   %}
143
144   %{
145   /* will be included in the C file */
146   void somefunc(int i)
147   {
148         /* some code */
149   }
150   %}
151
152 .fi
153
154 .SH INCLUDE FILES
155 .PP
156 Gob will automatically include the class header file at the top of the .c 
157 source file.  If you wish to include it somewhere else, put the include
158 into some %{ %} section above the class definition, and gob will not include
159 it automatically.  This way you can avoid circular includes and control
160 where in the file do you want to include the header.
161 .PP
162 If you made any data members private, gob will also create a source file
163 that will be called \fB<basename>-private.h\fR.  Same rule as above applies
164 for this just as it does for the regular header file.  If you do explicitly
165 include the regular header file, you should always include this private
166 header file below it.  That is, if you use any private data members.  If you
167 don't, the private header file automatically includes the public header file,
168 and thus the public header file will be indirectly included at the very top
169 of the file.
170
171 .SH MAKING A NEW CLASS
172 .PP
173 The class header:
174 .PP
175 There can be only one class per input file.  Defining a class
176 is sort of like in Java, you define the class and write inline code
177 directly into the class definition.  To define a class you need to specify
178 the new object name and the name of the object from which it is derived
179 from, such as this "class <new type> from <parent type> { <class code> }".
180 For example:
181 .nf
182
183   class Gtk:New:Button from Gtk:Button {
184           <class code>
185   }
186
187 .fi
188 .PP
189 Data members:
190 .PP
191 There are four types of data members.  Three of them are normal
192 data numbers, and one is a virtual one, usually linked to a normal
193 data member.  The three normal data members are public, protected and
194 private.  Public and protected are basically just entries in the object
195 structure, while private has it's own dynamically allocated private
196 structure.  Protected members are always put after the public one in the
197 structure and are marked protected in the header file.  There is only one
198 identifier allowed per typename unlike in normal C.  Example:
199 .nf
200
201   public int i;
202   private GtkWidget *h;
203   protected long k;
204
205 .fi
206 .PP
207 Public and protected data members are accessed normally as members of
208 the object struct.  Example where 'i' is as above a public data member:
209 .nf
210
211   object->i = 1;
212
213 .fi
214 .PP
215 The private data members are defined in a structure which is only available
216 inside the .c file, or by including a private header file.  You must access
217 them using the structure _priv.  Example
218 where 'h' is the private data member (as in the above example):
219 .nf
220
221   object->_priv->h = NULL;
222
223 .fi
224 The _priv structure is defined in the \fB<basename>-private.h\fR.
225 This file is automatically included if you don't include it yourself.  You
226 should always explicitly include it if you explicitly also include the main
227 header file.
228 .PP
229 In case you use the \fB--no-private-header\fR option, no
230 private header file is created and you can only access the _priv pointer
231 below the class definition in the .gob file.
232 .PP
233 Automatic Initialization (0.93.0 and higher only):
234 .PP
235 You can automatically initialize the public private and protected data members
236 without having to add an init method.  The advantage here is that
237 initialization is kept close to the definition of the data member and thus
238 it's easier to check.  To do this, just add a '=' followed by a number or
239 a token.  It is also possible to include arbitrary C code for more elaborate
240 initializations by putting it all in curly braces.  Note that the curly braces
241 will not be printed into the output, but since gob does not C parsing it needs
242 them to figure out where the C code ends.  The code will be inserted into the
243 init method, above the user defined body.  So for example the following
244 will initialize an integer to -1 and a string with a newly allocated string
245 of "hello".
246 .nf
247
248   public int foo = -1;
249   private char *bar = {g_strdup("hello")};
250
251 .fi
252 .PP
253 Automatic Destruction (0.93.0 and higher only):
254 .PP
255 Most data stored as pointers needs to have a function called when the object
256 is destroyed, to either free it or give up a reference.  Gob will let you
257 define a function to be called on the data the object is destroyed.  This is
258 achieved by putting 'destroywith' followed by a function name after the
259 variable definition.  It is only called if the data you defined this on
260 is not NULL, so you cans specify functions which do not handle NULL.  It
261 is very much like the GDestroyNotify function used in GTK+ and glib in many
262 places.  Unlike many other places, gob will not enforce any kind of type
263 safety here so be a little bit more careful.  Any function you give it will
264 be called as a "void function(void *)".  It will in fact be cast into such
265 a form before called.  This is to avoid spurious warnings for gtk calls to
266 subclass methods.  The function needs not be of that form, it just has to
267 take one argument which is the pointer to the data.  You should also not
268 define this on any non-pointer data as the results may be undefined.
269 Example:
270 .nf
271
272   public Gtk:Widget *window = NULL
273           destroywith gtk_widget_destroy;
274   public char *foo = {g_strdup("bar")}
275           destroywith g_free;
276
277 .fi
278 Note that the function name you give must be a real function and not macro.
279 Also note that this is always called in the "finalize" method of GtkObject.
280 .PP
281 Sometimes you may want to run arbitrary code on destruction.  While this can
282 be perfectly well done in the destroy handler.  Depending on the style you
283 may want to include all destruction/initialization code together with the
284 definition of the data member.  Thus you may want to put arbitrary code which
285 will then be inserted into the "finalize" method of GtkObject.  This can be
286 done with the "destroy" keyword followed by arbitrary code in curly braces.  
287 Inside this code a macro called VAR will be define which refers to your
288 variable.  So for example destroying a GString can be either done with
289 a helper routine or the following code:
290 .nf
291
292   public GString *string = {g_string_new(NULL)}
293           destroy {
294                   if(VAR) g_string_free(VAR, TRUE);
295           };
296
297 .fi
298 The thing to remember with these is that there are many ways to do this
299 and you'd better be consistent in your code in how you use the above things.
300 Also defining a helper routine that will do the destruction will be a nicer
301 thing to do if that's a possibility.  The "destroy" keyword with code does
302 take up more space in the file and it may become more cluttered.
303 .PP
304 GTK+ Arguments:
305 .PP
306 The fourth type of a data member an argument type.  It is a named data member
307 which is one of the features of the GTK+ object system.  You need to define a
308 get and a set handler.  They are fragments of C code that will be used to get
309 the value or set the value of the argument.  Inside them you can use the define
310 ARG to which you assign the data or get the data.  You can also use the
311 identifier "self" as pointer to the object instance.  The type is defined as
312 one of the gtk type enums, but without the GTK_TYPE_ prefix.  For example:
313 .nf
314
315   public int height;
316   argument INT height set { self->height = ARG; } get { ARG = self->height; };
317
318 .fi
319 .PP
320 If you don't define a set or a get handler it will be a read-only
321 or a write-only argument.  If you want to add extra argument flags, add
322 them into parenthesis after the argument keyword, separated by '|' and
323 without the GTK_ARG_ prefix.  For example:
324 .nf
325
326   public int height;
327   argument (CONSTRUCT) INT height get { ARG = self->height; };
328
329 .fi
330 This makes the argument settable even before the object is constructed, so
331 that people can pass it to gtk_object_new function.  Useful is also
332 CONSTRUCT_ONLY flag which makes the argument only available during
333 construction of the object.
334 .PP
335 Since 0.92.1, gob creates macros which can be used for type safe access to
336 gtk arguments.  The macros are called <type>_ARG_<argument name>(x) and
337 <type>_GET_ARG_<argument name>(x).  They define both the string and the
338 value part of the argument.  So for setting an argument of height, one would
339 use (for object type My:Object):
340 .nf
341
342   gtk_object_set(GTK_OBJECT(object),
343                  MY_OBJECT_ARG_HEIGHT(7),
344                  NULL);
345
346 .fi
347 And for getting, you would use:
348 .nf
349
350   int height;
351   gtk_object_set(GTK_OBJECT(object),
352                  MY_OBJECT_GET_ARG_HEIGHT(&height),
353                  NULL);
354
355 .fi
356 Note however that the type safety only works completely on GNU C compilers.
357 The code will compile on other compilers but with minimal type safety.
358 .PP
359 To get good type safety on POINTER types however, you should specify
360 an optional C type that gob should use.  For other then POINTER types
361 this is redundant but possible.  To do this, place '(type <c type>)'
362 right after the GTK+ type.  Example:
363 .nf
364
365   argument POINTER (type char *) foo set { /* foo */ } get { /* bar */ };
366
367 .fi
368 .PP
369 Sometimes it can become tiresome to type in the set and get handlers if
370 they are trivial.  So gob since version 0.93.0 provides automatic argument
371 linking to data members.  There are three different cases it handles, direct
372 link (keyword 'link'), string linking (keyword 'stringlink') and object
373 linking (keyword 'objectlink').  You just place the keyword after the argument
374 name instead of the get/set handlers.  It will link to a data member of the
375 same name that was defined earlier in the input file.  Best is to see examples:
376 .nf
377
378   public int foo;
379   argument INT foo link;
380
381 .fi
382 is just like
383 .nf
384
385   public int foo;
386   argument INT (type int) foo
387   get { ARG = self->foo; }
388   set { self->foo = ARG; };
389
390 .fi
391 Similiarly,
392 .nf
393
394   private char * foo;
395   argument POINTER foo stringlink;
396
397 .fi
398 is just like
399 .nf
400
401   private char * foo;
402   argument POINTER (type char *) foo
403   get {
404         ARG = self->_priv->foo;
405   } set {
406         g_free(self->_priv->foo);
407         self->_priv->foo = g_strdup(ARG);
408   }
409
410 .fi
411 And for the objectlink we would have:
412 .nf
413
414   public Gtk:Object * foo;
415   argument POINTER foo objectlink;
416
417 .fi
418 is just like
419 .nf
420
421   protected Gtk:Object * foo;
422   argument POINTER (type Gtk:Object *) foo
423   get {
424         ARG = self->foo;
425   } set {
426         if(self->foo)
427                 gtk_object_unref(self->foo);
428         self->foo = ARG;
429         if(self->foo)
430                 gtk_object_ref(self->foo);
431   }
432
433 .fi
434 .PP
435 As you see it will handle NULLs correctly (for the string, g_free and g_strdup
436 handle NULLs).  And it will also handle private, protected and public members.
437 Also you should notice that when the get is used, only a pointer is always
438 returned for both objectlink and strinklink.  So you should treat the returned
439 value with care and never free it (and notice that it will only be around
440 until you set the argument to something else or destroy the object).
441 .PP
442 Methods:
443 .PP
444 There is a whole array of possible methods.  The three normal,
445 "familiar" method types are private, protected and public.  Public are
446 defined as normal functions with a prototype in the header file.  
447 Protected methods are defined as normal methods (which you can call from other
448 files), but their prototype is placed in the private header file.  Private
449 methods
450 are defined as static functions with prototypes at the top of the .c
451 file.  Then there are signal, virtual and override methods.  More on those
452 later.  You can also
453 define init and class_init methods with a special definition if you want
454 to add code to the constructors or you can just leave them out.
455 You can also not define a body for a method, by just using ';' instead of a
456 body.  This will define an empty function.  You can't do this for non-void
457 regular public, private or protected methods, however it is acceptable for
458 non-void virtual, signal and override methods.
459 .PP
460 Function argument lists:
461 .PP
462 For all but the init and class_init methods, you use the
463 following syntax for arguments.  The first argument can be just "self",
464 which gob will translate into a pointer to the object instance.  The rest
465 of the arguments are very similar to normal C arguments.  If the
466 typename is an object pointer you should use the syntax defined above
467 with the words separated by ':'
468 .nf
469 <type> <argument id>
470 or
471 <type> <argument id> (check <list of checks>)
472 .fi
473 .PP
474 The checks are glib type preconditions, and can be the following:
475 "null", which tests pointers for being NULL, "type" which checks GTK+
476 object pointers for being the right type, "<test> <number>" which tests
477 numeric arguments for being a certain value.  The test can be a <,>,<=,>=
478 != or ==.  Example:
479 .nf
480   
481   public int foo(self, int h (check > 0 < 11), Gtk:Widget *w (check null type))
482
483 .fi
484 .PP
485 This will be the prototype of a function which has a self pointer
486 as the first argument, an integer argument which will be checked and has
487 to be more then 0 and less then 11, and a pointer to a GtkWidget object
488 instance and it is checked for being null and the type will also be
489 checked.
490 .PP
491 Error return:
492 .PP
493 Methods which have a return value, there also has to be something
494 returned if there is an error, such as if a precondition is not met.  The
495 default is 0, casted to the type of the method.  If you need to return
496 something else then you can specify an "onerror" keyword after the
497 prototype and after that a number, a token (an identifier) or a bit of C
498 code enclosed in braces {}.  The braces will not be printed into the
499 output, they just delimit the string.  For example:
500 .nf
501
502   public void * get_something(self, int i (check >= 0)) onerror NULL {
503           ...
504   }
505
506 .fi
507 The onerror value is also used in overrides that have a return value, in
508 case there isn't a parent method, PARENT_HANDLER will return it.  More about
509 this later.
510 .PP
511 Default return:
512 .PP
513 Some signal and virtual methods have a return type.  But what happens if
514 there is no default handler and no one connects to a signal.  GOB will
515 normally have the wrappers return whatever you specify with onerror or '0'
516 if you haven't specified anything.  But since 0.93.2 you can specify a default
517 return value with the keyword 'defreturn'.  It's use is identical to the
518 use of onerror, and you can in fact use both at the same time.  Example
519 .nf
520
521   virtual int get_some_int(self) onerror -1 defreturn 10 ;
522
523 .fi
524 That is an empty virtual method (in C++ terms a pure virtual).  If you never
525 specify any handler for it in the derived children it will just return 10.
526 .PP
527 Constructor methods:
528 .PP
529 There are two methods that handle the construction of an object, init and
530 class_init.  You define them by just using the init or class_init keyword 
531 with an untyped argument in the argument list.  The argument will be
532 usable in your function as a pointer to your object or class depending if
533 it's init or class_init.
534 For example:
535 .nf
536
537   init(self) {
538           /* initialize the object here */
539           self->a = 9;
540           self->b = 9;
541   }
542
543   class_init(class) {
544           /* initialize the class, this is rarely needed */
545           class->blah = NULL;
546   }
547
548 .fi
549 The class_init function is very rarely needed as all standard class
550 initialization is taken care of for you by gob itself.  The init function
551 should on the other hand be used whenever you need to construct or initialize
552 anything in the object to put it into a sane state.  Sometimes you need
553 some arguments, for this you should either use a construct method and a
554 new function like many GTK+ widgets, and/or a CONSTRUCT or CONSTRUCT_ONLY
555 type of an argument.
556 .PP
557 Virtual methods:
558 .PP
559 Virtual methods are basically pointers in the class structure,
560 so that one can override the method in derived methods.  They can be empty
561 (if you put ';' instead of the C code).  A wrapper will also be defined
562 which makes calling the methods he same as public methods.  This type of
563 method is just a little bit "slower" then normal functions, but not as
564 slow as signals.  You define them by using "virtual" keyword before the
565 prototype.  If you put the keyword "private" right after the "virtual"
566 keyword, the wrapper will not be a public method, but a private one.
567 You can do the same with "protected" to make a protected wrapper.
568 .PP
569 Signals:
570 .PP
571 Signals are methods to which the user can bind other handlers
572 and override the default handler.  The default handler is basically the
573 method body.  This is the most versatile and flexible type of a method
574 and also the slowest.  You need to specify a whole bunch of things when
575 you define a signal.  One thing is when the default handler will be run,
576 first or last.  You specify that by "first" or "last" right after the
577 "signal" keyword.  Then you need to define the gtk enum types (again
578 without the GTK_TYPE_ prefix).  For that you define the return types
579 and the types of arguments after the "self" pointer (not including the
580 "self" pointer).  You put it in the following syntax "<return type> (<list
581 of arguments>)".  If the return type is void, the type should be "NONE",
582 the same should be for the argument list.  The rest of the prototype is
583 the same as for other method types.  The body can also be empty, and
584 also there is a public method wrapper which you can use for calling the
585 signal just like a public method.  Example:
586 .nf
587
588   signal first INT(POINTER,INT)
589   int do_something(self, Gtk:Widget *w (check null type), int length)
590   {
591           ...
592   }
593   
594 or
595
596   signal last NONE(NONE) void foo(self);
597
598 .fi
599 .PP
600 If you don't want the wrapper that emits the signal to be public, you can
601 include the keyword "private" after the "signal" keyword.  This will make
602 the wrapper a normal private method.  You can also make a protected wrapper
603 by using "protected" instead of "private".
604 .PP
605 If you don't define a "first" or a "last", the default will be taken as
606 "last".
607 .PP
608 You can also add additional flags.  You do this just like with the argument
609 flags, although this is probably very rare.  These are the GTK_RUN_* flags,
610 and you can add them without the GTK_RUN_ prefix into a parenthesis, just
611 after the "signal" keyword.  By default all public signals are GTK_RUN_ACTION.
612 .PP
613 Override methods:
614 .PP
615 If you need to override some method (a signal or a virtual method
616 of some class in the parent tree of the new object), you can define and
617 override method.  After the "override" keyword, you should put the
618 typename of the class you are overriding a method from.  Other then that
619 it is the same as for other methods.  The "self" pointer in this case
620 should be the type of the method you are overriding so that you don't
621 get warnings during compilation.  Also to call the method of the parent
622 class, you can use the PARENT_HANDLER macro with your arguments.  Example:
623 .nf
624
625   override (Gtk:Container) void
626   add (Gtk:Container *self (check null type), Gtk:Widget *wid (check null type))
627   {
628           /* some code here */
629           PARENT_HANDLER(self, wid);
630   }
631
632 .fi
633 If the function has a return value, then PARENT_HANDLER is an expression that
634 you can use.  It will return whatever the parent handler returned, or the
635 "onerror" expression if there was no parent handler.
636 .PP
637 Calling methods:
638 .PP
639 Inside the code, pointers are set for the methods, so that you don't
640 have to type the class name before each call, just the name of the method.
641 Example:
642 .nf
643
644   private int
645   foo(self)
646   {
647           return self->len;
648   }
649   
650   private int
651   bar(self,int i)
652   {
653           return foo(self) + i;
654   }
655
656 .fi
657 .PP
658 Making new objects:
659 .PP
660 You should define a new method which should be a normal public method.  Inside
661 this method, you can use the GET_NEW macro that is defined for you and that
662 will fetch a new object, so a fairly standard new method would look like:
663 .nf
664
665   public GtkObject *
666   new(void) {
667           GtkObject *ret;
668           ret = GTK_OBJECT (GET_NEW);
669           return ret;
670   }
671
672 .fi
673 .PP
674 Casts:
675 .PP
676 There are some standard casts defined for you.  Instead of using the full
677 macros inside the .c file, you can use SELF, IS_SELF and SELF_CLASS.  Using
678 these makes it easier to for example change classnames around.  There is
679 however no self type, so if you're declaring a pointer to your object, you
680 still have to use the full type.
681
682 .SH DEALING WITH DIFFERENT GOB VERSIONS
683 .PP
684 Defines:
685 .PP
686 In your generated C file, you can use the defines GOB_VERSION_MAJOR
687 GOB_VERSION_MINOR and GOB_VERSION_PATCHLEVEL if you wish to for example
688 use a feature that is only available in some newer gob version.  Note however
689 that you can only use these defines in the C code portions of your .gob file,
690 and #ifdef's cannot span multiple functions.  Check the BUGS section
691 for more on using the C preprocessor and gob.  Also note that these
692 have only been available since the 0.92.1 version of gob.
693 .PP
694 Minimum version requires:
695 .PP
696 You can also make your .gob file require at least certain version of gob.  You
697 do this by putting 'requires x.y.z' (where x.y.z is the version number) outside
698 of any C block, comment or class, usually you should make this the first line
699 in the file or close to the top.  If gob finds this and the version of gob used
700 to compile the code is lower then that listed in the require, gob will generate
701 an error and exit.  For example to require that gob version 0.92.1 or higher
702 be used to compile a file, put this at the top of that file:
703 .nf
704
705   requires 0.92.1
706
707 .fi
708 It should be noted however that this feature was not added until 0.92.1, and
709 so if the file gets compiled by a lower version, gob would generate a 
710 syntax error.  Thus by putting in a requires line, you are implicitly
711 requiring at least 0.92.1.
712
713 .SH C++ MODE
714 .PP
715 There is a C++ mode so that gob creates C++ compiler friendly files.  You need
716 to use the --for-cpp argument to gob.  This will make the generated file have
717 a .cc instead of a .c extension, and several things will be adjusted to
718 make it all work for a C++ compiler.  One thing that will be missing is an
719 alias to the new method, as that clashes with C++, so instead you'll have to
720 use the full name of the method inside your code.  Also note that gob does
721 not use any C++ features, this option will just make the generated code
722 compile with a C++ compiler.
723
724 .SH IDENTIFIER CONFLICTS
725 .PP
726 Gob will need to define some local varibles and functions in the generated
727 files, so you need to take some precaution not to conflict with these.  The
728 general rule of thumb is that all of these start with three underscores.  There
729 is one, "parent_class" which doesn't because it's intended for use in your
730 code.  For virtuals or signals, you cannot use the identifier __parent__
731 which is used for the parent of the object.  You should actually never access
732 __parent__ either as it not guaranteed that it will stay named this way.
733 Data members cannot be named __parent__ nor _priv.  For methods, you cannot
734 use the identifiers "init" or "class_init" unless you mean the constructor
735 methods.  You shouldn't generally use 3 underscores even in override method
736 argument lists and virtual and signal method names as it might confuse the
737 PARENT_HANDLER macro.  In fact avoiding all names with three underscores is
738 the best policy when working with gob.
739 .PP
740 There are a couple of defines which you shouldn't be redefining in the code
741 or other headers.  These are SELF, IS_SELF, SELF_CLASS, ARG, VAR,
742 PARENT_HANDLER, GET_NEW, GOB_VERSION_MAJOR, GOB_VERSION_MINOR and
743 GOB_VERSION_PATCHLEVEL.
744
745 .SH USING GTK-DOC STYLE INLINE DOCUMENTATION
746 .PP
747 If you want to use gtk-doc style inline documentation for your objects, you
748 can do one of two things.  First, you could include the inline documentation
749 comments in your %{ %} section which will then be put verbatim into the
750 output source file.  This is the way you should use for functions you define
751 outside of the class.
752 .PP
753 For class methods, you should use a gtk+ style comment, however it can be
754 indented any number of tabs or spaces and you can use the short method name
755 without the type prefix.  Gob will automatically try to extract these and
756 translate to full names and put them in the output source file.  An example
757 would be:
758 .fi
759
760   class Gtk:Button:Example from Gtk:Button {
761           /**
762            * new:
763            *
764            * Makes a new #GtkButtonExample widget
765            *
766            * Returns: a new widget
767            **/
768           public
769           GtkWidget *
770           new(void)
771           {
772                   return GTK_WIDGET(GET_NEW);
773           }
774   } 
775
776 .fi
777 If the function you are documenting is a signal or a virtual then it will
778 be documentating the wrapper that starts that virtual function or emits
779 that signal.
780
781 .SH DEALING WITH CIRCULAR HEADERS
782 .PP
783 Sometimes you may need to use an object of type MyObjectA in the MyObjectB
784 class and vice versa.  Obviously you can't include headers for both.  So you
785 need to just declare the typedef in the header of A for B, and the other way
786 around as well.  The headers generated since v0.92.2 include a protecting
787 define before it declares the typedef.  This define is the
788 __TYPEDEF_<upper case object name>__.  So inside my-object-a.h there will be
789 this:
790 .nf
791
792   #ifndef __TYPEDEF_MY_OBJECT_A__
793   #define __TYPEDEF_MY_OBJECT_A__
794   typedef struct _MyObjectA MyObjectA;
795   #endif
796
797 .fi
798 Now instead of including my-object-a.h in the header section of
799 my-object-b.gob, just copy the above code there and you're set for using
800 MyObjectA as a type in the method parameters and public types.
801 .PP
802 Another way to get out of this problem is if you can use those types only
803 in the private members, in which case they won't be in the generated public
804 header.
805
806 .SH BUGS
807 .PP
808 Also the lexer does not actually parse the C code, so I'm sure that some corner
809 cases or maybe even some not so corner cases of C syntax might confuse gob
810 completely.  If you find any, send me the source that makes it go gaga and I'll
811 try to make the lexer try to handle it properly, but no promises.
812 .PP
813 Another thing is that gob ignores preprocessor macros.  Since gob counts
814 braces, the following code won't work:
815 .nf
816
817   #ifdef SOME_DEFINE
818   if(foo) {
819   #else
820   if(bar) {
821   #endif
822           blah();
823   }
824
825 .fi
826 To make this work, you'd have to do this:
827 .nf
828
829   #ifdef SOME_DEFINE
830   if(foo)
831   #else
832   if(bar)
833   #endif
834   {
835           blah();
836   }
837
838 .fi
839 There is no real good way we can handle this without parsing C code, so we
840 probably never will.  In the future, I might add #if 0 as a comment but
841 that's about as far as I can really take it and even that is problematic.
842 Basically, if you use gob, just don't use the C preprocessor too extensively.
843 .PP
844 Comments will not get through to the generated files unless inside C code.
845 This makes using something like gtk-doc harder.  However I'm planning to
846 fix this somehow.
847
848 .SH AUTHOR
849 .PP
850 George Lebl <jirka@5z.com>