[54] | 1 | /*
|
---|
| 2 | * TOPPERS Software
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
|
---|
| 6 | * Copyright (C) 2010 by Meika Sugimoto
|
---|
| 7 | *
|
---|
| 8 | * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 9 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 10 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 11 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 12 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 13 | * スコード中に含まれていること.
|
---|
| 14 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 15 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 16 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 17 | * の無保証規定を掲載すること.
|
---|
| 18 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 19 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 20 | * と.
|
---|
| 21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 24 | * 報告すること.
|
---|
| 25 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 26 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 27 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 28 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 29 | * 免責すること.
|
---|
| 30 | *
|
---|
| 31 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 32 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 33 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 34 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 35 | * の責任を負わない.
|
---|
| 36 | *
|
---|
| 37 | */
|
---|
| 38 | /*!
|
---|
| 39 | * \file toppers/diagnostics.hpp
|
---|
| 40 | * \brief 診断処理に関する宣言定義
|
---|
| 41 | */
|
---|
| 42 | #ifndef TOPPERS_DIAGNOSTICS_HPP_
|
---|
| 43 | #define TOPPERS_DIAGNOSTICS_HPP_
|
---|
| 44 |
|
---|
| 45 | #include <stdexcept>
|
---|
| 46 | #include "toppers/debug.hpp"
|
---|
| 47 | #include "toppers/gettext.hpp"
|
---|
| 48 | #include <boost/format.hpp>
|
---|
| 49 |
|
---|
| 50 | namespace toppers
|
---|
| 51 | {
|
---|
| 52 |
|
---|
| 53 | struct text_line;
|
---|
| 54 |
|
---|
| 55 | class diagnostics_error : public std::runtime_error
|
---|
| 56 | {
|
---|
| 57 | public:
|
---|
| 58 | diagnostics_error( std::string const& msg ) : std::runtime_error( msg ) {}
|
---|
| 59 | };
|
---|
| 60 |
|
---|
| 61 | class normal_exit {};
|
---|
| 62 |
|
---|
| 63 | int get_error_count();
|
---|
| 64 | int increment_error_count();
|
---|
| 65 | void set_program_name( char const* name );
|
---|
| 66 | std::string const& get_program_name();
|
---|
| 67 | int set_error_abort_threshold( int thresh );
|
---|
| 68 | void warning( char const* msg );
|
---|
| 69 | void warning( text_line const& line, char const* msg );
|
---|
| 70 | void error( char const* msg );
|
---|
| 71 | void error( text_line const& line, char const* msg );
|
---|
| 72 | void fatal( char const* msg );
|
---|
| 73 | void fatal( text_line const& line, char const* msg );
|
---|
| 74 | void set_error_location( char const* msg );
|
---|
| 75 |
|
---|
| 76 | template < typename T1 >
|
---|
| 77 | inline void warning( char const* str, T1 const& arg1 )
|
---|
| 78 | {
|
---|
| 79 | warning( ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | template < typename T1, typename T2 >
|
---|
| 83 | inline void warning( char const* str, T1 const& arg1, T2 const& arg2 )
|
---|
| 84 | {
|
---|
| 85 | warning( ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | template < typename T1, typename T2, typename T3 >
|
---|
| 89 | inline void warning( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
| 90 | {
|
---|
| 91 | warning( ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
| 95 | inline void warning( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
| 96 | {
|
---|
| 97 | warning( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | template < typename T1 >
|
---|
| 101 | inline void warning( text_line const& line, char const* str, T1 const& arg1 )
|
---|
| 102 | {
|
---|
| 103 | warning( line, ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | template < typename T1, typename T2 >
|
---|
| 107 | inline void warning( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2 )
|
---|
| 108 | {
|
---|
| 109 | warning( line, ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | template < typename T1, typename T2, typename T3 >
|
---|
| 113 | inline void warning( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
| 114 | {
|
---|
| 115 | warning( line, ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
| 119 | inline void warning( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
| 120 | {
|
---|
| 121 | warning( line, ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | template < typename T1 >
|
---|
| 125 | inline void error( char const* str, T1 const& arg1 )
|
---|
| 126 | {
|
---|
| 127 | error( ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | template < typename T1, typename T2 >
|
---|
| 131 | inline void error( char const* str, T1 const& arg1, T2 const& arg2 )
|
---|
| 132 | {
|
---|
| 133 | error( ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | template < typename T1, typename T2, typename T3 >
|
---|
| 137 | inline void error( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
| 138 | {
|
---|
| 139 | error( ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
| 143 | inline void error( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
| 144 | {
|
---|
| 145 | error( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | template < typename T1, typename T2, typename T3, typename T4, typename T5 >
|
---|
| 149 | inline void error( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 , T5 const& arg5 )
|
---|
| 150 | {
|
---|
| 151 | error( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 % arg5 ).str().c_str() );
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | template < typename T1 >
|
---|
| 155 | inline void error( text_line const& line, char const* str, T1 const& arg1 )
|
---|
| 156 | {
|
---|
| 157 | error( line, ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | template < typename T1, typename T2 >
|
---|
| 161 | inline void error( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2 )
|
---|
| 162 | {
|
---|
| 163 | error( line, ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | template < typename T1, typename T2, typename T3 >
|
---|
| 167 | inline void error( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
| 168 | {
|
---|
| 169 | error( line, ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
| 173 | inline void error( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
| 174 | {
|
---|
| 175 | error( line, ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | template < typename T1 >
|
---|
| 179 | inline void fatal( char const* str, T1 const& arg1 )
|
---|
| 180 | {
|
---|
| 181 | fatal( ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | template < typename T1, typename T2 >
|
---|
| 185 | inline void fatal( char const* str, T1 const& arg1, T2 const& arg2 )
|
---|
| 186 | {
|
---|
| 187 | fatal( ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | template < typename T1, typename T2, typename T3 >
|
---|
| 191 | inline void fatal( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
| 192 | {
|
---|
| 193 | fatal( ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
| 197 | inline void fatal( char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
| 198 | {
|
---|
| 199 | fatal( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | template < typename T1 >
|
---|
| 203 | inline void fatal( text_line const& line, char const* str, T1 const& arg1 )
|
---|
| 204 | {
|
---|
| 205 | fatal( line, ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | template < typename T1, typename T2 >
|
---|
| 209 | inline void fatal( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2 )
|
---|
| 210 | {
|
---|
| 211 | fatal( line, ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | template < typename T1, typename T2, typename T3 >
|
---|
| 215 | inline void fatal( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
| 216 | {
|
---|
| 217 | fatal( line, ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
| 221 | inline void fatal( text_line const& line, char const* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
| 222 | {
|
---|
| 223 | fatal( line, ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | inline void exit()
|
---|
| 227 | {
|
---|
| 228 | throw normal_exit();
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | #undef _
|
---|
| 232 | #define _( str ) ::toppers::gettext( str ).c_str()
|
---|
| 233 |
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | #endif // ! TOPPERS_DIAGNOSTICS_HPP_
|
---|
| 237 |
|
---|