ML Reference
MeVis/Foundation/Sources/MLUtilities/mlLogging.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00009 //----------------------------------------------------------------------------------
00010 
00011 #ifndef __mlLogging_H
00012 #define __mlLogging_H
00013 
00014 #include "mlUtilsSystem.h"
00015 #include "mlTypeDefs.h"
00016 
00017 #include "mlSystemWarningsDisable.h"
00018 #include <sstream>
00019 #include "mlSystemWarningsRestore.h"
00020 
00021 ML_UTILS_START_NAMESPACE
00022 
00023 //--------------------------------------------------------------------------------------------
00024 //
00036 
00037 //--------------------------------------------------------------------------------------------
00038 
00041 #define mlFatalError(FUNCTION, ERRORCODE) \
00042   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_FATAL, ERRORCODE, FUNCTION).getStream()
00043 
00046 #define mlError(FUNCTION, ERRORCODE) \
00047   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_ERROR, ERRORCODE, FUNCTION).getStream()
00048 
00051 #define mlWarning(FUNCTION, ERRORCODE) \
00052   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_WARNING, ERRORCODE, FUNCTION).getStream()
00053 
00056 #define mlInfo(FUNCTION) \
00057   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_INFORMATION, ML_RESULT_OK, FUNCTION).getStream()
00058 
00059 
00061 #define mlFatalErrorWithDump(FUNCTION, ERRORCODE, OBJECT) \
00062   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_FATAL, ERRORCODE, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
00063 
00065 #define mlErrorWithDump(FUNCTION, ERRORCODE, OBJECT) \
00066   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_ERROR, ERRORCODE, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
00067 
00069 #define mlWarningWithDump(FUNCTION, ERRORCODE, OBJECT) \
00070   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_WARNING, ERRORCODE, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
00071 
00073 #define mlInfoWithDump(FUNCTION, OBJECT) \
00074   ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_INFORMATION, ML_RESULT_OK, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
00075 
00077 
00078 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00079 
00080 class RuntimeType;
00081 
00082 namespace internal {
00083 
00084 template <typename T>
00085 inline const RuntimeType* MLSecureGetRuntimeTypeId(const T* object) {
00086   const RuntimeType* type = NULL;
00087   if (object) {
00088     try { 
00089       type = object->getTypeId();
00090     } catch(...) {};
00091   }
00092   return type;
00093 }
00094 
00095 #ifdef _MSC_VER
00096 #pragma warning( push )
00097 // suppress warning that doesn't seem to be relevant:
00098 #pragma warning(disable : 4251 )  // class 'std::ostringstream' needs to have dll-interface to be used by clients of class 'ml::OpenGL'
00099 #endif
00100 
00102 class ML_UTILS_EXPORT LogCollector
00103 {
00104 public:
00106   LogCollector(const char* file, int line, MLMessageType type, MLErrorCode errorCode,
00107     const char        *functionName,
00108     const void        *dumpObj  = NULL, 
00109     const RuntimeType *dumpObjRT= NULL);
00110 
00112   ~LogCollector();
00113 
00115   std::ostringstream& getStream() { return _stream; }
00116 
00117 private:
00118   std::ostringstream _stream;
00119   const char*        _file;
00120   int                _line;
00121   MLMessageType      _type;
00122   MLErrorCode        _errorCode;
00123   const char*        _functionName;
00124   const void        *_dumpObj; 
00125   const RuntimeType *_dumpObjRT;
00126 };
00127 
00128 #ifdef _MSC_VER
00129 #pragma warning( pop )
00130 #endif
00131 
00132 } // end namespace internal
00133 
00134 #endif // DOXYGEN_SHOULD_SKIP_THIS
00135 
00136 ML_UTILS_END_NAMESPACE
00137 
00138 
00139 #endif // __mlLogging_H
00140