00001 // Module: Log4CPLUS 00002 // File: ndc.h 00003 // Created: 6/2001 00004 // Author: Tad E. Smith 00005 // 00006 // 00007 // Copyright 2001-2009 Tad E. Smith 00008 // 00009 // Licensed under the Apache License, Version 2.0 (the "License"); 00010 // you may not use this file except in compliance with the License. 00011 // You may obtain a copy of the License at 00012 // 00013 // http://www.apache.org/licenses/LICENSE-2.0 00014 // 00015 // Unless required by applicable law or agreed to in writing, software 00016 // distributed under the License is distributed on an "AS IS" BASIS, 00017 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 // See the License for the specific language governing permissions and 00019 // limitations under the License. 00020 00025 #ifndef _LO4CPLUS_NDC_HEADER_ 00026 #define _LO4CPLUS_NDC_HEADER_ 00027 00028 #include "dcmtk/oflog/config.h" 00029 #include "dcmtk/oflog/tstring.h" 00030 #include "dcmtk/oflog/helpers/lloguser.h" 00031 #include "dcmtk/oflog/helpers/threads.h" 00032 00033 //#include <map> 00034 //#include <stack> 00035 #include "dcmtk/ofstd/ofstack.h" 00036 00037 #if (defined(__MWERKS__) && defined(__MACOS__)) 00038 using STD_NAMESPACE size_t; 00039 #endif 00040 00041 00042 namespace log4cplus { 00043 // Forward declarations 00044 class NDC; 00045 struct DiagnosticContext; 00046 typedef OFStack<DiagnosticContext> DiagnosticContextStack; 00047 00048 #if defined (_MSC_VER) 00049 LOG4CPLUS_EXPORT NDC& getNDC(); 00050 #endif 00051 00052 00117 class LOG4CPLUS_EXPORT NDC : protected log4cplus::helpers::LogLogUser { 00118 public: 00127 void clear(); 00128 00142 DiagnosticContextStack cloneStack(); 00143 00158 void inherit(const DiagnosticContextStack& stack); 00159 00163 log4cplus::tstring get(); 00164 00170 size_t getDepth(); 00171 00183 log4cplus::tstring pop(); 00184 00194 log4cplus::tstring peek(); 00195 00210 void push(const log4cplus::tstring& message); 00211 00221 void remove(); 00222 00253 void setMaxDepth(size_t maxDepth); 00254 00255 // Dtor 00256 ~NDC(); 00257 00258 private: 00259 // Methods 00260 DiagnosticContextStack* getPtr(); 00261 00262 // Data 00263 LOG4CPLUS_THREAD_LOCAL_TYPE threadLocal; 00264 00265 // Disallow construction (and copying) except by getNDC() 00266 NDC(); 00267 NDC(const NDC&); 00268 NDC& operator=(const NDC&); 00269 00270 // Friends 00271 #if defined (_MSC_VER) 00272 friend LOG4CPLUS_EXPORT NDC& getNDC(); 00273 #else 00274 friend NDC& getNDC(); 00275 #endif 00276 }; 00277 00278 00282 LOG4CPLUS_EXPORT NDC& getNDC(); 00283 00284 00288 struct LOG4CPLUS_EXPORT DiagnosticContext { 00289 // Ctors 00290 DiagnosticContext(const log4cplus::tstring& message, DiagnosticContext *parent); 00291 DiagnosticContext(const log4cplus::tstring& message); 00292 00293 // Data 00294 log4cplus::tstring message; 00295 log4cplus::tstring fullMessage; 00296 }; 00297 00298 00303 class LOG4CPLUS_EXPORT NDCContextCreator { 00304 public: 00306 NDCContextCreator(const log4cplus::tstring& msg); 00307 00309 ~NDCContextCreator(); 00310 }; 00311 00312 } // end namespace log4cplus 00313 00314 00315 #endif // _LO4CPLUS_NDC_HEADER_