1 //  Copyright (C) 2010, Vaclav Haisman. All rights reserved.
2 //
3 //  Redistribution and use in source and binary forms, with or without modifica-
4 //  tion, are permitted provided that the following conditions are met:
5 //
6 //  1. Redistributions of  source code must  retain the above copyright  notice,
7 //     this list of conditions and the following disclaimer.
8 //
9 //  2. Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //
13 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
14 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
16 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
17 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
18 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
19 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
20 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
21 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
22 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 #include "dcmtk/oflog/mdc.h"
25 #include "dcmtk/oflog/internal/internal.h"
26 
27 
28 namespace dcmtk
29 {
30 namespace log4cplus
31 {
32 
33 
MDC()34 MDC::MDC ()
35 { }
36 
37 
~MDC()38 MDC::~MDC ()
39 { }
40 
41 
42 MappedDiagnosticContextMap *
getPtr()43 MDC::getPtr ()
44 {
45     return &internal::get_ptd ()->mdc_map;
46 }
47 
48 
49 void
clear()50 MDC::clear()
51 {
52     MappedDiagnosticContextMap * const dc = getPtr ();
53     MappedDiagnosticContextMap ().swap (*dc);
54 }
55 
56 
57 void
put(tstring const & key,tstring const & value)58 MDC::put (tstring const & key, tstring const & value)
59 {
60     MappedDiagnosticContextMap * const dc = getPtr ();
61     (*dc)[key] = value;
62 }
63 
64 
65 bool
get(tstring * value,tstring const & key) const66 MDC::get (tstring * value, tstring const & key) const
67 {
68     assert (value);
69 
70     MappedDiagnosticContextMap * const dc = getPtr ();
71     MappedDiagnosticContextMap::const_iterator it = dc->find (key);
72     if (it != dc->end ())
73     {
74         *value = it->second;
75         return true;
76     }
77     else
78         return false;
79 }
80 
81 
82 void
remove(tstring const & key)83 MDC::remove (tstring const & key)
84 {
85     MappedDiagnosticContextMap * const dc = getPtr ();
86     dc->erase (key);
87 }
88 
89 
90 MappedDiagnosticContextMap const &
getContext() const91 MDC::getContext () const
92 {
93     return *getPtr ();
94 }
95 
96 
97 } // namespace log4cplus
98 } // end namespace dcmtk
99