log4cplus  1.1.0
ndc.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    ndc.h
00004 // Created: 6/2001
00005 // Author:  Tad E. Smith
00006 //
00007 //
00008 // Copyright 2001-2010 Tad E. Smith
00009 //
00010 // Licensed under the Apache License, Version 2.0 (the "License");
00011 // you may not use this file except in compliance with the License.
00012 // You may obtain a copy of the License at
00013 //
00014 //     http://www.apache.org/licenses/LICENSE-2.0
00015 //
00016 // Unless required by applicable law or agreed to in writing, software
00017 // distributed under the License is distributed on an "AS IS" BASIS,
00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 // See the License for the specific language governing permissions and
00020 // limitations under the License.
00021 
00026 #ifndef _LO4CPLUS_NDC_HEADER_
00027 #define _LO4CPLUS_NDC_HEADER_
00028 
00029 #include <log4cplus/config.hxx>
00030 
00031 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00032 #pragma once
00033 #endif
00034 
00035 #include <log4cplus/tstring.h>
00036 
00037 #include <map>
00038 #include <deque>
00039 
00040 
00041 namespace log4cplus {
00042     // Forward declarations
00043     struct DiagnosticContext;
00044     typedef std::deque<DiagnosticContext> DiagnosticContextStack;
00045 
00111     class LOG4CPLUS_EXPORT NDC
00112     {
00113     public:
00122         void clear();
00123 
00137         DiagnosticContextStack cloneStack() const;
00138 
00153         void inherit(const DiagnosticContextStack& stack);
00154 
00158         log4cplus::tstring const & get() const;
00159 
00165         std::size_t getDepth() const;
00166 
00183         log4cplus::tstring pop();
00184 
00188         void pop_void ();
00189 
00199         log4cplus::tstring const & peek() const;
00200 
00212         void push(const log4cplus::tstring& message);
00213         void push(tchar const * message);
00214 
00227         void remove();
00228 
00259         void setMaxDepth(std::size_t maxDepth);
00260 
00261         // Public ctor but only to be used by internal::DefaultContext.
00262         NDC();
00263 
00264       // Dtor
00265         virtual ~NDC();
00266 
00267     private:
00268       // Methods
00269         LOG4CPLUS_PRIVATE static DiagnosticContextStack* getPtr();
00270 
00271         template <typename StringType>
00272         LOG4CPLUS_PRIVATE
00273         void push_worker (StringType const &);
00274 
00275       // Disallow construction (and copying) except by getNDC()
00276         NDC(const NDC&);
00277         NDC& operator=(const NDC&);
00278     };
00279 
00280 
00284     LOG4CPLUS_EXPORT NDC& getNDC();
00285 
00286 
00290     struct LOG4CPLUS_EXPORT DiagnosticContext
00291     {
00292       // Ctors
00293         DiagnosticContext(const log4cplus::tstring& message,
00294             DiagnosticContext const * parent);
00295         DiagnosticContext(tchar const * message,
00296             DiagnosticContext const * parent);
00297         DiagnosticContext(const log4cplus::tstring& message);
00298         DiagnosticContext(tchar const * message);
00299         DiagnosticContext(DiagnosticContext const &);
00300         DiagnosticContext & operator = (DiagnosticContext const &);
00301 
00302 #if defined (LOG4CPLUS_HAVE_RVALUE_REFS)
00303         DiagnosticContext(DiagnosticContext &&);
00304         DiagnosticContext & operator = (DiagnosticContext &&);
00305 #endif
00306 
00307         void swap (DiagnosticContext &);
00308 
00309       // Data
00310         log4cplus::tstring message; 
00311         log4cplus::tstring fullMessage; 
00312     };
00313 
00314 
00319     class LOG4CPLUS_EXPORT NDCContextCreator {
00320     public:
00322         NDCContextCreator(const log4cplus::tstring& msg);
00323         NDCContextCreator(tchar const * msg);
00324 
00326         ~NDCContextCreator();
00327     };
00328 
00329 } // end namespace log4cplus
00330 
00331 
00332 #endif // _LO4CPLUS_NDC_HEADER_