Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

kdebug.h

Go to the documentation of this file.
00001 #ifndef MINIKDE_KDEBUG_H
00002 #define MINIKDE_KDEBUG_H
00003 
00004 #include <stdio.h>
00005 
00006 #include <qstring.h>
00007 
00008 class kdbgstream;
00009 typedef kdbgstream & (*KDBGFUNC)(kdbgstream &); // manipulator function
00010 
00011 class kdbgstream {
00012  public:
00013     kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) :
00014       area(_area), level(_level),  print(_print) { }
00015     kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true) :
00016       output(QString::fromLatin1(initialString)), area(_area), level(_level),  print(_print) { }
00017     ~kdbgstream()
00018     {
00019       if (!output.isEmpty()) {
00020         fprintf(stderr,"ASSERT: debug output not ended with \\n\n");
00021         *this << "\n";
00022       }
00023     }
00024    kdbgstream &operator<<(bool i)  {
00025         if (!print) return *this;
00026         output += QString::fromLatin1(i ? "true" : "false");
00027         return *this;
00028     }
00029     kdbgstream &operator<<(short i)  {
00030         if (!print) return *this;
00031         QString tmp; tmp.setNum(i); output += tmp;
00032         return *this;
00033     }
00034     kdbgstream &operator<<(unsigned short i) {
00035         if (!print) return *this;
00036         QString tmp; tmp.setNum(i); output += tmp;
00037         return *this;
00038     }
00039     kdbgstream &operator<<(char i)  {
00040         if (!print) return *this;
00041         QString tmp; tmp.setNum(int(i)); output += tmp;
00042         return *this;
00043     }
00044     kdbgstream &operator<<(unsigned char i) {
00045         if (!print) return *this;
00046         QString tmp; tmp.setNum(static_cast<unsigned int>(i)); output += tmp;
00047         return *this;
00048     }
00049 
00050     kdbgstream &operator<<(int i)  {
00051         if (!print) return *this;
00052         QString tmp; tmp.setNum(i); output += tmp;
00053         return *this;
00054     }
00055     kdbgstream &operator<<(unsigned int i) {
00056         if (!print) return *this;
00057         QString tmp; tmp.setNum(i); output += tmp;
00058         return *this;
00059     }
00060     kdbgstream &operator<<(long i) {
00061         if (!print) return *this;
00062         QString tmp; tmp.setNum(i); output += tmp;
00063         return *this;
00064     }
00065     kdbgstream &operator<<(unsigned long i) {
00066         if (!print) return *this;
00067         QString tmp; tmp.setNum(i); output += tmp;
00068         return *this;
00069     }
00070     kdbgstream &operator<<(const QString& string) {
00071         if (!print) return *this;
00072         output += string;
00073         if (output.at(output.length() -1 ) == '\n')
00074             flush();
00075         return *this;
00076     }
00077     kdbgstream &operator<<(const char *string) {
00078         if (!print) return *this;
00079         output += QString::fromUtf8(string);
00080         if (output.at(output.length() - 1) == '\n')
00081             flush();
00082         return *this;
00083     }
00084     kdbgstream &operator<<(const QCString& string) {
00085       *this << string.data();
00086       return *this;
00087     }
00088     kdbgstream& operator<<(KDBGFUNC f) {
00089         if (!print) return *this;
00090         return (*f)(*this);
00091     }
00092     kdbgstream& operator<<(double d) {
00093       QString tmp; tmp.setNum(d); output += tmp;
00094       return *this;
00095     }
00096     void flush() {
00097       if (output.isEmpty() || !print)
00098         return;
00099       printf("%s",output.latin1());
00100       output = QString::null;
00101     }
00102  private:
00103     QString output;
00104     unsigned int area, level;
00105     bool print;
00106 };
00107 
00108 inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; }
00109 
00110 inline kdbgstream kdDebug(int area = 0) { return kdbgstream(area, 0); }
00111 
00112 #endif

Generated on Sat Nov 5 16:17:11 2005 for OPIE by  doxygen 1.4.2