Alert.h

Go to the documentation of this file.
00001 #ifndef _ALERT_
00002 #define _ALERT_
00003 
00004 #include <sstream>
00005 #include <string>
00006 
00007 class Alert {
00008 public:
00009   enum Mode_t {
00010     MODE_ERR,
00011     MODE_WARN,
00012     MODE_MSG
00013   };
00014 
00015   struct ERROR {};
00016   struct WARNING {};
00017   struct MESSAGE {};
00018   
00019   struct SHOW {};
00020 
00021 public:
00022   Alert() : mode(MODE_MSG) {}
00023   virtual ~Alert() {}
00024 
00025   virtual void display();
00026 
00027 protected:
00028   std::string msg;
00029   Mode_t mode;
00030 
00031   friend Alert& operator<<(Alert& a, const std::string &s);
00032   friend Alert& operator<<(Alert& a, ERROR);
00033   friend Alert& operator<<(Alert& a, WARNING);
00034   friend Alert& operator<<(Alert& a, MESSAGE);
00035 };
00036 
00037 template<typename T>
00038 Alert& operator<<(Alert& a, const T &o)
00039 {
00040   std::ostringstream os;
00041   os << o;
00042   return a << os.str();
00043 }
00044 
00045 Alert& 
00046 operator<<(Alert& a, const std::string &s);
00047 inline Alert& 
00048 operator<<(Alert& a, Alert::ERROR) { a.mode = Alert::MODE_ERR; return a;}
00049 inline Alert&
00050 operator<<(Alert& a, Alert::WARNING) { a.mode = Alert::MODE_WARN; return a; }
00051 inline Alert&
00052 operator<<(Alert& a, Alert::MESSAGE) { a.mode = Alert::MODE_MSG; return a; }
00053 inline Alert&
00054 operator<<(Alert& a, Alert::SHOW) { a.display(); return a; }
00055 
00056 extern Alert& alert;
00057 
00058 #endif

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7