📄 ncbidiag.hpp
字号:
/// Check if a specified flag is set.////// @param flag/// Flag to check/// @param flags/// If eDPF_Default is set for "flags" then use the current global flags on/// its place (merged with other flags from "flags")./// @return/// "TRUE" if the specified "flag" is set in global "flags" that describes/// the post settings./// @sa SetDiagPostFlag(), UnsetDiagPostFlag()inline bool IsSetDiagPostFlag(EDiagPostFlag flag, TDiagPostFlags flags = eDPF_Default);/// Set global post flags to "flags"./// If "flags" have flag eDPF_Default set, it will be replaced by the/// current global post flags./// @return/// Previously set flagsNCBI_XNCBI_EXPORTextern TDiagPostFlags SetDiagPostAllFlags(TDiagPostFlags flags);/// Set the specified flag (globally).NCBI_XNCBI_EXPORTextern void SetDiagPostFlag(EDiagPostFlag flag);/// Unset the specified flag (globally).NCBI_XNCBI_EXPORTextern void UnsetDiagPostFlag(EDiagPostFlag flag);/// Versions of the above for extra trace flags.NCBI_XNCBI_EXPORTextern TDiagPostFlags SetDiagTraceAllFlags(TDiagPostFlags flags);NCBI_XNCBI_EXPORTextern void SetDiagTraceFlag(EDiagPostFlag flag);NCBI_XNCBI_EXPORTextern void UnsetDiagTraceFlag(EDiagPostFlag flag);/// Specify a string to prefix all subsequent error postings with.NCBI_XNCBI_EXPORTextern void SetDiagPostPrefix(const char* prefix);/// Push a string to the list of message prefixes.NCBI_XNCBI_EXPORTextern void PushDiagPostPrefix(const char* prefix);/// Pop a string from the list of message prefixes.NCBI_XNCBI_EXPORTextern void PopDiagPostPrefix(void);/////////////////////////////////////////////////////////////////////////////////// CDiagAutoPrefix --////// Define the auxiliary class to temporarily add a prefix.class NCBI_XNCBI_EXPORT CDiagAutoPrefix{public: /// Constructor. CDiagAutoPrefix(const string& prefix); /// Constructor. CDiagAutoPrefix(const char* prefix); /// Remove the prefix automagically, when the object gets out of scope. ~CDiagAutoPrefix(void);};/// Diagnostic post severity level.////// The value of DIAG_POST_LEVEL can be a digital value (0-9) or /// string value from CDiagBuffer::sm_SeverityName[].#define DIAG_POST_LEVEL "DIAG_POST_LEVEL"/// Set severity of post messages.////// This function has effect only if:/// - Environment variable $DIAG_POST_LEVEL is not set, and/// - Registry value of DIAG_POST_LEVEL, section DEBUG is not set ////// Do not post messages where severity is less than "min_sev"/// @return/// Return previous post-level.NCBI_XNCBI_EXPORTextern EDiagSev SetDiagPostLevel(EDiagSev post_sev = eDiag_Error);/// Disable change the diagnostic post level.////// Consecutive using SetDiagPostLevel() will not have effect.NCBI_XNCBI_EXPORTextern bool DisableDiagPostLevelChange(bool disable_change = true);/// Sets and locks the level, combining the previous two calls.NCBI_XNCBI_EXPORTextern void SetDiagFixedPostLevel(EDiagSev post_sev);/// Set the "die" (abort) level for the program.////// Abort the application if severity is >= "max_sev"./// Throw an exception if die_sev is not in the range/// [eDiagSevMin..eDiag_Fatal]./// @return/// Return previous die-level.NCBI_XNCBI_EXPORTextern EDiagSev SetDiagDieLevel(EDiagSev die_sev = eDiag_Fatal);/// Ignore the die level settings.////// WARNING!!! -- not recommended for use unless you are real desperate:/// By passing TRUE to this function you can make your application/// never exit/abort regardless of the level set by SetDiagDieLevel()./// But be warned this is usually a VERY BAD thing to do!/// -- because any library code counts on at least "eDiag_Fatal" to exit/// unconditionally, and thus what happens after "eDiag_Fatal" is posted is/// in general totally unpredictable! Therefore, use it on your own risk.NCBI_XNCBI_EXPORTextern void IgnoreDiagDieLevel(bool ignore, EDiagSev* prev_sev = 0);/// Abort handler function type.typedef void (*FAbortHandler)(void);/// Set/unset abort handler.////// If "func"==0 use default handler.NCBI_XNCBI_EXPORTextern void SetAbortHandler(FAbortHandler func = 0);/// Smart abort function.////// Processes user abort handler and does not popup assert windows/// if specified (environment variable DIAG_SILENT_ABORT is "Y" or "y").NCBI_XNCBI_EXPORTextern void Abort(void);/// Diagnostic trace setting.#define DIAG_TRACE "DIAG_TRACE"/// Which setting disables/enables posting of "eDiag_Trace" messages.////// By default, trace messages are disabled unless:/// - Environment variable $DIAG_TRACE is set (to any value), or/// - Registry value of DIAG_TRACE, section DEBUG is set (to any value)enum EDiagTrace { eDT_Default = 0, ///< Restores the default tracing context eDT_Disable, ///< Ignore messages of severity "eDiag_Trace" eDT_Enable ///< Enable messages of severity "eDiag_Trace"};/// Set the diagnostic trace settings.NCBI_XNCBI_EXPORTextern void SetDiagTrace(EDiagTrace how, EDiagTrace dflt = eDT_Default);/////////////////////////////////////////////////////////////////////////////////// SDiagMessage --////// Diagnostic message structure.////// Defines structure of the "data" message that is used with message handler/// function("func"), and destructor("cleanup")./// The "func(..., data)" to be called when any instance of "CNcbiDiagBuffer"/// has a new diagnostic message completed and ready to post./// "cleanup(data)" will be called whenever this hook gets replaced and/// on the program termination./// NOTE 1: "func()", "cleanup()" and "g_SetDiagHandler()" calls are/// MT-protected, so that they would never be called simultaneously/// from different threads./// NOTE 2: By default, the errors will be written to standard error stream.struct NCBI_XNCBI_EXPORT SDiagMessage { /// Initalize SDiagMessage fields. SDiagMessage(EDiagSev severity, const char* buf, size_t len, const char* file = 0, size_t line = 0, TDiagPostFlags flags = eDPF_Default, const char* prefix = 0, int err_code = 0, int err_subcode = 0, const char* err_text = 0); mutable EDiagSev m_Severity; ///< Severity level const char* m_Buffer; ///< Not guaranteed to be '\0'-terminated! size_t m_BufferLen; ///< Length of m_Buffer const char* m_File; ///< File name size_t m_Line; ///< Line number in file int m_ErrCode; ///< Error code int m_ErrSubCode; ///< Sub Error code TDiagPostFlags m_Flags; ///< Bitwise OR of "EDiagPostFlag" const char* m_Prefix; ///< Prefix string const char* m_ErrText; ///< Sometimes 'error' has no numeric code, ///< but can be represented as text // Compose a message string in the standard format(see also "flags"): // "<file>", line <line>: <severity>: [<prefix>] <message> [EOL] // and put it to string "str", or write to an output stream "os". /// Which write flags should be output in diagnostic message. enum EDiagWriteFlags { fNone = 0x0, ///< No flags fNoEndl = 0x01 ///< No end of line }; typedef int TDiagWriteFlags; /// Binary OR of "EDiagWriteFlags" /// Write to string. void Write(string& str, TDiagWriteFlags flags = fNone) const; /// Write to stream. CNcbiOstream& Write(CNcbiOstream& os, TDiagWriteFlags flags = fNone) const; CNcbiOstream& x_Write(CNcbiOstream& os, TDiagWriteFlags flags = fNone) const;};/// Insert message in output stream.inline CNcbiOstream& operator<< (CNcbiOstream& os, const SDiagMessage& mess) { return mess.Write(os);}/////////////////////////////////////////////////////////////////////////////////// CDiagHandler --////// Base diagnostic handler class.class NCBI_XNCBI_EXPORT CDiagHandler{public: /// Destructor. virtual ~CDiagHandler(void) {} /// Post message to handler. virtual void Post(const SDiagMessage& mess) = 0;};/// Diagnostic handler function type.typedef void (*FDiagHandler)(const SDiagMessage& mess);/// Diagnostic cleanup function type.typedef void (*FDiagCleanup)(void* data);/// Set the diagnostic handler using the specified diagnostic handler class.NCBI_XNCBI_EXPORTextern void SetDiagHandler(CDiagHandler* handler, bool can_delete = true);/// Get the currently set diagnostic handler class.NCBI_XNCBI_EXPORTextern CDiagHandler* GetDiagHandler(bool take_ownership = false);/// Set the diagnostic handler using the specified diagnostic handler/// and cleanup functions.NCBI_XNCBI_EXPORTextern void SetDiagHandler(FDiagHandler func, void* data, FDiagCleanup cleanup);/// Check if diagnostic handler is set.////// @return /// Return TRUE if user has ever set (or unset) diag. handler.NCBI_XNCBI_EXPORTextern bool IsSetDiagHandler(void);/////////////////////////////////////////////////////////////////////////////////// CStreamDiagHandler --////// Specialization of "CDiagHandler" for the stream-based diagnostics.class NCBI_XNCBI_EXPORT CStreamDiagHandler : public CDiagHandler{public: /// Constructor. /// /// This does *not* own the stream; users will need to clean it up /// themselves if appropriate. /// @param os /// Output stream. /// @param quick_flush /// Do stream flush after every message. CStreamDiagHandler(CNcbiOstream* os, bool quick_flush = true) : m_Stream(os), m_QuickFlush(quick_flush) {} /// Post message to the handler. virtual void Post(const SDiagMessage& mess); NCBI_XNCBI_EXPORT friend bool IsDiagStream(const CNcbiOstream* os);protected: CNcbiOstream* m_Stream; ///< Diagnostic streamprivate: bool m_QuickFlush; ///< Quick flush of stream flag};/// Set diagnostic stream.////// Error diagnostics are written to output stream "os"./// This uses the SetDiagHandler() functionality.NCBI_XNCBI_EXPORTextern void SetDiagStream(CNcbiOstream* os, bool quick_flush = true,///< Do stream flush after every message FDiagCleanup cleanup = 0, ///< Call "cleanup(cleanup_data)" if diag. void* cleanup_data = 0 ///< Stream is changed (see SetDiagHandler) );// Return TRUE if "os" is the current diag. stream.NCBI_XNCBI_EXPORT extern bool IsDiagStream(const CNcbiOstream* os);/////////////////////////////////////////////////////////////////////////////////// CDiagFactory --////// Diagnostic handler factory.class NCBI_XNCBI_EXPORT CDiagFactory{public: /// Factory method interface. virtual CDiagHandler* New(const string& s) = 0;};/////////////////////////////////////////////////////////////////////////////////// CDiagRestorer --////// Auxiliary class to limit the duration of changes to diagnostic settings.class NCBI_XNCBI_EXPORT CDiagRestorer{public: CDiagRestorer (void); ///< Captures current settings ~CDiagRestorer(void); ///< Restores captured settingsprivate: /// Private new operator. /// /// Prohibit dynamic allocation because there's no good reason to allow /// it, and out-of-order destruction is problematic. void* operator new (size_t) { throw runtime_error("forbidden"); } /// Private new[] operator. /// /// Prohibit dynamic allocation because there's no good reason to allow /// it, and out-of-order destruction is problematic. void* operator new[] (size_t) { throw runtime_error("forbidden"); } /// Private delete operator. /// /// Prohibit dynamic deallocation (and allocation) because there's no /// good reason to allow it, and out-of-order destruction is problematic. void operator delete (void*) { throw runtime_error("forbidden"); } /// Private delete[] operator. /// /// Prohibit dynamic deallocation (and allocation) because there's no /// good reason to allow it, and out-of-order destruction is problematic. void operator delete[] (void*) { throw runtime_error("forbidden"); } string m_PostPrefix; ///< Message prefix list<string> m_PrefixList; ///< List of prefixs TDiagPostFlags m_PostFlags; ///< Post flags EDiagSev m_PostSeverity; ///< Post severity EDiagSevChange m_PostSeverityChange; ///< Severity change EDiagSev m_DieSeverity; ///< Die level severity EDiagTrace m_TraceDefault; ///< Default trace setting bool m_TraceEnabled; ///< Trace enabled? CDiagHandler* m_Handler; ///< Class handler bool m_CanDeleteHandler; ///< Can handler be deleted? CDiagErrCodeInfo* m_ErrCodeInfo; ///< Error code information bool m_CanDeleteErrCodeInfo; ///< Can error code info. be deleted?};////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -