log4cplus
2.0.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: ndc.h 00004 // Created: 6/2001 00005 // Author: Tad E. Smith 00006 // 00007 // 00008 // Copyright 2001-2015 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 00105 class LOG4CPLUS_EXPORT NDC 00106 { 00107 public: 00116 void clear(); 00117 00131 DiagnosticContextStack cloneStack() const; 00132 00147 void inherit(const DiagnosticContextStack& stack); 00148 00152 log4cplus::tstring const & get() const; 00153 00159 std::size_t getDepth() const; 00160 00177 log4cplus::tstring pop(); 00178 00182 void pop_void (); 00183 00193 log4cplus::tstring const & peek() const; 00194 00206 void push(const log4cplus::tstring& message); 00207 void push(tchar const * message); 00208 00221 void remove(); 00222 00253 void setMaxDepth(std::size_t maxDepth); 00254 00255 // Public ctor but only to be used by internal::DefaultContext. 00256 NDC(); 00257 00258 // Dtor 00259 virtual ~NDC(); 00260 00261 private: 00262 // Methods 00263 LOG4CPLUS_PRIVATE static DiagnosticContextStack* getPtr(); 00264 00265 template <typename StringType> 00266 LOG4CPLUS_PRIVATE 00267 void push_worker (StringType const &); 00268 00269 // Disallow construction (and copying) except by getNDC() 00270 NDC(const NDC&); 00271 NDC& operator=(const NDC&); 00272 }; 00273 00274 00278 LOG4CPLUS_EXPORT NDC& getNDC(); 00279 00280 00284 struct LOG4CPLUS_EXPORT DiagnosticContext 00285 { 00286 // Ctors 00287 DiagnosticContext(const log4cplus::tstring& message, 00288 DiagnosticContext const * parent); 00289 DiagnosticContext(tchar const * message, 00290 DiagnosticContext const * parent); 00291 DiagnosticContext(const log4cplus::tstring& message); 00292 DiagnosticContext(tchar const * message); 00293 DiagnosticContext(DiagnosticContext const &); 00294 DiagnosticContext & operator = (DiagnosticContext const &); 00295 DiagnosticContext(DiagnosticContext &&); 00296 DiagnosticContext & operator = (DiagnosticContext &&); 00297 00298 void swap (DiagnosticContext &); 00299 00300 // Data 00301 log4cplus::tstring message; 00302 log4cplus::tstring fullMessage; 00303 }; 00304 00305 00310 class LOG4CPLUS_EXPORT NDCContextCreator { 00311 public: 00313 explicit NDCContextCreator(const log4cplus::tstring& msg); 00314 explicit NDCContextCreator(tchar const * msg); 00315 00316 NDCContextCreator() = delete; 00317 NDCContextCreator(NDCContextCreator const &) = delete; 00318 NDCContextCreator(NDCContextCreator &&) = delete; 00319 NDCContextCreator & operator= (NDCContextCreator const &) = delete; 00320 NDCContextCreator & operator= (NDCContextCreator &&) = delete; 00321 00323 ~NDCContextCreator(); 00324 }; 00325 00326 } // end namespace log4cplus 00327 00328 00329 #endif // _LO4CPLUS_NDC_HEADER_