00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NOTIFY_H
00020 #define NOTIFY_H
00021
00022 #include "dtoolbase.h"
00023
00024 #include "notifyCategory.h"
00025 #include "notifySeverity.h"
00026
00027 #include <string>
00028 #include <vector>
00029 #include <map>
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class EXPCL_DTOOLCONFIG Notify {
00046 PUBLISHED:
00047 Notify();
00048 ~Notify();
00049
00050 void set_ostream_ptr(ostream *ostream_ptr, bool delete_later);
00051 ostream *get_ostream_ptr() const;
00052
00053 typedef bool AssertHandler(const char *expression, int line,
00054 const char *source_file);
00055
00056 void set_assert_handler(AssertHandler *assert_handler);
00057 void clear_assert_handler();
00058 bool has_assert_handler() const;
00059 AssertHandler *get_assert_handler() const;
00060
00061 bool has_assert_failed() const;
00062 const string &get_assert_error_message() const;
00063 void clear_assert_failed();
00064
00065 NotifyCategory *get_top_category();
00066 NotifyCategory *get_category(const string &basename,
00067 NotifyCategory *parent_category);
00068 NotifyCategory *get_category(const string &basename,
00069 const string &parent_fullname);
00070 NotifyCategory *get_category(const string &fullname);
00071
00072 static ostream &out();
00073 static ostream &null();
00074 static void write_string(const string &str);
00075 static Notify *ptr();
00076
00077 public:
00078 static ios_fmtflags get_literal_flag();
00079
00080 bool assert_failure(const char *expression, int line,
00081 const char *source_file);
00082
00083 static NotifySeverity string_severity(const string &string);
00084
00085 void config_initialized();
00086
00087 private:
00088 ostream *_ostream_ptr;
00089 bool _owns_ostream_ptr;
00090 ostream *_null_ostream_ptr;
00091
00092 AssertHandler *_assert_handler;
00093 bool _assert_failed;
00094 string _assert_error_message;
00095
00096 typedef map<string, NotifyCategory *> Categories;
00097 Categories _categories;
00098
00099 static Notify *_global_ptr;
00100 };
00101
00102
00103
00104
00105
00106
00107
00108
00109 #define nout (Notify::out())
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 #ifdef NDEBUG
00134
00135 #define nassertr(condition, return_value)
00136 #define nassertv(condition)
00137 #define nassertd(condition) if (false)
00138
00139
00140 #define nassertr_always(condition, return_value) \
00141 { \
00142 if (!(condition)) { \
00143 return return_value; \
00144 } \
00145 }
00146
00147 #define nassertv_always(condition) \
00148 { \
00149 if (!(condition)) { \
00150 return; \
00151 } \
00152 }
00153
00154 #else // NDEBUG
00155
00156 #define nassertr(condition, return_value) \
00157 { \
00158 if (!(condition)) { \
00159 if (Notify::ptr()->assert_failure(#condition, __LINE__, __FILE__)) { \
00160 return return_value; \
00161 } \
00162 } \
00163 }
00164
00165 #define nassertv(condition) \
00166 { \
00167 if (!(condition)) { \
00168 if (Notify::ptr()->assert_failure(#condition, __LINE__, __FILE__)) { \
00169 return; \
00170 } \
00171 } \
00172 }
00173
00174 #define nassertd(condition) \
00175 if (!(condition) && \
00176 Notify::ptr()->assert_failure(#condition, __LINE__, __FILE__))
00177
00178 #define nassertr_always(condition, return_value) nassertr(condition, return_value)
00179 #define nassertv_always(condition) nassertv(condition)
00180
00181
00182 #endif // NDEBUG
00183
00184
00185 #include "notify.I"
00186
00187 #endif