File: logbuffer

package info (click to toggle)
bobcat 1.11.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,344 kB
  • ctags: 473
  • sloc: makefile: 12,078; cpp: 5,121; ansic: 63; sh: 14
file content (72 lines) | stat: -rw-r--r-- 1,667 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef _INCLUDED_BOBCAT_LOGBUFFER_
#define _INCLUDED_BOBCAT_LOGBUFFER_

#include <streambuf>
#include <ostream>
#include <string>

namespace FBB
{

enum TimeStamps
{
    NOTIMESTAMPS,
    TIMESTAMPS
};

class LogBuffer: public std::streambuf
{
    std::ostream *d_stream; // the stream to insert info to
    bool d_insertTimestamp; // write the timestamp or not
    bool d_active;          // actually write information or not
    bool d_empty;           // set to true at the beginning, after writing \n
    std::string d_delim;    // delimiter following time stamps

    public:
        LogBuffer(TimeStamps timestamps = TIMESTAMPS,  // output to cerr
                bool active = true,
                char const *delim = " ");
        LogBuffer(std::ostream &stream, 
                TimeStamps timestamps = TIMESTAMPS,
                bool active = true,
                char const *delim = " ");

        void setStream(std::ostream &stream)
        {
            d_stream = &stream;
        }
        bool empty() const
        {
            return d_empty;
        }

        virtual int overflow(int c);
        virtual int sync()
        {
            d_stream->flush();
            return 0;
        }

        void setActive(bool active)
        {
            d_active = active;
        }
        void settimestamp(TimeStamps timestamps, char const *delim = " ");

        void setEmpty(bool empty)
        {
            d_empty = empty;
        }

    private:
        void insertTimestamp();
        LogBuffer(LogBuffer const &other);              // NI
        LogBuffer &operator=(LogBuffer const &other);   // NI
};

} /* FBB */
        
#endif