+++ /dev/null
-#ifndef STLPLUS_MESSAGE_HANDLER\r
-#define STLPLUS_MESSAGE_HANDLER\r
-////////////////////////////////////////////////////////////////////////////////\r
-\r
-// Author: Andy Rushton\r
-// Copyright: (c) Southampton University 1999-2004\r
-// (c) Andy Rushton 2004-2009\r
-// License: BSD License, see ../docs/license.html\r
-\r
-// A general-purpose message handler using a message file as the source of all text\r
-\r
-////////////////////////////////////////////////////////////////////////////////\r
-#include "subsystems_fixes.hpp"\r
-#include "smart_ptr.hpp"\r
-#include <iostream>\r
-#include <string>\r
-#include <vector>\r
-#include <stdexcept>\r
-\r
-namespace stlplus\r
-{\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // Internals\r
-\r
- class message_handler_base;\r
- class message_handler_base_body;\r
-\r
- class message_handler;\r
- class message_handler_body;\r
-\r
- class message_context_body;\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // an object representing a file position\r
- // used for example when reporting errors when parsing a text file\r
-\r
- class message_position\r
- {\r
- public:\r
- message_position(void);\r
- message_position(const std::string& filename, unsigned line, unsigned column);\r
- ~message_position(void);\r
-\r
- // access the elements of the position\r
- const std::string& filename(void) const;\r
- // line number in the range 1..n\r
- // so line 0 means uninitialised\r
- unsigned line(void) const;\r
- // column number in the range 0..m-1\r
- unsigned column(void) const;\r
-\r
- // add a column offset to a position\r
- message_position operator + (unsigned) const;\r
- message_position& operator += (unsigned);\r
-\r
- // tests for valid position\r
- bool empty(void) const;\r
- bool valid(void) const;\r
-\r
- // vector of two strings\r
- // - the first reproducing the source line\r
- // - the second an arrow pointing to the correct column\r
- // the vector will be empty if the position can't be found\r
- std::vector<std::string> show(void) const;\r
-\r
- private:\r
- std::string m_filename;\r
- unsigned m_line;\r
- unsigned m_column;\r
- };\r
-\r
- std::string to_string(const message_position& where);\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // an object representing an message context\r
- // used to control the context stack\r
- // on initialisation, the message_context stores the state of the context stack\r
- // on destruction it restores the state by popping any context that has been pushed since creation\r
-\r
- class message_context\r
- {\r
- public:\r
- message_context(message_handler_base& handler);\r
-\r
- void set(message_handler_base& handler);\r
- void pop(void);\r
-\r
- private:\r
- friend class message_context_body;\r
- friend class message_handler_base;\r
- smart_ptr_nocopy<message_context_body> m_body;\r
- };\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // exception classes which can be thrown by the message handler\r
-\r
- // read_error is thrown if the message file read fails\r
- class message_handler_read_error : public std::runtime_error\r
- {\r
- public:\r
- message_handler_read_error(const message_position& position, const std::string& reason);\r
- ~message_handler_read_error(void) throw();\r
-\r
- const message_position& where(void) const;\r
-\r
- private:\r
- message_position m_position;\r
- };\r
-\r
- // format_error is thrown if a formatting error occurs trying to create the text for the message\r
-\r
- class message_handler_format_error : public std::runtime_error\r
- {\r
- public:\r
- message_handler_format_error(const std::string& format, unsigned offset);\r
- message_handler_format_error(const message_position& pos, const std::string& format, unsigned offset);\r
- ~message_handler_format_error(void) throw();\r
-\r
- const message_position& where(void) const;\r
- const std::string& format(void) const;\r
- unsigned offset(void) const;\r
-\r
- private:\r
- message_position m_position;\r
- std::string m_format;\r
- unsigned m_offset;\r
- };\r
-\r
- // id_error is thrown if an error id is requested that could not be found in the message file\r
-\r
- class message_handler_id_error : public std::runtime_error\r
- {\r
- public:\r
- message_handler_id_error(const std::string& id);\r
- ~message_handler_id_error(void) throw();\r
-\r
- const std::string& id(void) const;\r
-\r
- private:\r
- std::string m_id;\r
- };\r
-\r
- // limit_error is thrown when the number of errors reaches the error limit\r
-\r
- class message_handler_limit_error : public std::runtime_error\r
- {\r
- public:\r
- message_handler_limit_error(unsigned limit);\r
- ~message_handler_limit_error(void) throw();\r
-\r
- unsigned limit(void) const;\r
-\r
- private:\r
- unsigned m_limit; // the limit that was exceeded\r
- };\r
-\r
- // fatal_error is thrown when a fatal error is reported\r
-\r
- class message_handler_fatal_error : public std::runtime_error\r
- {\r
- public:\r
- message_handler_fatal_error(const std::string& id);\r
- ~message_handler_fatal_error(void) throw();\r
-\r
- const std::string& id(void) const;\r
-\r
- private:\r
- std::string m_id;\r
- };\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // base version returns message objects as vectors of strings\r
- // - it is then up to the user to decide what to do with them\r
- // - suitable for use in a GUI for example where the message is displayed in a dialog\r
-\r
- class message_handler_base\r
- {\r
- public:\r
- //////////////////////////////////////////////////////////////////////////////\r
- // constructor\r
-\r
- // The first form sets the show flag but doesn't load any message files.\r
- // The second and third forms also read message file(s) by calling\r
- // add_message_file and therefore can throw exceptions. The first form\r
- // defers file reading to explicit calls of add_message_file so does not\r
- // throw any exceptions.\r
-\r
- // show determines whether the source file line containing the source of a problem should also be shown\r
-\r
- message_handler_base(bool show = true)\r
- throw();\r
-\r
- message_handler_base(const std::string& message_file, bool show = true)\r
- throw(message_handler_read_error);\r
-\r
- message_handler_base(const std::vector<std::string>& message_files, bool show = true)\r
- throw(message_handler_read_error);\r
-\r
- virtual ~message_handler_base(void)\r
- throw();\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // message file handling\r
-\r
- // The message file format contains lines of the form:\r
- //\r
- // <id> <spaces> <text>\r
- //\r
- // In <id> is a unique mnemonic for the message. It starts with an\r
- // alphabetic character and may contain alphanumerics and underscores only.\r
- // The <spaces> can be one or more space or tab characters. The <text> is the\r
- // remainder of the line and is plain text (not a quoted string). All lines\r
- // starting with a non-alphabetic character are assumed to be comments and are\r
- // ignored\r
-\r
- // If the message file is missing the function throws read_error with no line\r
- // number. If formatting errors were found in the file,then it throws a\r
- // read_error with valid line information.\r
-\r
- // Any number of message files can be added and they accumulate\r
-\r
- void add_message_file(const std::string& message_file)\r
- throw(message_handler_read_error);\r
-\r
- void add_message_files(const std::vector<std::string>& message_files)\r
- throw(message_handler_read_error);\r
-\r
- void add_message(const std::string& id, const std::string& text)\r
- throw();\r
-\r
- bool message_present(const std::string& id) const\r
- throw();\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // format control\r
-\r
- // The status formats - that is, information/warning/error/fatal/context/supplement\r
- // formats take a single argument which is the formatted message\r
- // For example: "warning: @0"\r
- //\r
- // Messages may be printed as either simple or positional\r
- // simple: just a text message, such as a progress report\r
- // positional: a message relating to a source file line\r
- // The formatted message text is generated directly for simple messages\r
- // However, for positional messages, this text is further substituted\r
- // into a positional format string.\r
- // The positional format string takes up to 4 arguments:\r
- // @0: simple message text\r
- // @1: filename\r
- // @2: line number\r
- // @3: column number\r
- // You can miss out a part of this (e.g. the column number)\r
- // by simply not including the argument number in the format string\r
- // For example: "file: @1, line: @2: @0"\r
- //\r
- // The default formats are:\r
- // information: "@0"\r
- // warning: "warning: @0"\r
- // error: "error: @0"\r
- // fatal: "FATAL: @0"\r
- // context: "context: @0"\r
- // supplement: "supplement: @0"\r
- //\r
- // positional: "\"@1\" (@2,@3) : @0"\r
-\r
- void set_information_format(const std::string& format)\r
- throw();\r
-\r
- void set_warning_format(const std::string& format)\r
- throw();\r
-\r
- void set_error_format(const std::string& format)\r
- throw();\r
-\r
- void set_fatal_format(const std::string& format)\r
- throw();\r
-\r
- void set_context_format(const std::string& format)\r
- throw();\r
-\r
- void set_supplement_format(const std::string& format)\r
- throw();\r
-\r
- void set_position_format(const std::string& format)\r
- throw();\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // source file position display control\r
- // show_position indicates that the source file line containing the error\r
- // should be shown with the message on subsequent lines\r
- // hide_position indicates that the source file line should not be shown\r
-\r
- void show_position(void)\r
- throw();\r
-\r
- void hide_position(void)\r
- throw();\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // Message formatting functions\r
- // These functions return a vector of strings containing the completed message\r
-\r
- // There are 6 classes of message: information, context, supplement, warning, error, fatal\r
- // The 4 main classes are:\r
- // - information: progress messages, status messages etc.\r
- // - warning: a problem has been found but there is a sensible way of proceeding\r
- // - error: a problem has been found and the operation will fail\r
- // processing may continue but only to find further errors\r
- // - fatal: an internal (programming) error has been found and the operation is stopping NOW\r
- // The remaining two always follow one of the above\r
- // - context: give stack-like information of the error context \r
- // e.g. if processing include files, the sequence of includes forms a stack\r
- // - supplement: give extra information of the error context\r
- // e.g. give the set of possible solutions to the problem\r
-\r
- // There are 2 kinds of message: simple, positional\r
- // - simple: just a text message\r
- // - positional: a message relating to a source file and a specific position in that file\r
- // This gives 8 variants. \r
- // Note: a positional message with an empty position is treated as a simple message\r
-\r
- // Messages can have arguments.\r
- // All arguments are strings.\r
- // For each variant there are 5 functions relating to different numbers of arguments.\r
- // - general form: takes any number of arguments as a vector of strings\r
- // - 0 arguments: takes no arguments\r
- // - 1 argument: allows a single argument\r
- // - 2 arguments: allows two arguments\r
- // - 3 arguments: allows three arguments\r
- // For more than 3 arguments, use the general form\r
-\r
- // information messages\r
-\r
- // simple messages\r
- std::vector<std::string> information_message(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- std::vector<std::string> information_message(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> information_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // warning messages\r
-\r
- // simple messages\r
- std::vector<std::string> warning_message(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- std::vector<std::string> warning_message(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> warning_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // error messages\r
-\r
- // simple messages\r
- std::vector<std::string> error_message(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- std::vector<std::string> error_message(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> error_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // fatal messages\r
- // Note that these do not throw the fatal_error exception because that would prevent the message being reported\r
- // the caller should throw the exception after reporting the message\r
-\r
- // simple messages\r
- std::vector<std::string> fatal_message(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- std::vector<std::string> fatal_message(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- std::vector<std::string> fatal_message(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // supplement messages - these must be pushed *before* the message that they apply to\r
-\r
- // simple messages\r
- void push_supplement(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- void push_supplement(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_supplement(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // context stack - allows supplementary messages to be printed after each message showing where it came from\r
- // for example, an message whilst inlining a function could be followed by a "function called from..." message\r
-\r
- // simple context messages\r
- void push_context(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional context messages\r
- void push_context(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- void push_context(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- unsigned context_depth(void) const\r
- throw();\r
-\r
- // remove the last level of context if there is one\r
- void pop_context(void)\r
- throw();\r
- // remove context messages to the specified depth\r
- void pop_context(unsigned)\r
- throw();\r
-\r
- // push the context and save it in the message_context handle. When the\r
- // message_context handle goes out of scope, the context is popped\r
- // automatically\r
-\r
- // simple context messages\r
- message_context auto_push_context(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional context messages\r
- message_context auto_push_context(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- message_context auto_push_context(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- private:\r
- friend class message_handler_base_body;\r
- smart_ptr_nocopy<message_handler_base_body> m_base_body;\r
- };\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
- // iostream-based derivative uses the above base class to generate messages then uses iostream to print them\r
- // Note: since this is a public derivative, all message_handler_base operations are also available\r
-\r
- class message_handler : public message_handler_base\r
- {\r
- public:\r
- //////////////////////////////////////////////////////////////////////////////\r
- // constructor\r
-\r
- // The device is the output on which to print the error. For command-line tools\r
- // it will be either std::cout (standard output) or std::cerr (standard error) from\r
- // <iostream>.\r
-\r
- // The second and third form also reads a message file by calling\r
- // add_message_file and therefore can throw exceptions. The first form\r
- // defers file reading to explicit calls of add_message_file so does not\r
- // throw any exceptions.\r
-\r
- // limit sets the error limit - zero disables this feature\r
- // show determines whether the source file line containing the error should also be shown\r
-\r
- message_handler(std::ostream& device,unsigned limit = 0,bool show = true) \r
- throw();\r
-\r
- message_handler(std::ostream& device,\r
- const std::string& message_file,unsigned limit = 0,bool show = true) \r
- throw(message_handler_read_error);\r
-\r
- message_handler(std::ostream& device,\r
- const std::vector<std::string>& message_files,unsigned limit = 0,bool show = true) \r
- throw(message_handler_read_error);\r
-\r
- ~message_handler(void)\r
- throw();\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // error count and error limits\r
-\r
- void set_error_limit(unsigned error_limit)\r
- throw();\r
-\r
- unsigned error_limit(void) const\r
- throw();\r
-\r
- void reset_error_count(void)\r
- throw();\r
-\r
- unsigned error_count(void) const\r
- throw();\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // access the output device for whatever reason (for example, to ensure that\r
- // text output goes wherever the messages go)\r
-\r
- std::ostream& device(void);\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // Message reporting functions\r
- // These are based on the error formatting functions in the baseclass\r
-\r
- // information messages\r
-\r
- // simple messages\r
- bool information(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- bool information(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool information(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // warning messages\r
-\r
- // simple messages\r
- bool warning(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // positional messages\r
- bool warning(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- bool warning(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error);\r
-\r
- // error messages\r
-\r
- // simple messages\r
- bool error(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- // positional messages\r
- bool error(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- bool error(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error);\r
-\r
- // fatal messages\r
- // These report the error and then always throw the fatal_error exception\r
-\r
- // simple messages\r
- bool fatal(const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- // positional messages\r
- bool fatal(const message_position&,\r
- const std::string& id,\r
- const std::vector<std::string>& args)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const message_position&,\r
- const std::string& id)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- bool fatal(const message_position&,\r
- const std::string& id,\r
- const std::string& arg1,\r
- const std::string& arg2,\r
- const std::string& arg3)\r
- throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error);\r
-\r
- //////////////////////////////////////////////////////////////////////////////\r
- // plain text output\r
- // provides a simple way of outputting text from the program to the same device as the messages\r
- // Each call of plaintext is treated as a line of text and has a newline appended\r
-\r
- bool plaintext (const std::string& text);\r
-\r
- private:\r
- friend class message_handler_body;\r
- smart_ptr_nocopy<message_handler_body> m_body;\r
- };\r
-\r
- ////////////////////////////////////////////////////////////////////////////////\r
-\r
-} // end namespace stlplus\r
-\r
-#endif\r