DebStream.cc 2.04 KB
Newer Older
1
// (C) Copyright 2020 by Autodesk, Inc.
2

3 4 5
#ifdef DEB_ON

#include "DebOut.hh"
6
#include "DebFile.hh"
7
#include "DebUtils.hh"
8
#include "DebConfig.hh"
9 10
#include "Base/Code/CodeLink.hh"
#include "Base/Test/ChecksumDebugEvent.hh"
11

12 13
namespace Debug
{
14

15
void warning(const std::string& _wrng, const Base::CodeLink& _lnk)
16
{
17
  TEST(Debug::warning, record(_wrng, _lnk));
18
  Stream strm(File::modify());
19
  strm << WARNING << ": " << _wrng << ' ' << _lnk << Base::ENDL;
20 21
}

22
void error(const std::string& _err, const Base::CodeLink& _lnk)
23
{
24
  TEST(Debug::error, record(_err, _lnk));
25
  Stream strm(File::modify());
26
  strm << ERROR << ": " << _err << ' ' << _lnk << Base::ENDL;
27 28 29 30
}

//////////////////////////////////////////////////////////////////////////

31 32 33 34
Enter::Enter(
    const char* const _flnm, const char* const _fnct, int& _nmbr, int& _lvl)
    : flnm_(_flnm), fnct_(_fnct), outs_(0), strm_(File::modify())
{ // TODO: for thread-safety we will need to make the constructor body atomic!
35
  strm_.file_.enter(this);
36
  nmbr_ = _nmbr++;
37 38

  if (_lvl == INVALID_LEVEL)
39
    _lvl = Config::query().custom_level(flnm_, fnct_);
40
  lvl_ = _lvl;
41

42
  static int id_cnt = 0;
43
  id_ = ++id_cnt;
44 45
}

46
Enter::~Enter() { strm_.file_.exit(); }
47

48
Stream& Enter::stream()
49
{
50
  if (outs_ < 1)
51
    strm_.file_.start();
52
  ++outs_;
53

54
  return strm_;
55 56
}

57
//////////////////////////////////////////////////////////////////////////
58

59
Stream::Stream(const Stream& _othr) : file_(_othr.file_) {}
60
Stream& Stream::operator=(const Stream&) { return *this; }
61

62 63
Base::IOutputStream& Stream::print(const int _i)
{
64
  file_.print(_i);
65 66 67 68
  return *this;
};

Base::IOutputStream& Stream::print(const size_t _i)
69
{
70
  file_.print(_i);
71 72 73
  return *this;
};

74 75 76 77 78 79
Base::IOutputStream& Stream::print(const float _f)
{
  file_.print(_f);
  return *this;
};

80
Base::IOutputStream& Stream::print(const double _d)
81
{
82
  file_.print(_d);
83 84 85
  return *this;
};

86
Base::IOutputStream& Stream::print(const char* _s)
87
{
88
  file_.print(_s);
89 90 91
  return *this;
};

92
Base::IOutputStream& Stream::print(const char _c)
93
{
94
  file_.print(_c);
95 96 97
  return *this;
};

98
} // namespace Debug
99

100
#endif // DEB_ON