ESyS-Particle  4.0.1
console.h
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 #ifndef _CONSOLE_H_
00014 #define _CONSOLE_H_
00015 
00016 //--project includes--
00017 #include "Foundation/Matrix3.h"
00018 #include "Foundation/vec3.h"
00019 
00020 //--STL includes--
00021 #include <string>
00022 #include <sstream>
00023 #include <fstream>
00024 
00025 using std::string;
00026 using std::ostringstream;
00027 
00028 class CCounter;
00029 class CCounterList;
00030 
00039 class BasicCon 
00040 {
00041 public:
00042   enum VerboseLevel { all=0, dbg, info, msg, warning, err, critical, silent } ;
00043     
00044 protected:
00045   static int VLevel ;           
00046   static bool mute,quiet ;      
00047   static bool timing;
00048     
00049   char *CurBuffer ;             
00050   ostream *os ;                 
00051 
00052   virtual void process(ostringstream *str_os) ;
00053   virtual void show(char *level,bool h) ;
00054     
00055 public:
00056   BasicCon();
00057   BasicCon(ostream *Ios);
00058   virtual ~BasicCon() ;
00059     
00060   inline void SetQuiet(bool Q) { quiet = Q ; };  
00061   inline void SetTiming(bool T) { timing = T ; };  
00062   static void SetVerbose(int vl=all) ; 
00063   inline static int GetVerbose() { return VLevel; } ;
00064 
00065   virtual void flush() ;
00066   
00067   virtual void SetOStream(ostream *Ios);
00068             
00069   BasicCon & Message(bool h=true) ;  
00070   BasicCon & Error(bool h=true) ;    
00071   BasicCon & Warning(bool h=true) ;  
00072   BasicCon & Critical(bool h=true) ; 
00073   BasicCon & Info(bool h=true) ;     
00074   BasicCon & Debug(bool h=true) ;    
00075   BasicCon & XDebug(bool h=true) ;   
00076   BasicCon & Timing(bool h=true) ;   
00077     
00078   BasicCon &  operator<<(const char* s);
00079   BasicCon &  operator<<(char s);
00080   BasicCon &  operator<<(short s) ;
00081   BasicCon &  operator<<(int s) ;
00082   BasicCon &  operator<<(long s) ;
00083   BasicCon &  operator<<(float s) ;
00084   BasicCon &  operator<<(double s) ;
00085   BasicCon &  operator<<(unsigned char s) ;
00086   BasicCon &  operator<<(unsigned short s);
00087   BasicCon &  operator<<(unsigned int s);
00088   BasicCon &  operator<<(unsigned long s);
00089   BasicCon &  operator<<(void* s) ;
00090   BasicCon &  operator<<(Vec3 s);
00091   BasicCon &  operator<<(const Matrix3&);
00092   BasicCon &  operator<<(CCounter &s);
00093   BasicCon &  operator<<(CCounterList &s);
00094   BasicCon &  operator<<(const string&);
00095 } ;
00096 
00101 class ConsoleWindow {
00102 protected:
00103   static ConsoleWindow* Window ;
00104   virtual void UpdateCon() = 0 ;
00105 public:
00106   virtual ~ConsoleWindow() {}
00107   static bool immediate ;
00108   static void Update() ;
00109   static bool IsOpen() { return Window!=NULL ; } ;
00110 } ;
00111 
00116 class Con : public BasicCon {
00117 private:
00118   int CurCol ;
00119   char Buffer[4096] ;
00120 protected:
00121   virtual void process(ostringstream *str_os) ;
00122   Con();
00123 
00124 public:
00125   Con(ostream *Ios);
00126   virtual ~Con() ;
00127   virtual char *GetLast(char *buff) ;
00128 } ;
00129 
00134 class FCon : public Con
00135 {
00136   private:
00137   std::ofstream m_debugfile;
00138 
00139  public:
00140   FCon();
00141   virtual ~FCon() ;
00142 };
00143 
00144 
00145 
00146 #ifdef _ENABLE_DEBUG_FILE
00147 extern FCon console ;
00148 #else
00149 extern Con console ;
00150 #endif // _ENABLE_DEBUG_FILE
00151 extern BasicCon tconsole ;
00152 
00153 
00154 #endif