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