A handy wrapper around a NotifyCategory pointer. More...
#include "notifyCategoryProxy.h"
Public Member Functions | |
std::ostream & | debug (bool prefix=true) |
std::ostream & | error (bool prefix=true) |
std::ostream & | fatal (bool prefix=true) |
NotifyCategory * | get_safe_ptr () |
Returns a pointer which is *not* assumed to have been already initialized; if necessary, it will be initialized before it returns. More... | |
NotifyCategory * | get_unsafe_ptr () |
Returns a pointer which is assumed to have been already initialized. More... | |
std::ostream & | info (bool prefix=true) |
NotifyCategory * | init () |
Initializes the proxy object by calling get_category() on the template class. More... | |
bool | is_error () |
bool | is_fatal () |
bool | is_info () |
bool | is_on (NotifySeverity severity) |
bool | is_warning () |
NotifyCategory & | operator * () |
This operator handles the case of dereferencing the proxy object as if it were a pointer, e.g. More... | |
NotifyCategory * | operator -> () |
This magic operator function defines the syntax proxy->info(), etc., for all of the methods that are defined for NotifyCategory. More... | |
operator NotifyCategory * () | |
This operator handles the case of passing the proxy object to a function that accepts a NotifyCategory pointer. More... | |
std::ostream & | out (NotifySeverity severity, bool prefix=true) |
std::ostream & | spam (bool prefix=true) |
std::ostream & | warning (bool prefix=true) |
Static Public Member Functions | |
static constexpr bool | is_debug () |
static constexpr bool | is_spam () |
A handy wrapper around a NotifyCategory pointer.
This wrapper pretends to be a NotifyCategory object itself, except that it is capable of initializing its pointer if it is NULL.
The advantage to this over a normal pointer is that it can be used in functions that run at static init time, without worrying about ordering issues among static init routines. If the pointer hasn't been initialized yet, no sweat; it can initialize itself.
This must be a template class so it can do this magic; it templates on a class with a static method called get_category() that returns a new pointer to the NotifyCategory. This way the compiler can generate correct static- init-independent code to initialize the proxy.
In general, if the proxy object is treated as if it were itself a NotifyCategory object, then it doesn't check whether its category is initialized, and so may not be run at static init time. That is, you may call proxy.info(), but only when you are not running at static init time. This is an optimization so you can avoid this unnecessary check when you know (as in most cases) the code does not run at static init.
On the other hand, if the proxy object is treated as if it were a *pointer* to a NotifyCategory object, then it *does* check whether its category is initialized; you may safely use it in this way at static init time. Thus, you may call proxy->info() safely whenever you like.
Definition at line 51 of file notifyCategoryProxy.h.
|
inline |
Returns a pointer which is *not* assumed to have been already initialized; if necessary, it will be initialized before it returns.
This function may be used in functions that might execute at static init time. All of the category methods that are accessed via the arrow operator, e.g. proxy->info(), use this method.
Definition at line 52 of file notifyCategoryProxy.I.
|
inline |
Returns a pointer which is assumed to have been already initialized.
This function should only be used in functions that will certainly not execute at static init time. All of the category methods that are accessed via the dot operator, e.g. proxy.info(), use this method.
Definition at line 35 of file notifyCategoryProxy.I.
NotifyCategory * NotifyCategoryProxy< GetCategory >::init | ( | ) |
Initializes the proxy object by calling get_category() on the template class.
Definition at line 20 of file notifyCategoryProxy.I.
|
inline |
This operator handles the case of dereferencing the proxy object as if it were a pointer, e.g.
(*proxy).info(). It works the same way as the -> operator, above.
Definition at line 207 of file notifyCategoryProxy.I.
|
inline |
This magic operator function defines the syntax proxy->info(), etc., for all of the methods that are defined for NotifyCategory.
It's designed to vector through get_safe_ptr(), so this syntax is safe for functions that may execute at static init time.
Definition at line 196 of file notifyCategoryProxy.I.
|
inline |
This operator handles the case of passing the proxy object to a function that accepts a NotifyCategory pointer.
It works the same way as the -> and * operators, above.
Definition at line 218 of file notifyCategoryProxy.I.