Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

ndc.h

Go to the documentation of this file.
00001 // Module:  Log4CPLUS
00002 // File:    ndc.h
00003 // Created: 6/2001
00004 // Author:  Tad E. Smith
00005 //
00006 //
00007 // Copyright (C) Tad E. Smith  All rights reserved.
00008 //
00009 // This software is published under the terms of the Apache Software
00010 // License version 1.1, a copy of which has been included with this
00011 // distribution in the LICENSE.APL file.
00012 //
00013 
00018 #ifndef _LO4CPLUS_NDC_HEADER_
00019 #define _LO4CPLUS_NDC_HEADER_
00020 
00021 #include <log4cplus/config.h>
00022 #include <log4cplus/tstring.h>
00023 #include <log4cplus/helpers/logloguser.h>
00024 #include <log4cplus/helpers/threads.h>
00025 
00026 #include <map>
00027 #include <stack>
00028 
00029 #if (defined(__MWERKS__) && defined(__MACOS__))
00030 using std::size_t;
00031 #endif
00032 
00033 
00034 namespace log4cplus {
00035     // Forward declarations
00036     class NDC;
00037     struct DiagnosticContext;
00038     typedef std::stack<DiagnosticContext> DiagnosticContextStack;
00039 
00043     LOG4CPLUS_EXPORT NDC& getNDC();
00044 
00109     class LOG4CPLUS_EXPORT NDC : protected log4cplus::helpers::LogLogUser {
00110     public:
00119         void clear();
00120 
00134         DiagnosticContextStack cloneStack();
00135 
00150         void inherit(const DiagnosticContextStack& stack);
00151 
00155         log4cplus::tstring get();
00156 
00162         size_t getDepth();
00163 
00175         log4cplus::tstring pop();
00176 
00186         log4cplus::tstring peek();
00187 
00198         void push(const log4cplus::tstring& message);
00199 
00207         void remove();
00208 
00239         void setMaxDepth(size_t maxDepth);
00240 
00241       // Dtor
00242         ~NDC();
00243 
00244     private:
00245       // Methods
00246         DiagnosticContextStack* getPtr()
00247             { return static_cast<DiagnosticContextStack*>
00248                           (LOG4CPLUS_GET_THREAD_LOCAL_VALUE( threadLocal )); }
00249 
00250       // Data
00251         LOG4CPLUS_THREAD_LOCAL_TYPE threadLocal;
00252 
00253       // Disallow construction (and copying) except by getNDC()
00254         NDC();
00255         NDC(const NDC&);
00256         NDC& operator=(const NDC&);
00257 
00258       // Friends
00259         friend LOG4CPLUS_EXPORT NDC& getNDC();
00260     };
00261 
00262 
00263 
00267     struct LOG4CPLUS_EXPORT DiagnosticContext {
00268       // Ctors
00269         DiagnosticContext(const log4cplus::tstring& message, DiagnosticContext *parent);
00270         DiagnosticContext(const log4cplus::tstring& message);
00271 
00272       // Data
00273         log4cplus::tstring message; 
00274         log4cplus::tstring fullMessage; 
00275     };
00276 
00277 
00282     class LOG4CPLUS_EXPORT NDCContextCreator {
00283     public:
00285         NDCContextCreator(const log4cplus::tstring& msg) { getNDC().push(msg); }
00286 
00288         ~NDCContextCreator() { getNDC().pop(); }
00289     };
00290 
00291 } // end namespace log4cplus
00292 
00293 
00294 #endif // _LO4CPLUS_NDC_HEADER_

Generated on Mon Feb 9 09:10:30 2004 for log4cplus by doxygen 1.3.2