]> git.draconx.ca Git - gob-dx.git/blobdiff - doc/gob2.1.in
Release 2.0.16
[gob-dx.git] / doc / gob2.1.in
index 9a53cffa7f2f62412a5474538a26c41abb294ce4..904691ebb0f61659edb7a9fa25dc2dd5da277a8d 100644 (file)
@@ -150,36 +150,44 @@ the extern "C" and the protecting define.  To do this you can put them
 into the \'headertop\' (or \'ht\') section.  You may wish to include code or
 comments in all the files, which you can do by putting them into the \'all\'
 (or \'a\') section.  Similarly, code you wish to appear at the top of all
-files go in the \'alltop\' (or \'at\') section.  For example:
+files go in the \'alltop\' (or \'at\') section.  Finally,
+\'afterdecls\' includes code between the declarations and the method
+implementations, but note that \'afterdecls\' requires version 2.0.16.
+For example:
 .nf
 
   %alltop{
-  /* this will be on top of all output files */
+        /* this will be on top of all output files */
   %}
 
   %headertop{
-  /* this will be on top of the public header */
+        /* this will be on top of the public header */
   %}
 
   %privateheader{
-  /* this will go into the private header file */
+        /* this will go into the private header file */
   %}
 
   %h{
-  /* will be included in the header */
-  void somefunc(int i);
+        /* will be included in the header */
+        void somefunc(int i);
   %}
 
   %a{
-  /* will be included in all files */
+        /* will be included in all files */
+  %}
+
+  %afterdecls{
+        /* between the declarations and the method implementations */
+        /* Requires gob version 2.0.16 */
   %}
 
   %{
-  /* will be included in the C file */
-  void somefunc(int i)
-  {
-        /* some code */
-  }
+        /* will be included in the C file */
+        void somefunc(int i)
+        {
+              /* some code */
+        }
   %}
 
 .fi
@@ -282,11 +290,12 @@ member foo:
   classwide int foo;
 
 .fi
-To access the member you do the standard voodoo of getting the class from the
-object and casting it to your class pointer.  Thus the following would work:
+To access the member you can use the SELF_GET_CLASS macro (or
+YOUR_OBJECT_NAME_GET_CLASS) to get at the class.
+Thus the following would work:
 .nf
 
-  SELF_CLASS(GTK_OBJECT(object)->klass)->foo = 20;
+  SELF_GET_CLASS(object)->foo = 20;
 
 .fi
 .PP
@@ -604,15 +613,43 @@ to be more then 0 and less then 11, and a pointer to a GtkWidget object
 instance and it is checked for being null and the type will also be
 checked.
 .PP
+.B "Function attributes:"
+.PP
+For method that aren't virtual, signal or override methods, and aren't
+init or class_init, GLib function attribute macros G_GNUC_PRINTF,
+G_GNUC_SCANF, and G_GNUC_FORMAT can optionally be included after the
+argument list.  Simply include an \'attr\' keyword and the C code to include
+in the file.  You have to include braces and anything inside the braces
+will be printed into the header file after the function declaration and
+before the trailing semicolon.  The braces themselves are not printed.
+For example:
+.nf
+
+  public void
+  print (self, const char *format (check null), ...)
+    attr {G_GNUC_PRINTF(2, 3)}
+
+.fi
+.PP
+This will produce a prototype which will generate a warning at compile
+time if the contents of the format argument (argument number 2) aren't
+consistent with the types and number of the subsequent variadic
+arguments (the first of which is argument number 3).  Only one \'attr\'
+keyword per method is allowed.
+If you have more than one attribute to include, you should
+put them all within the braces.
+Note that function attributes were aded in version 2.0.16.
+.PP
 .B "Error return:"
 .PP
 Methods which have a return value, there also has to be something
-returned if there is an error, such as if a precondition is not met.  The
-default is 0, casted to the type of the method.  If you need to return
-something else then you can specify an "onerror" keyword after the
-prototype and after that a number, a token (an identifier) or a bit of C
-code enclosed in braces {}.  The braces will not be printed into the
-output, they just delimit the string.  For example:
+returned if there is an error, such as if a precondition is not met.
+The default is 0, casted to the type of the method.  If you need to
+return something else then you can specify an \'onerror\' keyword after
+the prototype and any optional function attribute macros, and after
+that a number, a token (an identifier) or a bit of C code enclosed in
+braces {}.  The braces will not be printed into the output, they just
+delimit the string.  For example:
 .nf
 
   public void * get_something (self, int i (check >= 0)) onerror NULL {
@@ -667,6 +704,31 @@ initialization is taken care of for you by gob itself.  The init function
 should on the other hand be used whenever you need to construct or initialize
 anything in the object to put it into a sane state.
 .PP
+.B "Constructor, dispose, finalize methods:"
+.PP
+Since 2.0.16, you can also easily add code to the object's constructor,
+dispose, and finalize methods.  See GObject documentation on how these are
+run.  The code you add will be run before calling the parents function
+for dispose and finalize, and after the parent function for constructor.
+The syntax is just like init and class_init.
+For example:
+.nf
+
+  constructor (self) {
+       /* constructor method */
+  }
+
+  dispose (self) {
+       /* dispose method */
+  }
+
+  finalize (self) {
+       /* finalize method */
+  }
+
+.fi
+You can also just override those methods as usual, but the above is much easier and nearly as flexible.
+.PP
 .B "Virtual methods:"
 .PP
 Virtual methods are basically pointers in the class structure,