Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

output.h

By: a guest on Feb 7th, 2011  |  syntax: C++  |  size: 0.80 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifndef OUTPUT_H
  2. #define OUTPUT_H
  3.  
  4. #include <iostream>
  5. #include <sstream>
  6. #include <QString>
  7.  
  8. class Output: public std::ostream
  9. {
  10.     friend std::ostream& operator<<(std::ostream &out, const QString var);
  11. private:
  12.  
  13.     class StreamBuffer: public std::stringbuf
  14.     {
  15.     private:
  16.         std::ostream &out;
  17.         QString prefix;
  18.  
  19.     public:
  20.         StreamBuffer(std::ostream& str, const QString &p);
  21.  
  22.         //Kada se pozove sync funkcija:
  23.         //1) Ispisemo prefix, onda sadrzaj buffera
  24.         //2) Resetiramo buffer
  25.         //3) pozovemo flush stvarnog objekta koji koristimo za ispis
  26.         virtual int sync();
  27.     };
  28.  
  29.     //Ova klasa samo koristi specijalnu verziju buffera
  30.     StreamBuffer buffer;
  31.  
  32. public:
  33.     Output(const QString &prefix);
  34.  
  35.  
  36. };
  37.  
  38.  
  39. #endif // OUTPUT_H