Defines | Typedefs | Functions
core/vgui/vgui_tag.h File Reference

Allow clients to register 'tag functions' which are called later. More...

Go to the source code of this file.

Defines

#define vgui_tag(tk)

Typedefs

typedef int(* vgui_tag_function )(void)
 The type of a tag function.

Functions

int vgui_tag_add (vgui_tag_function, char const *)
 Registers a tag function - returns 0.
vgui_tag_function const * vgui_tag_list ()
 Returns null-terminated list of tag functions.
void vgui_tag_call ()
 Call all registered tag functions and remove them from the list.

Detailed Description

Allow clients to register 'tag functions' which are called later.

Author:
fsm

Real Purpose:

An impl library "blah" should register a tag function at library initialization time. The old method, where a library had a line something like

   static vgui_blah *init_dummy = new vgui_blah;

caused problems (segv) if a vgui_blah uses run-time libraries which have not yet been initialized. No particular order of library initialization may be assumed, so static objects in libA might not yet have been constructed when libB is initialized.

The workaround provided by vgui_tag is to make impl libraries register tag functions instead. Class vgui then promises to call all the registered tag functions near the beginning of vgui::init(); There is no problem with registering function pointers, as these are POD (Plain Old Data). Thus, vgui_blah_tag.cxx now looks like this :

   static int vgui_blah_function() { new vgui_blah; return 0; }
   int vgui_blah_tag = vgui_tag_add(vgui_blah_function, "blah");

Thus, when 'vgui_blah_tag' is initialized, the tag function called 'vgui_blah_tag_function' is registered. There is no instance of vgui_blah created until that tag function is called by vgui::init().

    Modifications
     07-AUG-2002 K.Y.McGaul - Changed to Doxygen style comments.
   

Definition in file vgui_tag.h.


Define Documentation

#define vgui_tag (   tk)
Value:
int vgui_##tk##_tag_function(); \
int vgui_##tk##_tag = vgui_tag_add(vgui_##tk##_tag_function, #tk); \
static int vgui_##tk##_tag_function_(); \
int vgui_##tk##_tag_function() { \
  static bool once = false; \
  static int  value = 0; \
  if (!once) \
    value = vgui_##tk##_tag_function_(); \
  once = true; \
  return value; \
} \
int vgui_##tk##_tag_function_()

Definition at line 62 of file vgui_tag.h.


Typedef Documentation

typedef int(* vgui_tag_function)(void)

The type of a tag function.

Definition at line 44 of file vgui_tag.h.


Function Documentation

int vgui_tag_add ( vgui_tag_function  ,
char const *   
)

Registers a tag function - returns 0.

Definition at line 19 of file vgui_tag.cxx.

void vgui_tag_call ( )

Call all registered tag functions and remove them from the list.

Definition at line 32 of file vgui_tag.cxx.

vgui_tag_function const* vgui_tag_list ( )

Returns null-terminated list of tag functions.

Definition at line 27 of file vgui_tag.cxx.