File: debug.cc

package info (click to toggle)
pdf2djvu 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,388 kB
  • ctags: 771
  • sloc: cpp: 5,869; sh: 4,283; xml: 780; makefile: 160; python: 24
file content (52 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download | duplicates (4)
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
/* Copyright © 2007, 2008, 2009 Jakub Wilk
 *
 * This package is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 dated June, 1991.
 */

#include "debug.hh"

class DevNull : public std::ostream
{
public:
  DevNull()
  : std::ostream(0)
  { }
};

static DevNull static_dev_null;
std::ostream &dev_null = static_dev_null;

DebugStream error_log(std::cerr);
static DebugStream null_debug(dev_null);
static DebugStream full_debug(std::clog);

DebugStream &debug(int n, int threshold)
{
  if (n <= threshold)
    return full_debug;
  else
    return null_debug;
}

void DebugStream::indent()
{
  unsigned int level = this->level;
  if (level > 0)
  {
    while (level-- > 1)
      this->ostream << "  ";
    this->ostream << "- ";
  }
}

DebugStream &operator<<(DebugStream &stream, std::ostream& (*pf)(std::ostream&))
{
  if (pf == static_cast<std::ostream& (*)(std::ostream&)>(std::endl))
    stream.started = false;
  stream.ostream << pf;
  return stream;
}

// vim:ts=2 sw=2 et