DebFile.hh 1.37 KB
Newer Older
1
// (C) Copyright 2019 by Autodesk, Inc.
2
3
4
5
6
7

#ifndef BASE_DEBFILE_HH_INCLUDED
#define BASE_DEBFILE_HH_INCLUDED
#ifdef DEB_ON

#include <Base/Utils/IOutputStream.hh>
8
9
10
#include <Base/Debug/DebConfig.hh>

#include <string>
11
12
13

namespace Debug {
typedef unsigned int uint;
14
using Base::ENDL;
15
16
17
class Enter;

//! Debug file.
18
19
20
class File
{
public:
21
  static const File& query();
22
23
24
  static File& modify();

public:
25
  const char* double_format = "%.17g";
26

27
28
  bool no_log() const { return flnm_ == nullptr; }
  bool log() const { return !no_log(); }
29

30
31
32
  void enter(const Enter* const _entr);
  void start();
  void exit();
33

34
35
36
  void print(const char _c) { print(_c, true); }
  void print(const char* const _s);
  void print(const std::string& _s);
37
38
  void print(const size_t _i);
  void print(const int _i);
39
  void print(float _f);
40
41
  void print(double _d);

42
43
44
45
46
47
private:
  int flush_nmbr_ = 0;
  bool line_strt_ = true; // are we at the start of the line?
  Config::print_function cnsl_prnt_ = Config::query().console_print;
  const char* const flnm_ = Config::query().log_filename;
  std::string* bffr_ = nullptr;
48

49
50
private:
  ~File();
51

52
  bool flushed() const { return flush_nmbr_ > 0; }
53

54
55
56
  void print_header();
  void print_footer();
  void print_time();
57

58
59
60
  void print(const char _c, const bool _cnsl);
  void line_break(const bool _cnsl = true);
  void flush();
61
62
63
64
65
66
};

}//namespace Debug

#endif//DEB_ON
#endif//BASE_DEBFILE_HH_INCLUDED