HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_StaticInit.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SYSdeclareStaticObject(API, NAME)
 
#define SYSimplementStaticObject(NAME, TYPE)
 
#define SYSdeclareStaticInit(API, NAME)
 
#define SYSimplementStaticInit(NAME)
 

Macro Definition Documentation

#define SYSdeclareStaticInit (   API,
  NAME 
)
Value:
static class API NAME##StaticInit { \
public: \
NAME##StaticInit (); \
~NAME##StaticInit (); \
NAME##StaticInit (const NAME##StaticInit &) = delete; \
NAME##StaticInit &operator=(const NAME##StaticInit &) = delete; \
} NAME##Initializer;
LeafData & operator=(const LeafData &)=delete

Static initializers in C++ are very dangerous and the interactions are undefined when one static initializer accesses another statically defined object.

These macros allow you to use statically initialized objects safely, or, to call a static initialization function at startup. As well, these macros handle destruction and cleanup when the last users of your code have themselved been destructed.

To avoid name conflicts, you may need to use descriptive names for the static objects. Eg for an instance of a UT_Lock class, instead of the name theLock choose theSharedStringLock, when it is used in UT_SharedString.C

HOW TO USE:

FOR OBJECTS:

To have an staticly initialized object that is safe to access from 
other locations during static initialization, do this:

DECLARATION:

// In the header (.h) do this SYSdeclareStaticObject(SYS_API,theFoobar);

IMPLEMENTATION

// In the implementation (.C) do this SYSimplementStaticObject(theFoobar,SYS_Foobar);

// Then, later you can to theFoobar->doStuff();

FOR FUNCTIONS

You can also have just plain initialization and cleanup functions.

DECLARATION:

// In the header (.h) do this SYSdeclareStaticInit(SYS_API,foobar);

IMPLEMENTATION

// Declare two void functions based on the name you chose void foobarInit() { // do stuff }

void foobarCleanUp() { // clean up stuff }

// In the implementation (.C) do this SYSimplementStaticInit(foobar);

HOW DOES THIS WORK?

This works because a small statically initialized object is inserted into each .C file that includes your header. That little object uses reference counting to ensure that your static initialization is done the first time a .o file that references your code is statically initialized.

That reference counting also makes sure that your static stuff is cleaned up when all .o's containing references have had their static destructors run.

Definition at line 112 of file SYS_StaticInit.h.

#define SYSdeclareStaticObject (   API,
  NAME 
)
Value:
static class API NAME##StaticInit { \
public: \
NAME##StaticInit (); \
~NAME##StaticInit (); \
NAME##StaticInit (const NAME##StaticInit &) = delete; \
NAME##StaticInit &operator=(const NAME##StaticInit &) = delete; \
} NAME##Initializer;
LeafData & operator=(const LeafData &)=delete

Static initializers in C++ are very dangerous and the interactions are undefined when one static initializer accesses another statically defined object.

These macros allow you to use statically initialized objects safely, or, to call a static initialization function at startup. As well, these macros handle destruction and cleanup when the last users of your code have themselved been destructed.

To avoid name conflicts, you may need to use descriptive names for the static objects. Eg for an instance of a UT_Lock class, instead of the name theLock choose theSharedStringLock, when it is used in UT_SharedString.C

HOW TO USE:

FOR OBJECTS:

To have an staticly initialized object that is safe to access from 
other locations during static initialization, do this:

DECLARATION:

// In the header (.h) do this SYSdeclareStaticObject(SYS_API,theFoobar);

IMPLEMENTATION

// In the implementation (.C) do this SYSimplementStaticObject(theFoobar,SYS_Foobar);

// Then, later you can to theFoobar->doStuff();

FOR FUNCTIONS

You can also have just plain initialization and cleanup functions.

DECLARATION:

// In the header (.h) do this SYSdeclareStaticInit(SYS_API,foobar);

IMPLEMENTATION

// Declare two void functions based on the name you chose void foobarInit() { // do stuff }

