Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Notify Class Reference

An object that handles general error reporting to the user. More...

#include "pnotify.h"

Public Types

typedef bool AssertHandler(const char *expression, int line, const char *source_file)
 

Public Member Functions

bool assert_failure (const std::string &expression, int line, const char *source_file)
 This function is not intended to be called directly by user code. More...
 
bool assert_failure (const char *expression, int line, const char *source_file)
 This function is not intended to be called directly by user code. More...
 
void clear_assert_failed ()
 Resets the assert_failed flag that is set whenever an assertion test fails. More...
 
void clear_assert_handler ()
 Removes the installed assert handler and restores default behavior of nassertr() and nassertv(). More...
 
void config_initialized ()
 Intended to be called only by Config, this is a callback that indicates to Notify when Config has done initializing and Notify can safely set up some internal state variables that depend on Config variables. More...
 
const std::string & get_assert_error_message () const
 Returns the error message that corresponds to the assertion that most recently failed. More...
 
AssertHandler * get_assert_handler () const
 Returns a pointer to the user-installed assert handler, if one was installed, or NULL otherwise. More...
 
NotifyCategoryget_category (const std::string &basename, NotifyCategory *parent_category)
 Finds or creates a new Category given the basename of the category and its parent in the category hierarchy. More...
 
NotifyCategoryget_category (const std::string &basename, const std::string &parent_fullname)
 Finds or creates a new Category given the basename of the category and the fullname of its parent. More...
 
NotifyCategoryget_category (const std::string &fullname)
 Finds or creates a new Category given the fullname of the Category. More...
 
std::ostream * get_ostream_ptr () const
 Returns the system-wide ostream for all Notify messages. More...
 
NotifyCategoryget_top_category ()
 Returns the topmost Category in the hierarchy. More...
 
bool has_assert_failed () const
 Returns true if an assertion test has failed (and not been ignored) since the last call to clear_assert_failed(). More...
 
bool has_assert_handler () const
 Returns true if a user assert handler has been installed, false otherwise. More...
 
void set_assert_handler (AssertHandler *assert_handler)
 Sets a pointer to a C function that will be called when an assertion test fails. More...
 
void set_ostream_ptr (std::ostream *ostream_ptr, bool delete_later)
 Changes the ostream that all subsequent Notify messages will be written to. More...
 

Static Public Member Functions

static ios_fmtflags get_literal_flag ()
 Returns a flag that may be set on the Notify stream via setf() that, when set, enables "literal" mode, which means the Notify stream will not attempt to do any fancy formatting (like word-wrapping). More...
 
static std::ostream & null ()
 A convenient way to get an ostream that doesn't do anything. More...
 
static std::ostream & out ()
 A convenient way to get the ostream that should be written to for a Notify- type message. More...
 
static Notifyptr ()
 Returns the pointer to the global Notify object. More...
 
static NotifySeverity string_severity (const std::string &string)
 Given a string, one of "debug", "info", "warning", etc., return the corresponding Severity level, or NS_unspecified if none of the strings matches. More...
 
static void write_string (const std::string &str)
 A convenient way for scripting languages, which may know nothing about ostreams, to write to Notify. More...
 

Detailed Description

An object that handles general error reporting to the user.

It contains a pointer to an ostream, initially cerr, which can be reset at will to point to different output devices, according to the needs of the application. All output generated within Panda should vector through the Notify ostream.

This also includes a collection of Categories and Severities, which may be independently enabled or disabled, so that error messages may be squelched or respected according to the wishes of the user.

Definition at line 33 of file pnotify.h.

Member Function Documentation

◆ assert_failure() [1/2]

bool Notify::assert_failure ( const std::string &  expression,
int  line,
const char *  source_file 
)

This function is not intended to be called directly by user code.

It's called from the nassertr() and assertv() macros when an assertion test fails; it handles the job of printing the warning message and deciding what to do about it.

If this function returns true, the calling function should return out of its function; if it returns false, the calling function should ignore the assertion.

Definition at line 308 of file notify.cxx.

◆ assert_failure() [2/2]

bool Notify::assert_failure ( const char *  expression,
int  line,
const char *  source_file 
)

This function is not intended to be called directly by user code.

It's called from the nassertr() and assertv() macros when an assertion test fails; it handles the job of printing the warning message and deciding what to do about it.

If this function returns true, the calling function should return out of its function; if it returns false, the calling function should ignore the assertion.

Definition at line 324 of file notify.cxx.

References has_assert_handler().

◆ clear_assert_failed()

void Notify::clear_assert_failed ( )
inline

Resets the assert_failed flag that is set whenever an assertion test fails.

See has_assert_failed().

Definition at line 47 of file pnotify.I.

◆ clear_assert_handler()

void Notify::clear_assert_handler ( )

Removes the installed assert handler and restores default behavior of nassertr() and nassertv().

Definition at line 143 of file notify.cxx.

◆ config_initialized()

void Notify::config_initialized ( )

Intended to be called only by Config, this is a callback that indicates to Notify when Config has done initializing and Notify can safely set up some internal state variables that depend on Config variables.

Definition at line 424 of file notify.cxx.

◆ get_assert_error_message()

const std::string & Notify::get_assert_error_message ( ) const
inline

Returns the error message that corresponds to the assertion that most recently failed.

Definition at line 38 of file pnotify.I.

◆ get_assert_handler()

