HDK
|
Go to the source code of this file.
Macros | |
#define | SYSdeclareStaticObject(API, NAME) |
#define | SYSimplementStaticObject(NAME, TYPE) |
#define | SYSdeclareStaticInit(API, NAME) |
#define | SYSimplementStaticInit(NAME) |
#define SYSdeclareStaticInit | ( | API, | |
NAME | |||
) |
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 | |||
) |
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 | ) |
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 | |||
) |
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.