📄 error.hh
字号:
};/** @class SilentErrorHandler * @brief An ErrorHandler that does not report messages. * * Use SilentErrorHandler when an ErrorHandler object is required, but error * messages should not be printed. */class SilentErrorHandler : public ErrorHandler { public: SilentErrorHandler() { }};/** @class ErrorVeneer * @brief Base class for ErrorHandlers that forward messages. * * ErrorHandlers can stack. Stacking ErrorHandlers simplify modify a message * and then pass the result to a base ErrorHandler, which does the actual * printing. The ErrorVeneer base class simplifies the implementation of * stacking ErrorHandlers. It provides versions of ErrorHandler's format(), * decorate(), emit(), and account() methods that forward to the underlying * handler. */class ErrorVeneer : public ErrorHandler { public: /** @brief Construct an ErrorVeneer. * @param errh base ErrorHandler * * If @a errh is 0, then the ErrorVeneer acts like a * SilentErrorHandler. */ ErrorVeneer(ErrorHandler *errh) : _errh(errh) { } String vformat(const char *fmt, va_list val); String decorate(const String &str); void *emit(const String &str, void *user_data, bool more); void account(int level); private: ErrorHandler *_errh;};#if defined(CLICK_USERLEVEL) || defined(CLICK_TOOL)/** @class FileErrorHandler * @brief An ErrorHandler that prints error messages to a given file. * * FileErrorHandler is the typical base ErrorHandler used at user level. It * prints messages to a file passed in to the constructor, and calls exit() or * abort() based on the error level. */class FileErrorHandler : public ErrorHandler { public: /** @brief Construct a FileErrorHandler. * @param f file to print errors * @param prefix string to prefix every error line */ FileErrorHandler(FILE *f, const String &prefix = String()); void set_default_flags(int default_flags) { _default_flags = default_flags; } String vformat(const char *fmt, va_list val); void *emit(const String &str, void *user_data, bool more); void account(int level); private: FILE *_f; String _context; int _default_flags;};#endif/** @class LocalErrorHandler * @brief A convenience stackable ErrorHandler. * * It's often convenient to pass a null ErrorHandler pointer when errors * should not be printed. The LocalErrorHandler class simplifies dealing with * ErrorHandler pointers that may or may not be null. LocalErrorHandler is a * transparent layer on the base handler; but if the base handler is null, it * acts like a SilentErrorHandler. For example: * @code * void f(ErrorHandler *errh) { // errh might or might not be null * LocalErrorHandler lerrh(errh); * ... lerrh.message("message") ... * } * @endcode */class LocalErrorHandler : public ErrorVeneer { public: /** @brief Construct a LocalErrorHandler. */ LocalErrorHandler(ErrorHandler *errh) : ErrorVeneer(errh) { }};/** @class ContextErrorHandler * @brief A stackable ErrorHandler that prints context lines. * * The stackable ContextErrorHandler adds context to the first error * message printed, and optionally indent error messages so that they appear * grouped underneath the context. * @code * FileErrorHandler errh1(stderr); * ContextErrorHandler errh2(&errh1, "While counting to 2:"); * errh2.error("An error occurred."); * errh2.error("Another error occurred."); * // prints "While counting to 2:\n" * // " An error occurred.\n" * // " Another error occurred.\n" * @endcode * * To prevent ContextErrorHandler from indenting or printing context for a * message, add a "{context:no}" annotation to the message's first line. To * turn off the indent but keep the context, add a "{context:noindent}" * annotation. * @code * FileErrorHandler errh1(stderr); * ContextErrorHandler errh2(&errh1, "While counting to 2:"); * errh2.error("{context:no}An error occurred."); * errh2.error("Another error occurred."); * // prints "An error occurred.\n" * // "While counting to 2:\n" * // " Another error occurred.\n" * * FileErrorHandler errh1(stderr); * PrefixErrorHandler noctx_errh(stderr, "{context:no}"); * ContextErrorHandler errh2(&errh1, "While counting to 2:"); * errh2.error("An error occurred."); * errh2.error("Another error occurred."); * // prints "An error occurred.\n" * // "Another error occurred.\n" * @endcode * * ContextErrorHandler adds the "{context:context}" annotation to context * lines. */class ContextErrorHandler : public ErrorVeneer { public: /** @brief Construct a ContextErrorHandler. * @param errh base ErrorHandler * @param fmt format for context lines * * The context message is formed by @a errh->format() using @a fmt and * any additional arguments. */ ContextErrorHandler(ErrorHandler *errh, const char *fmt, ...); /** @brief Return true iff the context has already been printed. */ bool context_printed() const { return _context_printed; } /** @brief Set whether the context has been printed. */ void set_context_printed(bool x) { _context_printed = x; } /** @brief Set the context string to @a str. */ void set_context(const String &str) { _context = str; } /** @brief Set the indent string to @a str. * * The indent string is prepended to all non-context messages. It can * contain landmarks as well as non-landmark text. The default indent * string is " " (two spaces). */ void set_indent(const String &str) { _indent = str; } /** @brief Set the context landmark to @a str. * * The context landmark is used to decorate the context, and also applied * to any error messages that lack landmarks of their own. The default * context landmark is empty. * * @note The input @a str is passed to * ErrorHandler::make_landmark_anno(). */ void set_context_landmark(const String &str) { _context_landmark = make_landmark_anno(str); } String decorate(const String &str); private: String _context; String _indent; String _context_landmark; bool _context_printed;};/** @class PrefixErrorHandler * @brief A stackable ErrorHandler that adds a prefix to error messages. * * The stackable ContextErrorHandler adds a prefix to every error line * printed. For example: * @code * FileErrorHandler errh1(stderr); * PrefixErrorHandler errh2(&errh1, "Blah--"); * errh2.error("An error occurred."); * errh2.error("Another error occurred."); * // prints "Blah--An error occurred.\n" * // "Blah--Another error occurred.\n" * @endcode */class PrefixErrorHandler : public ErrorVeneer { public: /** @brief Construct a PrefixErrorHandler. * @param errh base ErrorHandler * @param prefix string to prefix to error lines */ PrefixErrorHandler(ErrorHandler *errh, const String &prefix); String decorate(const String &str); private: String _prefix;};/** @class LandmarkErrorHandler * @brief A stackable ErrorHandler that adds a default landmark to error * messages. * * The stackable ContextErrorHandler adds a default landmark to every error * line printed. Error lines' own landmarks are preserved when they exist. * For example: * @code * FileErrorHandler errh1(stderr); * LandmarkErrorHandler errh2(&errh1, "file:1"); * errh2.error("An error occurred."); * errh2.lerror("file:2", "Another error occurred."); * // prints "file:1: An error occurred.\n" * // "file:2: Another error occurred.\n" * @endcode */class LandmarkErrorHandler : public ErrorVeneer { public: /** @brief Construct a LandmarkErrorHandler. * @param errh base ErrorHandler * @param landmark default landmark */ LandmarkErrorHandler(ErrorHandler *errh, const String &landmark); /** @brief Set the default landmark applied to error messages. */ void set_landmark(const String &landmark) { _landmark = make_landmark_anno(landmark); } String decorate(const String &str); private: String _landmark;};#if defined(CLICK_USERLEVEL) || defined(CLICK_TOOL)/** @class BailErrorHandler * @brief A stackable ErrorHandler that exits when errors occur. * * The stackable BailErrorHandler, available only at user level, causes the * Click process to exit if an error worse than a configurable level occurs. */class BailErrorHandler : public ErrorVeneer { public: /** @brief Construct a BailErrorHandler. * @param errh base ErrorHandler * @param level error level that causes premature exit * * An error message with level less than or equal to @a el_error will * cause the process to exit with status 1. */ BailErrorHandler(ErrorHandler *errh, int level = el_error); void account(int level); private: int _level;};#endif#undef ERRH_SENTINELCLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -