Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ABSTRACTSTREAM_H
00028 #define ABSTRACTSTREAM_H
00029
00030 #include <QtCore>
00031
00032 #include "SharedObject.h"
00033 #include "QGpCoreToolsDLLExport.h"
00034
00035 namespace QGpCoreTools {
00036
00037 class QGPCORETOOLS_EXPORT AbstractStream: public SharedObject
00038 {
00039 public:
00040 AbstractStream();
00041 virtual ~AbstractStream();
00042
00043
00044 enum ClassId {StandardId=0, StringId, FileId, LogViewId, CustomId};
00045 virtual ClassId classId() const=0;
00046
00047 void setPrefix(const QString & prefix);
00048
00049 void freeze(bool b) {_frozen=b;}
00050 bool isFrozen() const {return _frozen;}
00051
00052 void setNext(AbstractStream * s) {_next=s;}
00053 AbstractStream * next() const {return _next;}
00054
00055 void setPrevious(AbstractStream * s);
00056 AbstractStream * previous() const {return _previous;}
00057
00058 AbstractStream& operator<<(const QString& val);
00059 AbstractStream& operator<<(int val) {return operator<<(QString::number(val));}
00060 AbstractStream& operator<<(double val) {return operator<<(QString::number(val));}
00061 AbstractStream& operator<<(const char * val) {return operator<<(QString(val));}
00062 AbstractStream& operator<<(QChar val) {return operator<<(QString(val));}
00063 AbstractStream& operator<<(char val) {return operator<<(QString(QChar::fromAscii(val)));}
00064 void endl();
00065 void flush();
00066 protected:
00067 virtual void sendToStream(const QString& val)=0;
00068 virtual void flushStream()=0;
00069
00070 void lock() {_mutex.lock();}
00071 void unlock() {_mutex.unlock();}
00072 private:
00073 inline QString timeStampedPrefix();
00074
00075 AbstractStream * _next, * _previous;
00076 bool _frozen, _lineOpen;
00077 enum PrefixType {NoPrefix, String, TimeStamp};
00078 PrefixType _prefixType;
00079 QString _prefix1, _prefix2;
00080 QMutex _mutex;
00081 };
00082
00083 typedef AbstractStream& (*AbstractStreamFunction)(AbstractStream&);
00084
00085 inline AbstractStream& operator<<(AbstractStream &s, AbstractStreamFunction f)
00086 {
00087 return (*f)(s);
00088 }
00089
00090 QGPCORETOOLS_EXPORT AbstractStream& endl(AbstractStream &s);
00091 QGPCORETOOLS_EXPORT AbstractStream& flush(AbstractStream &s);
00092
00093 }
00094
00095 #endif // ABSTRACTSTREAM_H