summaryrefslogtreecommitdiff
path: root/libcult/cult/trace/record.hxx
blob: 90276dd5c85617ae0fa7ce1e898775a45411e9c8 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// file      : cult/trace/record.hxx
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef CULT_TRACE_RECORD_HXX
#define CULT_TRACE_RECORD_HXX

#include <cult/types/fundamental.hxx>

#include <cstring> // memset
#include <ostream>
#include <streambuf>

namespace Cult
{
  namespace Trace
  {
    class Record: public NonCopyable
    {
    public:
      Record (Char const* id, Int level);

    public:
      Char const*
      text () const;

      Char const*
      id () const;

      Int
      level () const;

      Void
      level (Int);

    public:
      template <typename T>
      Record&
      operator<< (T const& arg);

    private:
      Char const* id_;
      Int level_;

      //@@ need to wrap streambuf.
      //
      class FixedBuffer : public std::streambuf
      {
      public:
        FixedBuffer (Char* buf, Size size)
        {
          std::memset (buf, 0, size);
          setp (buf, buf + size - 1);
        };

        virtual int_type
        overflow (int_type c)
        {
          return c;
        }
      };

#ifndef CULT_TRACE_NULL
      char buf_[1024];
      FixedBuffer sbuf_;
      std::ostream os_;
#endif
    };
  }
}

#ifndef CULT_TRACE_NULL

#include <cult/trace/record.ixx>
#include <cult/trace/record.txx>

#else

#include <cult/trace/null/record.ixx>
#include <cult/trace/null/record.txx>

#endif


#endif  // CULT_TRACE_RECORD_HXX