Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:26

0001 //************************************************************
0002 // JStreamLogBuffer.h - streambuf-derived buffer for use with
0003 // JStreamLog.
0004 // Author:  Craig Bookwalter
0005 // Date:    Aug 2005
0006 // Notes:   Much of this was derived from examples given by
0007 //  D. Kuehl at http://www.inf.uni-konstanz.de/~kuehl/iostream/
0008 //  Also, many thanks to J. Hardie for his assistance with 
0009 //  obscure protected-member rules. 
0010 //*************************************************************
0011 
0012 #pragma once
0013 #include <iostream>
0014 #include <string.h>
0015 #include <pthread.h>
0016 #include <string>
0017 #include <sstream>
0018 #include <map>
0019 
0020 
0021 extern pthread_mutex_t jstreamlog_mutex;
0022 
0023 
0024 /// JStreamLogBuffer is a streambuf-derived buffer for use
0025 /// with JLogStream. Unless you're writing your own stream,
0026 /// you shouldn't ever need this class. It's basically a 
0027 /// wrapper for a passed-in streambuf with the tweak that
0028 /// it appends a prefix to each output statement, namely
0029 /// a status label and a timestamp. 
0030 ///
0031 
0032 class JStreamLogBuffer : public std::streambuf
0033 {
0034     private:
0035         std::streambuf* __sbuf;
0036         char*           __tag;
0037 //      bool            __newline;
0038         bool            __prepend_timestamp;
0039         bool            __prepend_threadstamp;
0040 
0041     protected:
0042         int overflow(int c);
0043         int sync();
0044         std::string getThreadStamp();
0045         std::string getTimeStamp();
0046 
0047         // keep a buffer for each thread that tries to write so only
0048         // complete messages are written to the screen.
0049         std::map<pthread_t,std::string> thr_buffers;
0050 
0051     public:
0052         JStreamLogBuffer(std::streambuf* buf, const char* tag);
0053         virtual ~JStreamLogBuffer();
0054 
0055         std::string GetTag(void){return std::string(__tag);}
0056         bool GetTimestampFlag(void){return __prepend_timestamp;}
0057         bool GetThreadstampFlag(void){return __prepend_threadstamp;}
0058         void SetTag(std::string tag);
0059         void SetTimestampFlag(bool prepend_timestamp=true){__prepend_timestamp=prepend_timestamp;}
0060         void SetThreadstampFlag(bool prepend_threadstamp=true){__prepend_threadstamp=prepend_threadstamp;}
0061 };
0062