File: NDC.cpp

package info (click to toggle)
log4cpp 0.2.5-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,436 kB
  • ctags: 524
  • sloc: sh: 6,657; cpp: 1,960; ansic: 421; makefile: 334
file content (112 lines) | stat: -rw-r--r-- 2,366 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * NDC.cpp
 *
 * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
 * Copyright 2000, Bastiaan Bakker. All rights reserved.
 *
 * See the COPYING file for the terms of usage and distribution.
 */

#include "log4cpp/Portability.hh"
#include "log4cpp/NDC.hh"

namespace log4cpp {

    NDC::DiagnosticContext::DiagnosticContext(const std::string& message) :
        message(message),
        fullMessage(message) {
    }

    NDC::DiagnosticContext::DiagnosticContext(const std::string& message, 
            const DiagnosticContext& parent) :
        message(message),
        fullMessage(parent.message + " " + message) {
    }

    NDC NDC::_nDC;

    void NDC::clear() {
        getNDC()._clear();
    }

    NDC::ContextStack* NDC::cloneStack() {
        return getNDC()._cloneStack();
    }

    const std::string& NDC::get() {
        return getNDC()._get();
    }

    int NDC::getDepth() {
        return getNDC()._getDepth();
    }

    void NDC::inherit(NDC::ContextStack* stack) {
        getNDC()._inherit(stack);
    }

    std::string NDC::pop() {
        return getNDC()._pop();
    }

    void NDC::push(const std::string& message) {
        getNDC()._push(message);
    }

    void NDC::setMaxDepth(int maxDepth) {
        getNDC()._setMaxDepth(maxDepth);
    }

    NDC& NDC::getNDC() {
        return _nDC;
    }

    NDC::NDC() {
    }

    NDC::~NDC() {
    }

    void NDC::_clear() {
        _stack.clear();
    }

    NDC::ContextStack* NDC::_cloneStack() {
        return new ContextStack(_stack);
    }

    const std::string& NDC::_get() const {
        static std::string empty = "";

        return _stack.empty() ?
            empty :
            _stack.back().fullMessage;
    }

    int NDC::_getDepth() const {
        return _stack.size();
    }

    void NDC::_inherit(NDC::ContextStack* stack) {
        _stack = *stack;
    }

    std::string NDC::_pop() {
        std::string result = _stack.back().message;
        _stack.pop_back();
        return result;
    }

    void NDC::_push(const std::string& message) {
        if (_stack.empty()) {
            _stack.push_back(DiagnosticContext(message));
        } else {            
            _stack.push_back(DiagnosticContext(message, _stack.back()));
        }
    }

    void NDC::_setMaxDepth(int maxDepth) {
        // XXX no maximum
    }

}