LogTrace.cpp
Go to the documentation of this file.
1 #include "LogTrace.hpp"
2 
3 namespace iv
4 {
5 
6 thread_local LogTrace * LogTrace::first;
7 thread_local unsigned LogTrace::change_counter;
8 
10 {
11  // note the change
12  LogTrace::change_counter++;
13 
14  // add it to the end of stack
15  if( !LogTrace::first )
16  {
17  LogTrace::first = this;
18  this->previous = nullptr;
19  this->next = nullptr;
20  }
21  else
22  {
23  LogTrace * last = LogTrace::first;
24  while( last->next )
25  last = last->next;
26  last->next = this;
27  this->previous = last;
28  this->next = nullptr;
29  }
30 }
31 
33 {
34  // note the change
35  LogTrace::change_counter++;
36 
37  // remove it from the stack
38  if( this->previous )
39  this->previous->next = this->next;
40  else
41  LogTrace::first = this->next;
42 
43  if( this->next )
44  this->next->previous = this->previous;
45 }
46 
48 {
49  return LogTrace::change_counter;
50 }
51 
52 void LogTrace::PrintTrace( std::ostream & out )
53 {
54  LogTrace * current = LogTrace::first;
55  while( current )
56  {
57  current->PrintTraceLine( out );
58  current = current->next;
59  }
60 }
61 
62 LambdaLogTrace::LambdaLogTrace( std::function< void( std::ostream & ) > const & f ) :
63  _lambda( f )
64 {
65 }
66 
67 void LambdaLogTrace::PrintTraceLine( std::ostream & out )
68 {
69  this->_lambda( out );
70 }
71 
72 }