void foobarCleanUp() { // clean up stuff }

// In the implementation (.C) do this SYSimplementStaticInit(foobar);

HOW DOES THIS WORK?

This works because a small statically initialized object is inserted into each .C file that includes your header. That little object uses reference counting to ensure that your static initialization is done the first time a .o file that references your code is statically initialized.

That reference counting also makes sure that your static stuff is cleaned up when all .o's containing references have had their static destructors run.

Definition at line 89 of file SYS_StaticInit.h.

#define SYSimplementStaticInit (   NAME)
Value:
static int NAME##StaticInitCounter = 0; \
NAME##StaticInit::NAME##StaticInit () \
{ \
if (0 == NAME##StaticInitCounter++) \
NAME##Init(); \
} \
NAME##StaticInit::~NAME##StaticInit () \
{ \
if (0 == --NAME##StaticInitCounter) \
NAME##CleanUp(); \
}
if(num_boxed_items<=0)
Definition: UT_RTreeImpl.h:697

Static initializers in C++ are very dangerous and the interactions are undefined when one static initializer accesses another statically defined object.

These macros allow you to use statically initialized objects safely, or, to call a static initialization function at startup. As well, these macros handle destruction and cleanup when the last users of your code have themselved been destructed.

To avoid name conflicts, you may need to use descriptive names for the static objects. Eg for an instance of a UT_Lock class, instead of the name theLock choose theSharedStringLock, when it is used in UT_SharedString.C

HOW TO USE:

FOR OBJECTS:

To have an staticly initialized object that is safe to access from 
other locations during static initialization, do this:

DECLARATION:

// In the header (.h) do this SYSdeclareStaticObject(SYS_API,theFoobar);

IMPLEMENTATION

// In the implementation (.C) do this SYSimplementStaticObject(theFoobar,SYS_Foobar);

// Then, later you can to theFoobar->doStuff();

FOR FUNCTIONS

You can also have just plain initialization and cleanup functions.

DECLARATION:

// In the header (.h) do this SYSdeclareStaticInit(SYS_API,foobar);

IMPLEMENTATION

// Declare two void functions based on the name you chose void foobarInit() { // do stuff }

void foobarCleanUp() { // clean up stuff }

// In the implementation (.C) do this SYSimplementStaticInit(foobar);

HOW DOES THIS WORK?

This works because a small statically initialized object is inserted into each .C file that includes your header. That little object uses reference counting to ensure that your static initialization is done the first time a .o file that references your code is statically initialized.

That reference counting also makes sure that your static stuff is cleaned up when all .o's containing references have had their static destructors run.

Definition at line 121 of file SYS_StaticInit.h.

#define SYSimplementStaticObject (   NAME,
  TYPE 
)
Value:
static int NAME##StaticInitCounter = 0; \
static TYPE * NAME = NULL; \
NAME##StaticInit::NAME##StaticInit () \
{ \
if (0 == NAME##StaticInitCounter++) \
NAME = new TYPE(); \
} \
NAME##StaticInit::~NAME##StaticInit () \
{ \
if (0 == --NAME##StaticInitCounter) \
delete NAME; \
}
if(num_boxed_items<=0)
Definition: UT_RTreeImpl.h:697

Static initializers in C++ are very dangerous and the interactions are undefined when one static initializer accesses another statically defined object.

These macros allow you to use statically initialized objects safely, or, to call a static initialization function at startup. As well, these macros handle destruction and cleanup when the last users of your code have themselved been destructed.

To avoid name conflicts, you may need to use descriptive names for the static objects. Eg for an instance of a UT_Lock class, instead of the name theLock choose theSharedStringLock, when it is used in UT_SharedString.C

HOW TO USE:

FOR OBJECTS:

To have an staticly initialized object that is safe to access from 
other locations during static initialization, do this:

DECLARATION:

// In the header (.h) do this SYSdeclareStaticObject(SYS_API,theFoobar);

IMPLEMENTATION

// In the implementation (.C) do this SYSimplementStaticObject(theFoobar,SYS_Foobar);

// Then, later you can to theFoobar->doStuff();

FOR FUNCTIONS

You can also have just plain initialization and cleanup functions.

DECLARATION:

// In the header (.h) do this SYSdeclareStaticInit(SYS_API,foobar);

IMPLEMENTATION

// Declare two void functions based on the name you chose void foobarInit() { // do stuff }

void foobarCleanUp() { // clean up stuff }

// In the implementation (.C) do this SYSimplementStaticInit(foobar);

HOW DOES THIS WORK?

This works because a small statically initialized object is inserted into each .C file that includes your header. That little object uses reference counting to ensure that your static initialization is done the first time a .o file that references your code is statically initialized.

That reference counting also makes sure that your static stuff is cleaned up when all .o's containing references have had their static destructors run.

Definition at line 98 of file SYS_StaticInit.h.