Notify::AssertHandler * Notify::get_assert_handler ( ) const

Returns a pointer to the user-installed assert handler, if one was installed, or NULL otherwise.

Definition at line 160 of file notify.cxx.

◆ get_category() [1/3]

NotifyCategory * Notify::get_category ( const std::string &  basename,
NotifyCategory parent_category 
)

Finds or creates a new Category given the basename of the category and its parent in the category hierarchy.

The parent pointer may be NULL to indicate this is a top-level Category.

Definition at line 179 of file notify.cxx.

Referenced by get_category(), and get_top_category().

◆ get_category() [2/3]

NotifyCategory * Notify::get_category ( const std::string &  basename,
const std::string &  parent_fullname 
)

Finds or creates a new Category given the basename of the category and the fullname of its parent.

This is another way to create a category when you don't have a pointer to its parent handy, but you know the name of its parent. If the parent Category does not already exist, it will be created.

Definition at line 218 of file notify.cxx.

References get_category().

◆ get_category() [3/3]

NotifyCategory * Notify::get_category ( const std::string &  fullname)

Finds or creates a new Category given the fullname of the Category.

This name should be a sequence of colon-separated names of parent Categories, ending in the basename of this Category, e.g. display:glxdisplay. This is a shorthand way to define a Category when a pointer to its parent is not handy.

Definition at line 230 of file notify.cxx.

References get_category(), and get_top_category().

◆ get_literal_flag()

ios_fmtflags Notify::get_literal_flag ( )
static

Returns a flag that may be set on the Notify stream via setf() that, when set, enables "literal" mode, which means the Notify stream will not attempt to do any fancy formatting (like word-wrapping).

Notify does not itself respect this flag; this is left up to the ostream that Notify writes to. Note that Notify just maps to cerr by default, in which case this does nothing. But the flag is available in case any extended types want to make use of it.

Definition at line 104 of file notify.cxx.

◆ get_ostream_ptr()

ostream * Notify::get_ostream_ptr ( ) const

Returns the system-wide ostream for all Notify messages.

Definition at line 89 of file notify.cxx.

◆ get_top_category()

NotifyCategory * Notify::get_top_category ( )

Returns the topmost Category in the hierarchy.

This may be used to traverse the hierarchy of available Categories.

Definition at line 169 of file notify.cxx.

References get_category().

Referenced by get_category().

◆ has_assert_failed()

bool Notify::has_assert_failed ( ) const
inline

Returns true if an assertion test has failed (and not been ignored) since the last call to clear_assert_failed().

When an assertion test fails, the assert handler may decide either to abort, return, or ignore the assertion. Naturally, if it decides to abort, this flag is irrelevant. If it chooses to ignore the assertion, the flag is not set. However, if the assert handler chooses to return out of the function (the normal case), it will also set this flag to indicate that an assertion failure has occurred.

This will also be the behavior in the absence of a user-defined assert handler.

Definition at line 29 of file pnotify.I.

◆ has_assert_handler()

bool Notify::has_assert_handler ( ) const

Returns true if a user assert handler has been installed, false otherwise.

Definition at line 151 of file notify.cxx.

Referenced by assert_failure().

◆ null()

ostream & Notify::null ( )
static

A convenient way to get an ostream that doesn't do anything.

Returned by Category::out() when a particular Category and/or Severity is disabled.

Definition at line 270 of file notify.cxx.

References ptr().

◆ out()

ostream & Notify::out ( )
static

A convenient way to get the ostream that should be written to for a Notify- type message.

Also see Category::out() for a message that is specific to a particular Category.

Definition at line 261 of file notify.cxx.

References ptr().

Referenced by write_string().

◆ ptr()

Notify * Notify::ptr ( )
static

Returns the pointer to the global Notify object.

There is only one of these in the world.

Definition at line 289 of file notify.cxx.

References init_memory_hook().

Referenced by null(), and out().

◆ set_assert_handler()

void Notify::set_assert_handler ( Notify::AssertHandler *  assert_handler)

Sets a pointer to a C function that will be called when an assertion test fails.

This function may decide what to do when that happens: it may choose to abort or return. If it returns, it should return true to indicate that the assertion should be respected (and the calling function should return out of its block of code), or false to indicate that the assertion should be completely ignored.

If an assert handler is installed, it completely replaces the default behavior of nassertr() and nassertv().

Definition at line 134 of file notify.cxx.

◆ set_ostream_ptr()

void Notify::set_ostream_ptr ( std::ostream *  ostream_ptr,
bool  delete_later 
)

Changes the ostream that all subsequent Notify messages will be written to.

If the previous ostream was set with delete_later = true, this will delete the previous ostream. If ostream_ptr is NULL, this resets the default to cerr.

Definition at line 71 of file notify.cxx.

◆ string_severity()

NotifySeverity Notify::string_severity ( const std::string &  string)
static

Given a string, one of "debug", "info", "warning", etc., return the corresponding Severity level, or NS_unspecified if none of the strings matches.

Definition at line 386 of file notify.cxx.

◆ write_string()

void Notify::write_string ( const std::string &  str)
static

A convenient way for scripting languages, which may know nothing about ostreams, to write to Notify.

This writes a single string, followed by an implicit newline, to the Notify output stream.

Definition at line 280 of file notify.cxx.

References out().


The documentation for this class was generated from the following files: