summaryrefslogtreecommitdiffstats
path: root/src/common/ostream_temp.h
blob: 722b189cd31ff84089600797698ac79dad64bdc1 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <sstream>

typedef enum {
  CLOG_DEBUG = 0,
  CLOG_INFO = 1,
  CLOG_SEC = 2,
  CLOG_WARN = 3,
  CLOG_ERROR = 4,
  CLOG_UNKNOWN = -1,
} clog_type;

class OstreamTemp
{
public:
  class OstreamTempSink {
  public:
    virtual void do_log(clog_type prio, std::stringstream& ss) = 0;
    virtual ~OstreamTempSink() {}
  };
  OstreamTemp(clog_type type_, OstreamTempSink *parent_);
  OstreamTemp(OstreamTemp &&rhs) = default;
  ~OstreamTemp();

  template<typename T>
  std::ostream& operator<<(const T& rhs)
  {
    return ss << rhs;
  }

private:
  clog_type type;
  OstreamTempSink *parent;
  std::stringstream ss;
};