00001 #ifndef WARN_ONCE_IS_INCLUDED 00002 #define WARN_ONCE_IS_INCLUDED 00003 00004 #include "support.H" 00005 00006 /***************************************************************** 00007 * WarnOnce: 00008 * 00009 * For when you want to print an error message about something, 00010 * but once is enough, instead of over and over, every frame, 00011 * like a brainless ninny. 00012 *****************************************************************/ 00013 class WarnOnce { 00014 public: 00015 WarnOnce(Cstr_ptr& msg) : _msg(msg), _done(false) {} 00016 00017 // Print the message if it's the first time: 00018 void warn() { 00019 if (!_done) { 00020 _done = true; 00021 cerr << **_msg << endl; 00022 } 00023 } 00024 00025 // Print the message if the condition is false: 00026 void check(bool condition) { 00027 if (!condition) 00028 warn(); 00029 } 00030 00031 protected: 00032 str_ptr _msg; // message to print 00033 bool _done; // true if it's been printed already 00034 }; 00035 00036 #endif // WARN_ONCE_IS_INCLUDED 00037 00038 /* end of file warn_once.H */