NDC.cpp
Go to the documentation of this file.
1 /*
2  * NDC.cpp
3  *
4  * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5  * Copyright 2000, Bastiaan Bakker. All rights reserved.
6  *
7  * See the COPYING file for the terms of usage and distribution.
8  */
9 
10 #include "PortabilityImpl.hh"
11 #include <log4cpp/NDC.hh>
13 
14 namespace log4cpp {
15 
16  NDC::DiagnosticContext::DiagnosticContext(const std::string& message) :
17  message(message),
18  fullMessage(message) {
19  }
20 
22  const DiagnosticContext& parent) :
23  message(message),
24  fullMessage(parent.fullMessage + " " + message) {
25  }
26 
27  bool NDC::isUsedNDC = false;
28  const std::string NDC::emptyString = "";
29 
30  namespace {
32  }
33 
34  void NDC::clear() {
35  getNDC()._clear();
36  }
37 
39  return getNDC()._cloneStack();
40  }
41 
42  const std::string& NDC::get() {
43  if (isUsedNDC)
44  return getNDC()._get();
45  else
46  return emptyString;
47  }
48 
49  size_t NDC::getDepth() {
50  return getNDC()._getDepth();
51  }
52 
54  getNDC()._inherit(stack);
55  }
56 
57  std::string NDC::pop() {
58  return getNDC()._pop();
59  }
60 
61  void NDC::push(const std::string& message) {
62  if (!isUsedNDC)
63  isUsedNDC = true;
64  getNDC()._push(message);
65  }
66 
67  void NDC::setMaxDepth(int maxDepth) {
68  getNDC()._setMaxDepth(maxDepth);
69  }
70 
72  NDC* nDC = _nDC.get();
73 
74  if (!nDC) {
75  nDC = new NDC();
76  _nDC.reset(nDC);
77  }
78 
79  return *nDC;
80  }
81 
83  }
84 
86  }
87 
88  void NDC::_clear() {
89  _stack.clear();
90  }
91 
93  return new ContextStack(_stack);
94  }
95 
96  const std::string& NDC::_get() const {
97  static std::string empty = "";
98 
99  return (_stack.empty() ? empty : _stack.back().fullMessage);
100  }
101 
102  size_t NDC::_getDepth() const {
103  return _stack.size();
104  }
105 
107  _stack = *stack;
108  }
109 
110  std::string NDC::_pop() {
111  std::string result = _stack.back().message;
112  _stack.pop_back();
113  return result;
114  }
115 
116  void NDC::_push(const std::string& message) {
117  if (_stack.empty()) {
118  _stack.push_back(DiagnosticContext(message));
119  } else {
120  _stack.push_back(DiagnosticContext(message, _stack.back()));
121  }
122  }
123 
124  void NDC::_setMaxDepth(int maxDepth) {
125  // XXX no maximum
126  }
127 
128 }
virtual void _push(const std::string &message)
Definition: NDC.cpp:116
ContextStack _stack
Definition: NDC.hh:177
virtual const std::string & _get() const
Definition: NDC.cpp:96
static void setMaxDepth(int maxDepth)
Definition: NDC.cpp:67
virtual size_t _getDepth() const
Definition: NDC.cpp:102
DiagnosticContext(const std::string &message)
Definition: NDC.cpp:16
static NDC & getNDC()
Definition: NDC.cpp:71
static const std::string & get()
Definition: NDC.cpp:42
std::vector< DiagnosticContext > ContextStack
Definition: NDC.hh:87
virtual void _setMaxDepth(int maxDepth)
Definition: NDC.cpp:124
virtual void _inherit(ContextStack *stack)
Definition: NDC.cpp:106
static bool isUsedNDC
Definition: NDC.hh:74
static void push(const std::string &message)
Definition: NDC.cpp:61
static size_t getDepth()
Definition: NDC.cpp:49
virtual void _clear()
Definition: NDC.cpp:88
static void inherit(ContextStack *stack)
Definition: NDC.cpp:53
static ContextStack * cloneStack()
Definition: NDC.cpp:38
virtual std::string _pop()
Definition: NDC.cpp:110
virtual ContextStack * _cloneStack()
Definition: NDC.cpp:92
static const std::string emptyString
Definition: NDC.hh:75
virtual ~NDC()
Definition: NDC.cpp:85
static std::string pop()
Definition: NDC.cpp:57
static void clear()
Definition: NDC.cpp:34


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:14:17