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 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
9 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
10 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
11 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
12 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
13 | * XR[hÉÜÜêĢ鱯D
|
---|
14 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
15 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
16 | gip
|
---|
17 | * Ò}j
|
---|
18 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
19 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
20 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
21 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
22 | * ÆD
|
---|
23 | * (a) Äzzɺ¤hL
|
---|
24 | gipÒ}j
|
---|
25 | AÈÇjÉCãLÌ
|
---|
26 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
27 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
28 | * ñ·é±ÆD
|
---|
29 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
30 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
31 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
32 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
33 | * ÆÓ·é±ÆD
|
---|
34 | *
|
---|
35 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
36 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
37 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
38 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
39 | * ÌÓCðíÈ¢D
|
---|
40 | *
|
---|
41 | */
|
---|
42 | /*!
|
---|
43 | * \file toppers/diagnostics.hpp
|
---|
44 | * \brief ffÉÖ·éé¾è`
|
---|
45 | */
|
---|
46 | #ifndef TOPPERS_DIAGNOSTICS_HPP_
|
---|
47 | #define TOPPERS_DIAGNOSTICS_HPP_
|
---|
48 |
|
---|
49 | #include <stdexcept>
|
---|
50 | #include "toppers/debug.hpp"
|
---|
51 | #include "toppers/gettext.hpp"
|
---|
52 | #include <boost/format.hpp>
|
---|
53 |
|
---|
54 | namespace toppers
|
---|
55 | {
|
---|
56 |
|
---|
57 | struct text_line;
|
---|
58 |
|
---|
59 | class diagnostics_error : public std::runtime_error
|
---|
60 | {
|
---|
61 | public:
|
---|
62 | diagnostics_error( std::string const& msg ) : std::runtime_error( msg ) {}
|
---|
63 | };
|
---|
64 |
|
---|
65 | class normal_exit {};
|
---|
66 |
|
---|
67 | int get_error_count();
|
---|
68 | int increment_error_count();
|
---|
69 | void set_program_name( char const* name );
|
---|
70 | std::string const& get_program_name();
|
---|
71 | int set_error_abort_threshold( int thresh );
|
---|
72 | void warning( const char* msg );
|
---|
73 | void warning( text_line const& line, const char* msg );
|
---|
74 | void error( const char* msg );
|
---|
75 | void error( text_line const& line, const char* msg );
|
---|
76 | void fatal( const char* msg );
|
---|
77 | void fatal( text_line const& line, const char* msg );
|
---|
78 |
|
---|
79 | template < typename T1 >
|
---|
80 | inline void warning( const char* str, T1 const& arg1 )
|
---|
81 | {
|
---|
82 | warning( ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
83 | }
|
---|
84 |
|
---|
85 | template < typename T1, typename T2 >
|
---|
86 | inline void warning( const char* str, T1 const& arg1, T2 const& arg2 )
|
---|
87 | {
|
---|
88 | warning( ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
89 | }
|
---|
90 |
|
---|
91 | template < typename T1, typename T2, typename T3 >
|
---|
92 | inline void warning( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
93 | {
|
---|
94 | warning( ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
95 | }
|
---|
96 |
|
---|
97 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
98 | inline void warning( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
99 | {
|
---|
100 | warning( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
101 | }
|
---|
102 |
|
---|
103 | template < typename T1 >
|
---|
104 | inline void warning( text_line const& line, const char* str, T1 const& arg1 )
|
---|
105 | {
|
---|
106 | warning( line, ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
107 | }
|
---|
108 |
|
---|
109 | template < typename T1, typename T2 >
|
---|
110 | inline void warning( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2 )
|
---|
111 | {
|
---|
112 | warning( line, ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
113 | }
|
---|
114 |
|
---|
115 | template < typename T1, typename T2, typename T3 >
|
---|
116 | inline void warning( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
117 | {
|
---|
118 | warning( line, ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
119 | }
|
---|
120 |
|
---|
121 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
122 | inline void warning( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
123 | {
|
---|
124 | warning( line, ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
125 | }
|
---|
126 |
|
---|
127 | template < typename T1 >
|
---|
128 | inline void error( const char* str, T1 const& arg1 )
|
---|
129 | {
|
---|
130 | error( ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
131 | }
|
---|
132 |
|
---|
133 | template < typename T1, typename T2 >
|
---|
134 | inline void error( const char* str, T1 const& arg1, T2 const& arg2 )
|
---|
135 | {
|
---|
136 | error( ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
137 | }
|
---|
138 |
|
---|
139 | template < typename T1, typename T2, typename T3 >
|
---|
140 | inline void error( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
141 | {
|
---|
142 | error( ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
143 | }
|
---|
144 |
|
---|
145 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
146 | inline void error( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
147 | {
|
---|
148 | error( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
149 | }
|
---|
150 |
|
---|
151 | template < typename T1, typename T2, typename T3, typename T4, typename T5 >
|
---|
152 | inline void error( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 , T5 const& arg5 )
|
---|
153 | {
|
---|
154 | error( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 % arg5 ).str().c_str() );
|
---|
155 | }
|
---|
156 |
|
---|
157 | template < typename T1 >
|
---|
158 | inline void error( text_line const& line, const char* str, T1 const& arg1 )
|
---|
159 | {
|
---|
160 | error( line, ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
161 | }
|
---|
162 |
|
---|
163 | template < typename T1, typename T2 >
|
---|
164 | inline void error( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2 )
|
---|
165 | {
|
---|
166 | error( line, ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
167 | }
|
---|
168 |
|
---|
169 | template < typename T1, typename T2, typename T3 >
|
---|
170 | inline void error( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
171 | {
|
---|
172 | error( line, ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
173 | }
|
---|
174 |
|
---|
175 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
176 | inline void error( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
177 | {
|
---|
178 | error( line, ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
179 | }
|
---|
180 |
|
---|
181 | template < typename T1 >
|
---|
182 | inline void fatal( const char* str, T1 const& arg1 )
|
---|
183 | {
|
---|
184 | fatal( ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
185 | }
|
---|
186 |
|
---|
187 | template < typename T1, typename T2 >
|
---|
188 | inline void fatal( const char* str, T1 const& arg1, T2 const& arg2 )
|
---|
189 | {
|
---|
190 | fatal( ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
191 | }
|
---|
192 |
|
---|
193 | template < typename T1, typename T2, typename T3 >
|
---|
194 | inline void fatal( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
195 | {
|
---|
196 | fatal( ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
197 | }
|
---|
198 |
|
---|
199 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
200 | inline void fatal( const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
201 | {
|
---|
202 | fatal( ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
203 | }
|
---|
204 |
|
---|
205 | template < typename T1 >
|
---|
206 | inline void fatal( text_line const& line, const char* str, T1 const& arg1 )
|
---|
207 | {
|
---|
208 | fatal( line, ( boost::format( str ) % arg1 ).str().c_str() );
|
---|
209 | }
|
---|
210 |
|
---|
211 | template < typename T1, typename T2 >
|
---|
212 | inline void fatal( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2 )
|
---|
213 | {
|
---|
214 | fatal( line, ( boost::format( str ) % arg1 % arg2 ).str().c_str() );
|
---|
215 | }
|
---|
216 |
|
---|
217 | template < typename T1, typename T2, typename T3 >
|
---|
218 | inline void fatal( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
---|
219 | {
|
---|
220 | fatal( line, ( boost::format( str ) % arg1 % arg2 % arg3 ).str().c_str() );
|
---|
221 | }
|
---|
222 |
|
---|
223 | template < typename T1, typename T2, typename T3, typename T4 >
|
---|
224 | inline void fatal( text_line const& line, const char* str, T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
---|
225 | {
|
---|
226 | fatal( line, ( boost::format( str ) % arg1 % arg2 % arg3 % arg4 ).str().c_str() );
|
---|
227 | }
|
---|
228 |
|
---|
229 | inline void exit()
|
---|
230 | {
|
---|
231 | throw normal_exit();
|
---|
232 | }
|
---|
233 |
|
---|
234 | #undef _
|
---|
235 | #define _( str ) ::toppers::gettext( str ).c_str()
|
---|
236 |
|
---|
237 | }
|
---|
238 |
|
---|
239 | #endif // ! TOPPERS_DIAGNOSTICS_HPP_
|
---|
240 |
|
---|