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 00206 void push(const log4cplus::tstring& message); 00207 00215 void remove(); 00216 00247 void setMaxDepth(size_t maxDepth); 00248 00249 // Dtor 00250 ~NDC(); 00251 00252 private: 00253 // Methods 00254 DiagnosticContextStack* getPtr(); 00255 00256 // Data 00257 LOG4CPLUS_THREAD_LOCAL_TYPE threadLocal; 00258 00259 // Disallow construction (and copying) except by getNDC() 00260 NDC(); 00261 NDC(const NDC&); 00262 NDC& operator=(const NDC&); 00263 00264 // Friends 00265 #if defined (_MSC_VER) 00266 friend LOG4CPLUS_EXPORT NDC& getNDC(); 00267 #else 00268 friend NDC& getNDC(); 00269 #endif 00270 }; 00271 00272 00276 LOG4CPLUS_EXPORT NDC& getNDC(); 00277 00278 00282 struct LOG4CPLUS_EXPORT DiagnosticContext { 00283 // Ctors 00284 DiagnosticContext(const log4cplus::tstring& message, DiagnosticContext *parent); 00285 DiagnosticContext(const log4cplus::tstring& message); 00286 00287 // Data 00288 log4cplus::tstring message; 00289 log4cplus::tstring fullMessage; 00290 }; 00291 00292 00297 class LOG4CPLUS_EXPORT NDCContextCreator { 00298 public: 00300 NDCContextCreator(const log4cplus::tstring& msg); 00301 00303 ~NDCContextCreator(); 00304 }; 00305 00306 } // end namespace log4cplus 00307 00308 00309 #endif // _LO4CPLUS_NDC_HEADER_