LogTrace.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 #include <iostream>
5 
6 namespace iv
7 {
8 
16 class LogTrace
17 {
18 public:
19  LogTrace();
20  ~LogTrace();
21 
22  LogTrace( LogTrace const & ) = delete;
23  LogTrace & operator=( LogTrace const & ) = delete;
24 
29  static void PrintTrace( std::ostream & );
30 
35  static unsigned GetChangeCounter();
36 
37 protected:
43  virtual void PrintTraceLine( std::ostream & ) = 0;
44 
45 private:
46  LogTrace * previous;
47  LogTrace * next;
48  static thread_local LogTrace * first;
49  static thread_local unsigned change_counter;
50 };
51 
52 
53 class LambdaLogTrace : public LogTrace
54 {
55 public:
56  LambdaLogTrace( std::function< void( std::ostream & ) > const & f );
57 
58 protected:
59  virtual void PrintTraceLine( std::ostream & ) override;
60 
61 private:
62  std::function< void( std::ostream & ) > _lambda;
63 };
64 
65 }