33class EXPCL_DTOOL_PRC Notify {
38#if defined(CPPPARSER) && defined(HAVE_PYTHON)
45 typedef bool AssertHandler(
const char *expression,
int line,
46 const char *source_file);
61 const std::string &parent_fullname);
64 static std::ostream &
out();
65 static std::ostream &
null();
73 const char *source_file);
75 const char *source_file);
82 std::ostream *_ostream_ptr;
83 bool _owns_ostream_ptr;
84 std::ostream *_null_ostream_ptr;
86 AssertHandler *_assert_handler;
88 std::string _assert_error_message;
92 typedef std::map<std::string, NotifyCategory *> Categories;
93 Categories _categories;
95 static Notify *_global_ptr;
104#define nout (Notify::out())
131#define _nassert_check(condition) (__builtin_expect(!(condition), 0))
133#define _nassert_check(condition) (!(condition))
138#define nassertr(condition, return_value)
139#define nassertv(condition)
140#define nassertd(condition) if (false)
143#define nassertr_always(condition, return_value) \
145 if (_nassert_check(condition)) { \
146 return return_value; \
150#define nassertv_always(condition) \
152 if (_nassert_check(condition)) { \
157#define nassert_raise(message) Notify::write_string(message)
161#define nassertr(condition, return_value) \
163 if (_nassert_check(condition)) { \
164 if (Notify::ptr()->assert_failure(#condition, __LINE__, __FILE__)) { \
165 return return_value; \
170#define nassertv(condition) \
172 if (_nassert_check(condition)) { \
173 if (Notify::ptr()->assert_failure(#condition, __LINE__, __FILE__)) { \
179#define nassertd(condition) \
180 if (_nassert_check(condition) && \
181 Notify::ptr()->assert_failure(#condition, __LINE__, __FILE__))
183#define nassertr_always(condition, return_value) nassertr(condition, return_value)
184#define nassertv_always(condition) nassertv(condition)
186#define nassert_raise(message) Notify::ptr()->assert_failure(message, __LINE__, __FILE__)
190#if __cplusplus >= 201103
191#define __nassert_static(condition, line, file) static_assert((condition), #condition " at line " #line " of " file)
192#define _nassert_static(condition, line, file) __nassert_static(condition, line, file)
193#define nassert_static(condition) _nassert_static(condition, __LINE__, __FILE__)
195#define __nassert_static(condition, suffix) typedef char nassert_static_ ## suffix [(condition) ? 1 : -1];
196#define _nassert_static(condition, suffix) __nassert_static(condition, suffix)
197#define nassert_static(condition) _nassert_static(condition, __COUNTER__)
A particular category of error messages.
static std::ostream & out()
A convenient way to get the ostream that should be written to for a Notify- type message.
static void write_string(const std::string &str)
A convenient way for scripting languages, which may know nothing about ostreams, to write to Notify.
void clear_assert_handler()
Removes the installed assert handler and restores default behavior of nassertr() and nassertv().
void set_assert_handler(AssertHandler *assert_handler)
Sets a pointer to a C function that will be called when an assertion test fails.
NotifyCategory * get_top_category()
Returns the topmost Category in the hierarchy.
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.
void config_initialized()
Intended to be called only by Config, this is a callback that indicates to Notify when Config has don...
std::ostream * get_ostream_ptr() const
Returns the system-wide ostream for all Notify messages.
static NotifySeverity string_severity(const std::string &string)
Given a string, one of "debug", "info", "warning", etc., return the corresponding Severity level,...
const std::string & get_assert_error_message() const
Returns the error message that corresponds to the assertion that most recently failed.
AssertHandler * get_assert_handler() const
Returns a pointer to the user-installed assert handler, if one was installed, or NULL otherwise.
void clear_assert_failed()
Resets the assert_failed flag that is set whenever an assertion test fails.
bool has_assert_failed() const
Returns true if an assertion test has failed (and not been ignored) since the last call to clear_asse...
static std::ostream & null()
A convenient way to get an ostream that doesn't do anything.
NotifyCategory * 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 hie...
static Notify * ptr()
Returns the pointer to the global Notify object.
bool has_assert_handler() const
Returns true if a user assert handler has been installed, false otherwise.
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...
void set_ostream_ptr(std::ostream *ostream_ptr, bool delete_later)
Changes the ostream that all subsequent Notify messages will be written to.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.