]> Dogcows Code - chaz/yoink/blob - src/stlplus/subsystems/message_handler.cpp
archiving support for releases
[chaz/yoink] / src / stlplus / subsystems / message_handler.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
7
8 ////////////////////////////////////////////////////////////////////////////////
9 #include "message_handler.hpp"
10 #include "dprintf.hpp"
11 #include <fstream>
12 #include <map>
13 #include <list>
14 #include <ctype.h>
15 ////////////////////////////////////////////////////////////////////////////////
16
17 namespace stlplus
18 {
19
20 ////////////////////////////////////////////////////////////////////////////////
21 // Utilities
22
23 static std::ostream& operator<< (std::ostream& device, const std::vector<std::string>& data)
24 {
25 for (unsigned i = 0; i < data.size(); i++)
26 device << data[i] << std::endl;
27 device.flush();
28 return device;
29 }
30
31 ////////////////////////////////////////////////////////////////////////////////
32
33 static const char* information_id = "INFORMATION";
34 static const char* context_id = "CONTEXT";
35 static const char* supplement_id = "SUPPLEMENT";
36 static const char* warning_id = "WARNING";
37 static const char* error_id = "ERROR";
38 static const char* fatal_id = "FATAL";
39 static const char* position_id = "POSITION";
40
41 static const char* default_information_format = "@0";
42 static const char* default_context_format = "context: @0";
43 static const char* default_supplement_format = "supplement: @0";
44 static const char* default_warning_format = "warning: @0";
45 static const char* default_error_format = "error: @0";
46 static const char* default_fatal_format = "FATAL: @0";
47 static const char* default_position_format = "\"@1\" (@2,@3) : @0";
48
49 ////////////////////////////////////////////////////////////////////////////////
50 // position class
51
52 message_position::message_position(void) :
53 m_filename(std::string()), m_line(0), m_column(0)
54 {
55 }
56
57 message_position::message_position(const std::string& filename, unsigned line, unsigned column) :
58 m_filename(filename), m_line(line), m_column(column)
59 {
60 }
61
62 message_position::~message_position(void)
63 {
64 }
65
66 const std::string& message_position::filename(void) const
67 {
68 return m_filename;
69 }
70
71 unsigned message_position::line(void) const
72 {
73 return m_line;
74 }
75
76 unsigned message_position::column(void) const
77 {
78 return m_column;
79 }
80
81 message_position message_position::operator + (unsigned offset) const
82 {
83 message_position result(*this);
84 result += offset;
85 return result;
86 }
87
88 message_position& message_position::operator += (unsigned offset)
89 {
90 m_column += offset;
91 return *this;
92 }
93
94 bool message_position::empty(void) const
95 {
96 return m_filename.empty();
97 }
98
99 bool message_position::valid(void) const
100 {
101 return !empty();
102 }
103
104 std::vector<std::string> message_position::show(void) const
105 {
106 std::vector<std::string> result;
107 if (valid())
108 {
109 // skip row-1 lines of the file and print out the resultant line
110 std::ifstream source(filename().c_str());
111 std::string current_line;
112 for (unsigned i = 0; i < line(); i++)
113 {
114 if (!source.good())
115 return result;
116 std::getline(source,current_line);
117 }
118 result.push_back(current_line);
119 // now put an up-arrow at the appropriate column
120 // preserve any tabs in the original line
121 result.push_back(std::string());
122 for (unsigned j = 0; j < column(); j++)
123 {
124 if (j < current_line.size() && current_line[j] == '\t')
125 result.back() += '\t';
126 else
127 result.back() += ' ';
128 }
129 result.back() += '^';
130 }
131 return result;
132 }
133
134 std::string to_string(const message_position& where)
135 {
136 return dformat("{%s:%u:%u}", where.filename().c_str(), where.line(), where.column());
137 }
138
139 ////////////////////////////////////////////////////////////////////////////////
140 // context subclass
141
142 class message_context_body
143 {
144 private:
145 unsigned m_depth;
146 message_handler_base* m_base;
147
148 public:
149 message_context_body(message_handler_base& handler) :
150 m_depth(0), m_base(0)
151 {
152 set(handler);
153 }
154
155 ~message_context_body(void)
156 {
157 pop();
158 }
159
160 void set(message_handler_base& handler)
161 {
162 m_base = &handler;
163 m_depth = m_base->context_depth();
164 }
165
166 void pop(void)
167 {
168 if (m_base)
169 m_base->pop_context(m_depth);
170 }
171 private:
172 message_context_body(const message_context_body&);
173 message_context_body& operator=(const message_context_body&);
174 };
175
176 // exported context class
177
178 message_context::message_context(message_handler_base& handler) : m_body(new message_context_body(handler))
179 {
180 }
181
182 void message_context::set(message_handler_base& handler)
183 {
184 m_body->set(handler);
185 }
186
187 void message_context::pop(void)
188 {
189 m_body->pop();
190 }
191
192 ////////////////////////////////////////////////////////////////////////////////
193 // exceptions
194
195 // read_error
196
197 message_handler_read_error::message_handler_read_error(const message_position& position, const std::string& reason) :
198 std::runtime_error(to_string(position) + std::string(": Message handler read error - ") + reason),
199 m_position(position)
200 {
201 }
202
203 message_handler_read_error::~message_handler_read_error(void) throw()
204 {
205 }
206
207 const message_position& message_handler_read_error::where(void) const
208 {
209 return m_position;
210 }
211
212 // format error
213
214 message_handler_format_error::message_handler_format_error(const std::string& format, unsigned offset) :
215 std::runtime_error(std::string("Message handler formatting error in \"") + format + std::string("\"")),
216 m_position("",0,0), m_format(format), m_offset(offset)
217 {
218 }
219
220 message_handler_format_error::message_handler_format_error(const message_position& pos, const std::string& format, unsigned offset) :
221 std::runtime_error(to_string(pos) + std::string(": Message handler formatting error in \"") + format + std::string("\"")),
222 m_position(pos), m_format(format), m_offset(offset)
223 {
224 }
225
226 message_handler_format_error::~message_handler_format_error(void) throw()
227 {
228 }
229
230 const message_position& message_handler_format_error::where(void) const
231 {
232 return m_position;
233 }
234
235 const std::string& message_handler_format_error::format(void) const
236 {
237 return m_format;
238 }
239
240 unsigned message_handler_format_error::offset(void) const
241 {
242 return m_offset;
243 }
244
245 // id_error
246
247 message_handler_id_error::message_handler_id_error(const std::string& id) :
248 std::runtime_error(std::string("Message handler message ID not found: ") + id), m_id(id)
249 {
250 }
251
252 message_handler_id_error::~message_handler_id_error(void) throw()
253 {
254 }
255
256 const std::string& message_handler_id_error::id(void) const
257 {
258 return m_id;
259 }
260
261 // limit_error
262
263 message_handler_limit_error::message_handler_limit_error(unsigned limit) :
264 std::runtime_error(std::string("Message handler limit error: ") + dformat("%u",limit) + std::string(" reached")),
265 m_limit(limit)
266 {
267 }
268
269 message_handler_limit_error::~message_handler_limit_error(void) throw()
270 {
271 }
272
273 unsigned message_handler_limit_error::limit(void) const
274 {
275 return m_limit;
276 }
277
278 // fatal_error
279
280 message_handler_fatal_error::message_handler_fatal_error(const std::string& id) :
281 std::runtime_error(std::string("Message Handler Fatal error: ") + id),
282 m_id(id)
283 {
284 }
285
286 message_handler_fatal_error::~message_handler_fatal_error(void) throw()
287 {
288 }
289
290 const std::string& message_handler_fatal_error::id(void) const
291 {
292 return m_id;
293 }
294
295 ////////////////////////////////////////////////////////////////////////////////
296
297 class message
298 {
299 private:
300 unsigned m_index; // index into message files
301 unsigned m_line; // line
302 unsigned m_column; // column
303 std::string m_text; // text
304
305 public:
306 message(unsigned index = (unsigned)-1,
307 unsigned line = 0,
308 unsigned column = 0,
309 const std::string& text = "") :
310 m_index(index),m_line(line),m_column(column),m_text(text)
311 {
312 }
313 message(const std::string& text) :
314 m_index((unsigned)-1),m_line(0),m_column(0),m_text(text)
315 {
316 }
317
318 ~message(void)
319 {
320 }
321
322 unsigned index(void) const
323 {
324 return m_index;
325 }
326
327 unsigned line(void) const
328 {
329 return m_line;
330 }
331
332 unsigned column(void) const
333 {
334 return m_column;
335 }
336
337 const std::string& text(void) const
338 {
339 return m_text;
340 }
341 };
342
343 ////////////////////////////////////////////////////////////////////////////////
344
345 class pending_message
346 {
347 private:
348 message_position m_position;
349 std::string m_id;
350 std::vector<std::string> m_args;
351 public:
352 pending_message(const message_position& position, const std::string& id, const std::vector<std::string>& args) :
353 m_position(position), m_id(id), m_args(args) {}
354 pending_message(const std::string& id, const std::vector<std::string>& args) :
355 m_position(message_position()), m_id(id), m_args(args) {}
356 ~pending_message(void) {}
357
358 const message_position& position(void) const {return m_position;}
359 const std::string& id(void) const {return m_id;}
360 const std::vector<std::string>& args(void) const {return m_args;}
361 };
362
363 ////////////////////////////////////////////////////////////////////////////////
364
365 class message_handler_base_body
366 {
367 public:
368 std::vector<std::string> m_files; // message files in the order they were added
369 std::map<std::string,message> m_messages; // messages stored as id:message pairs
370 bool m_show; // show source
371 std::list<pending_message> m_context; // context message stack
372 std::list<pending_message> m_supplement; // supplementary message stack
373
374 public:
375 message_handler_base_body(void) :
376 m_show(false)
377 {
378 // preload with default formats
379 add_message(information_id,default_information_format);
380 add_message(warning_id,default_warning_format);
381 add_message(error_id,default_error_format);
382 add_message(fatal_id,default_fatal_format);
383 add_message(position_id,default_position_format);
384 add_message(context_id,default_context_format);
385 add_message(supplement_id,default_supplement_format);
386 }
387
388 ~message_handler_base_body(void)
389 {
390 }
391
392 void set_show(bool show)
393 {
394 m_show = show;
395 }
396
397 void add_message_file(const std::string& file)
398 throw(message_handler_read_error)
399 {
400 m_files.push_back(file);
401 std::ifstream input(file.c_str());
402 if (!input.good())
403 throw message_handler_read_error(message_position(file,0,0), std::string("file not found: ") + file);
404 std::string line;
405 unsigned l = 0;
406 while(input.good())
407 {
408 std::getline(input,line);
409 l++;
410 if (line.size() > 0 && isalpha(line[0]))
411 {
412 // Get the id field which starts with an alphabetic and contains alphanumerics and underscore
413 std::string id;
414 unsigned i = 0;
415 for (; i < line.size(); i++)
416 {
417 if (isalnum(line[i]) || line[i] == '_')
418 id += line[i];
419 else
420 break;
421 }
422 // check this ID is unique within the files - however it is legal to override a hard-coded message
423 std::map<std::string,message>::iterator found = m_messages.find(id);
424 if (found != m_messages.end() && found->second.index() != (unsigned)-1)
425 throw message_handler_read_error(message_position(file,l,i), std::string("repeated ID ") + id);
426 // skip whitespace
427 for (; i < line.size(); i++)
428 {
429 if (!isspace(line[i]))
430 break;
431 }
432 // now get the text part and add the message to the message map
433 std::string text = line.substr(i, line.size()-i);
434 m_messages[id] = message(m_files.size()-1, l, i, text);
435 }
436 }
437 }
438
439 void add_message(const std::string& id, const std::string& text)
440 throw()
441 {
442 m_messages[id] = message((unsigned)-1, 0, 0, text);
443 }
444
445 bool message_present(const std::string& id) const
446 throw()
447 {
448 return m_messages.find(id) != m_messages.end();
449 }
450
451 void push_supplement(const message_position& position,
452 const std::string& message_id,
453 const std::vector<std::string>& args)
454 {
455 m_supplement.push_back(pending_message(position,message_id,args));
456 }
457
458 void push_context(const message_position& position,
459 const std::string& message_id,
460 const std::vector<std::string>& args)
461 {
462 m_context.push_back(pending_message(position,message_id,args));
463 }
464
465 void pop_context(unsigned depth)
466 {
467 while (depth < m_context.size())
468 m_context.pop_back();
469 }
470
471 unsigned context_depth(void) const
472 {
473 return m_context.size();
474 }
475
476 std::vector<std::string> format_report(const message_position& position,
477 const std::string& message_id,
478 const std::string& status_id,
479 const std::vector<std::string>& args)
480 throw(message_handler_id_error,message_handler_format_error)
481 {
482 // gathers everything together into a full multi-line report
483 std::vector<std::string> result;
484 // the first part of the report is the status message (info/warning/error/fatal)
485 result.push_back(format_id(position, message_id, status_id, args));
486 // now append any supplemental messages that have been stacked
487 // these are printed in FIFO order i.e. the order that they were added to the handler
488 for (std::list<pending_message>::iterator j = m_supplement.begin(); j != m_supplement.end(); j++)
489 result.push_back(format_id(j->position(),j->id(),supplement_id,j->args()));
490 // now discard any supplementary messages because they only persist until they are printed once
491 m_supplement.clear();
492 // now append any context messages that have been stacked
493 // these are printed in LIFO order i.e. closest context first
494 for (std::list<pending_message>::reverse_iterator i = m_context.rbegin(); i != m_context.rend(); i++)
495 result.push_back(format_id(i->position(),i->id(),context_id,i->args()));
496 return result;
497 }
498
499 std::string format_id(const message_position& position,
500 const std::string& message_id,
501 const std::string& status_id,
502 const std::vector<std::string>& args)
503 throw(message_handler_id_error,message_handler_format_error)
504 {
505 // This function creates a fully-formatted single-line message from a
506 // combination of the position format and the status format plus the message
507 // ID and its arguments. There are up to three levels of substitution
508 // required to do this.
509
510 // get the status format from the status_id
511 std::map<std::string,message>::iterator status_found = m_messages.find(status_id);
512 if (status_found == m_messages.end()) throw message_handler_id_error(status_id);
513
514 // similarly get the message format
515 std::map<std::string,message>::iterator message_found = m_messages.find(message_id);
516 if (message_found == m_messages.end()) throw message_handler_id_error(message_id);
517
518 // format the message contents
519 std::string message_text = format_message(message_found->second, args);
520
521 // now format the message in the status string (informational, warning etc).
522 std::vector<std::string> status_args;
523 status_args.push_back(message_text);
524 std::string result = format_message(status_found->second, status_args);
525
526 // finally, if the message is positional, format the status message in the positional string
527 if (position.valid())
528 {
529 // get the position format from the message set
530 std::map<std::string,message>::iterator position_found = m_messages.find(position_id);
531 if (position_found == m_messages.end()) throw message_handler_id_error(position_id);
532
533 // now format the message
534 std::vector<std::string> position_args;
535 position_args.push_back(result);
536 position_args.push_back(position.filename());
537 position_args.push_back(dformat("%u",position.line()));
538 position_args.push_back(dformat("%u",position.column()));
539 result = format_message(position_found->second, position_args);
540 // add the source file text and position if that option is on
541
542 if (m_show)
543 {
544 std::vector<std::string> show = position.show();
545 for (unsigned i = 0; i < show.size(); i++)
546 {
547 result += std::string("\n");
548 result += show[i];
549 }
550 }
551 }
552 return result;
553 }
554
555 std::string format_message(const message& mess,
556 const std::vector<std::string>& args)
557 throw(message_handler_format_error)
558 {
559 // this function creates a formatted string from the stored message text and
560 // the arguments. Most of the work is done in format_string. However, if a
561 // formatting error is found, this function uses extra information stored in
562 // the message data structure to improve the reporting of the error
563 try
564 {
565 // This is the basic string formatter which performs parameter substitution
566 // into a message. Parameter placeholders are in the form @0, @1 etc, where
567 // the number is the index of the argument in the args vector. At present,
568 // no field codes are supported as in printf formats Algorithm: scan the
569 // input string and transfer it into the result. When an @nnn appears,
570 // substitute the relevant argument from the args vector. Throw an exception
571 // if its out of range. Also convert C-style escaped characters of the form
572 // \n.
573 std::string format = mess.text();
574 std::string result;
575 for (unsigned i = 0; i < format.size(); )
576 {
577 if (format[i] == '@')
578 {
579 // an argument substitution has been found - now find the argument number
580 if (i+1 == format.size()) throw message_handler_format_error(format, i);
581 i++;
582 // check for @@ which is an escaped form of '@'
583 if (format[i] == '@')
584 {
585 result += '@';
586 i++;
587 }
588 else
589 {
590 // there must be at least one digit in the substitution number
591 if (!isdigit(format[i])) throw message_handler_format_error(format,i);
592 unsigned a = 0;
593 for (; i < format.size() && isdigit(format[i]); i++)
594 {
595 a *= 10;
596 a += (format[i] - '0');
597 }
598 // check for an argument request out of the range of the set of arguments
599 if (a >= args.size()) throw message_handler_format_error(format,i-1);
600 result += args[a];
601 }
602 }
603 else if (format[i] == '\\')
604 {
605 // an escaped character has been found
606 if (i+1 == format.size()) throw message_handler_format_error(format, i);
607 i++;
608 // do the special ones first, then all the others just strip off the \ and leave the following characters
609 switch(format[i])
610 {
611 case '\\':
612 result += '\\';
613 break;
614 case 't':
615 result += '\t';
616 break;
617 case 'n':
618 result += '\n';
619 break;
620 case 'r':
621 result += '\r';
622 break;
623 case 'a':
624 result += '\a';
625 break;
626 default:
627 result += format[i];
628 break;
629 }
630 i++;
631 }
632 else
633 {
634 // plain text found - just append to the result
635 result += format[i++];
636 }
637 }
638 return result;
639 }
640 catch(message_handler_format_error& exception)
641 {
642 // if the message came from a message file, improve the error reporting by adding file positional information
643 // Also adjust the position from the start of the text (stored in the message field) to the column of the error
644 if (mess.index() != (unsigned)-1)
645 throw message_handler_format_error(
646 message_position(m_files[mess.index()], mess.line(), mess.column()+exception.offset()),
647 exception.format(),
648 exception.offset());
649 else
650 throw exception;
651 }
652 }
653
654 private:
655 message_handler_base_body(message_handler_base_body&);
656 message_handler_base_body& operator=(message_handler_base_body&);
657 };
658
659 ////////////////////////////////////////////////////////////////////////////////
660
661 message_handler_base::message_handler_base(bool show)
662 throw() :
663 m_base_body(new message_handler_base_body)
664 {
665 m_base_body->set_show(show);
666 }
667
668 message_handler_base::message_handler_base(const std::string& file, bool show)
669 throw(message_handler_read_error) :
670 m_base_body(new message_handler_base_body)
671 {
672 m_base_body->set_show(show);
673 add_message_file(file);
674 }
675
676 message_handler_base::message_handler_base(const std::vector<std::string>& files, bool show)
677 throw(message_handler_read_error) :
678 m_base_body(new message_handler_base_body)
679 {
680 m_base_body->set_show(show);
681 add_message_files(files);
682 }
683
684 message_handler_base::~message_handler_base(void)
685 throw()
686 {
687 }
688
689 ////////////////////////////////////////////////////////////////////////////////
690
691 void message_handler_base::add_message_file(const std::string& file)
692 throw(message_handler_read_error)
693 {
694 m_base_body->add_message_file(file);
695 }
696
697 void message_handler_base::add_message_files(const std::vector<std::string>& files)
698 throw(message_handler_read_error)
699 {
700 for (unsigned i = 0; i < files.size(); i++)
701 add_message_file(files[i]);
702 }
703
704 void message_handler_base::add_message(const std::string& id, const std::string& text)
705 throw()
706 {
707 m_base_body->add_message(id,text);
708 }
709
710 bool message_handler_base::message_present(const std::string& id) const
711 throw()
712 {
713 return m_base_body->message_present(id);
714 }
715
716 ////////////////////////////////////////////////////////////////////////////////
717
718 void message_handler_base::set_information_format(const std::string& format) throw()
719 {
720 add_message(information_id, format);
721 }
722
723 void message_handler_base::set_warning_format(const std::string& format) throw()
724 {
725 add_message(warning_id, format);
726 }
727
728 void message_handler_base::set_error_format(const std::string& format) throw()
729 {
730 add_message(error_id, format);
731 }
732
733 void message_handler_base::set_fatal_format(const std::string& format) throw()
734 {
735 add_message(fatal_id, format);
736 }
737
738 void message_handler_base::set_position_format(const std::string& format) throw()
739 {
740 add_message(position_id, format);
741 }
742
743 void message_handler_base::set_context_format(const std::string& format) throw()
744 {
745 add_message(context_id, format);
746 }
747
748 void message_handler_base::set_supplement_format(const std::string& format) throw()
749 {
750 add_message(supplement_id, format);
751 }
752
753 ////////////////////////////////////////////////////////////////////////////////
754
755 void message_handler_base::show_position(void)
756 throw()
757 {
758 m_base_body->set_show(true);
759 }
760
761 void message_handler_base::hide_position(void)
762 throw()
763 {
764 m_base_body->set_show(false);
765 }
766
767 ////////////////////////////////////////////////////////////////////////////////
768 // information messages
769
770 std::vector<std::string> message_handler_base::information_message(const std::string& id,
771 const std::vector<std::string>& args)
772 throw(message_handler_id_error,message_handler_format_error)
773 {
774 return information_message(message_position(), id, args);
775 }
776
777 std::vector<std::string> message_handler_base::information_message(const std::string& id)
778 throw(message_handler_id_error,message_handler_format_error)
779 {
780 std::vector<std::string> args;
781 return information_message(id, args);
782 }
783
784 std::vector<std::string> message_handler_base::information_message(const std::string& id,
785 const std::string& arg1)
786 throw(message_handler_id_error,message_handler_format_error)
787 {
788 std::vector<std::string> args;
789 args.push_back(arg1);
790 return information_message(id, args);
791 }
792
793 std::vector<std::string> message_handler_base::information_message(const std::string& id,
794 const std::string& arg1,
795 const std::string& arg2)
796 throw(message_handler_id_error,message_handler_format_error)
797 {
798 std::vector<std::string> args;
799 args.push_back(arg1);
800 args.push_back(arg2);
801 return information_message(id, args);
802 }
803
804 std::vector<std::string> message_handler_base::information_message(const std::string& id,
805 const std::string& arg1,
806 const std::string& arg2,
807 const std::string& arg3)
808 throw(message_handler_id_error,message_handler_format_error)
809 {
810 std::vector<std::string> args;
811 args.push_back(arg1);
812 args.push_back(arg2);
813 args.push_back(arg3);
814 return information_message(id, args);
815 }
816
817 std::vector<std::string> message_handler_base::information_message(const message_position& position,
818 const std::string& id,
819 const std::vector<std::string>& args)
820 throw(message_handler_id_error,message_handler_format_error)
821 {
822 return m_base_body->format_report(position, id, information_id, args);
823 }
824
825 std::vector<std::string> message_handler_base::information_message(const message_position& position,
826 const std::string& id)
827 throw(message_handler_id_error,message_handler_format_error)
828 {
829 std::vector<std::string> args;
830 return information_message(position, id, args);
831 }
832
833 std::vector<std::string> message_handler_base::information_message(const message_position& position,
834 const std::string& id,
835 const std::string& arg1)
836 throw(message_handler_id_error,message_handler_format_error)
837 {
838 std::vector<std::string> args;
839 args.push_back(arg1);
840 return information_message(position, id, args);
841 }
842
843 std::vector<std::string> message_handler_base::information_message(const message_position& position,
844 const std::string& id,
845 const std::string& arg1,
846 const std::string& arg2)
847 throw(message_handler_id_error,message_handler_format_error)
848 {
849 std::vector<std::string> args;
850 args.push_back(arg1);
851 args.push_back(arg2);
852 return information_message(position, id, args);
853 }
854
855 std::vector<std::string> message_handler_base::information_message(const message_position& position,
856 const std::string& id,
857 const std::string& arg1,
858 const std::string& arg2,
859 const std::string& arg3)
860 throw(message_handler_id_error,message_handler_format_error)
861 {
862 std::vector<std::string> args;
863 args.push_back(arg1);
864 args.push_back(arg2);
865 args.push_back(arg3);
866 return information_message(position, id, args);
867 }
868
869 ////////////////////////////////////////////////////////////////////////////////
870 // warning messages
871
872 std::vector<std::string> message_handler_base::warning_message(const std::string& id,
873 const std::vector<std::string>& args)
874 throw(message_handler_id_error,message_handler_format_error)
875 {
876 return warning_message(message_position(), id, args);
877 }
878
879 std::vector<std::string> message_handler_base::warning_message(const std::string& id)
880 throw(message_handler_id_error,message_handler_format_error)
881 {
882 std::vector<std::string> args;
883 return warning_message(id, args);
884 }
885
886 std::vector<std::string> message_handler_base::warning_message(const std::string& id,
887 const std::string& arg1)
888 throw(message_handler_id_error,message_handler_format_error)
889 {
890 std::vector<std::string> args;
891 args.push_back(arg1);
892 return warning_message(id, args);
893 }
894
895 std::vector<std::string> message_handler_base::warning_message(const std::string& id,
896 const std::string& arg1,
897 const std::string& arg2)
898 throw(message_handler_id_error,message_handler_format_error)
899 {
900 std::vector<std::string> args;
901 args.push_back(arg1);
902 args.push_back(arg2);
903 return warning_message(id, args);
904 }
905
906 std::vector<std::string> message_handler_base::warning_message(const std::string& id,
907 const std::string& arg1,
908 const std::string& arg2,
909 const std::string& arg3)
910 throw(message_handler_id_error,message_handler_format_error)
911 {
912 std::vector<std::string> args;
913 args.push_back(arg1);
914 args.push_back(arg2);
915 args.push_back(arg3);
916 return warning_message(id, args);
917 }
918
919 std::vector<std::string> message_handler_base::warning_message(const message_position& position,
920 const std::string& id,
921 const std::vector<std::string>& args)
922 throw(message_handler_id_error,message_handler_format_error)
923 {
924 return m_base_body->format_report(position, id, warning_id, args);
925 }
926
927 std::vector<std::string> message_handler_base::warning_message(const message_position& position,
928 const std::string& id)
929 throw(message_handler_id_error,message_handler_format_error)
930 {
931 std::vector<std::string> args;
932 return warning_message(position, id, args);
933 }
934
935 std::vector<std::string> message_handler_base::warning_message(const message_position& position,
936 const std::string& id,
937 const std::string& arg1)
938 throw(message_handler_id_error,message_handler_format_error)
939 {
940 std::vector<std::string> args;
941 args.push_back(arg1);
942 return warning_message(position, id, args);
943 }
944
945 std::vector<std::string> message_handler_base::warning_message(const message_position& position,
946 const std::string& id,
947 const std::string& arg1,
948 const std::string& arg2)
949 throw(message_handler_id_error,message_handler_format_error)
950 {
951 std::vector<std::string> args;
952 args.push_back(arg1);
953 args.push_back(arg2);
954 return warning_message(position, id, args);
955 }
956
957 std::vector<std::string> message_handler_base::warning_message(const message_position& position,
958 const std::string& id,
959 const std::string& arg1,
960 const std::string& arg2,
961 const std::string& arg3)
962 throw(message_handler_id_error,message_handler_format_error)
963 {
964 std::vector<std::string> args;
965 args.push_back(arg1);
966 args.push_back(arg2);
967 args.push_back(arg3);
968 return warning_message(position, id, args);
969 }
970
971 ////////////////////////////////////////////////////////////////////////////////
972 // error messages
973
974 std::vector<std::string> message_handler_base::error_message(const std::string& id,
975 const std::vector<std::string>& args)
976 throw(message_handler_id_error,message_handler_format_error)
977 {
978 return error_message(message_position(), id, args);
979 }
980
981 std::vector<std::string> message_handler_base::error_message(const std::string& id)
982 throw(message_handler_id_error,message_handler_format_error)
983 {
984 std::vector<std::string> args;
985 return error_message(id, args);
986 }
987
988 std::vector<std::string> message_handler_base::error_message(const std::string& id,
989 const std::string& arg1)
990 throw(message_handler_id_error,message_handler_format_error)
991 {
992 std::vector<std::string> args;
993 args.push_back(arg1);
994 return error_message(id, args);
995 }
996
997 std::vector<std::string> message_handler_base::error_message(const std::string& id,
998 const std::string& arg1,
999 const std::string& arg2)
1000 throw(message_handler_id_error,message_handler_format_error)
1001 {
1002 std::vector<std::string> args;
1003 args.push_back(arg1);
1004 args.push_back(arg2);
1005 return error_message(id, args);
1006 }
1007
1008 std::vector<std::string> message_handler_base::error_message(const std::string& id,
1009 const std::string& arg1,
1010 const std::string& arg2,
1011 const std::string& arg3)
1012 throw(message_handler_id_error,message_handler_format_error)
1013 {
1014 std::vector<std::string> args;
1015 args.push_back(arg1);
1016 args.push_back(arg2);
1017 args.push_back(arg3);
1018 return error_message(id, args);
1019 }
1020
1021 std::vector<std::string> message_handler_base::error_message(const message_position& position,
1022 const std::string& id,
1023 const std::vector<std::string>& args)
1024 throw(message_handler_id_error,message_handler_format_error)
1025 {
1026 return m_base_body->format_report(position, id, error_id, args);
1027 }
1028
1029 std::vector<std::string> message_handler_base::error_message(const message_position& position,
1030 const std::string& id)
1031 throw(message_handler_id_error,message_handler_format_error)
1032 {
1033 std::vector<std::string> args;
1034 return error_message(position, id, args);
1035 }
1036
1037 std::vector<std::string> message_handler_base::error_message(const message_position& position,
1038 const std::string& id,
1039 const std::string& arg1)
1040 throw(message_handler_id_error,message_handler_format_error)
1041 {
1042 std::vector<std::string> args;
1043 args.push_back(arg1);
1044 return error_message(position, id, args);
1045 }
1046
1047 std::vector<std::string> message_handler_base::error_message(const message_position& position,
1048 const std::string& id,
1049 const std::string& arg1,
1050 const std::string& arg2)
1051 throw(message_handler_id_error,message_handler_format_error)
1052 {
1053 std::vector<std::string> args;
1054 args.push_back(arg1);
1055 args.push_back(arg2);
1056 return error_message(position, id, args);
1057 }
1058
1059 std::vector<std::string> message_handler_base::error_message(const message_position& position,
1060 const std::string& id,
1061 const std::string& arg1,
1062 const std::string& arg2,
1063 const std::string& arg3)
1064 throw(message_handler_id_error,message_handler_format_error)
1065 {
1066 std::vector<std::string> args;
1067 args.push_back(arg1);
1068 args.push_back(arg2);
1069 args.push_back(arg3);
1070 return error_message(position, id, args);
1071 }
1072
1073 ////////////////////////////////////////////////////////////////////////////////
1074 // fatal messages
1075
1076 std::vector<std::string> message_handler_base::fatal_message(const std::string& id,
1077 const std::vector<std::string>& args)
1078 throw(message_handler_id_error,message_handler_format_error)
1079 {
1080 return fatal_message(message_position(), id, args);
1081 }
1082
1083 std::vector<std::string> message_handler_base::fatal_message(const std::string& id)
1084 throw(message_handler_id_error,message_handler_format_error)
1085 {
1086 std::vector<std::string> args;
1087 return fatal_message(id, args);
1088 }
1089
1090 std::vector<std::string> message_handler_base::fatal_message(const std::string& id,
1091 const std::string& arg1)
1092 throw(message_handler_id_error,message_handler_format_error)
1093 {
1094 std::vector<std::string> args;
1095 args.push_back(arg1);
1096 return fatal_message(id, args);
1097 }
1098
1099 std::vector<std::string> message_handler_base::fatal_message(const std::string& id,
1100 const std::string& arg1,
1101 const std::string& arg2)
1102 throw(message_handler_id_error,message_handler_format_error)
1103 {
1104 std::vector<std::string> args;
1105 args.push_back(arg1);
1106 args.push_back(arg2);
1107 return fatal_message(id, args);
1108 }
1109
1110 std::vector<std::string> message_handler_base::fatal_message(const std::string& id,
1111 const std::string& arg1,
1112 const std::string& arg2,
1113 const std::string& arg3)
1114 throw(message_handler_id_error,message_handler_format_error)
1115 {
1116 std::vector<std::string> args;
1117 args.push_back(arg1);
1118 args.push_back(arg2);
1119 args.push_back(arg3);
1120 return fatal_message(id, args);
1121 }
1122
1123 std::vector<std::string> message_handler_base::fatal_message(const message_position& position,
1124 const std::string& id,
1125 const std::vector<std::string>& args)
1126 throw(message_handler_id_error,message_handler_format_error)
1127 {
1128 return m_base_body->format_report(position, id, fatal_id, args);
1129 }
1130
1131 std::vector<std::string> message_handler_base::fatal_message(const message_position& position,
1132 const std::string& id)
1133 throw(message_handler_id_error,message_handler_format_error)
1134 {
1135 std::vector<std::string> args;
1136 return fatal_message(position, id, args);
1137 }
1138
1139 std::vector<std::string> message_handler_base::fatal_message(const message_position& position,
1140 const std::string& id,
1141 const std::string& arg1)
1142 throw(message_handler_id_error,message_handler_format_error)
1143 {
1144 std::vector<std::string> args;
1145 args.push_back(arg1);
1146 return fatal_message(position, id, args);
1147 }
1148
1149 std::vector<std::string> message_handler_base::fatal_message(const message_position& position,
1150 const std::string& id,
1151 const std::string& arg1,
1152 const std::string& arg2)
1153 throw(message_handler_id_error,message_handler_format_error)
1154 {
1155 std::vector<std::string> args;
1156 args.push_back(arg1);
1157 args.push_back(arg2);
1158 return fatal_message(position, id, args);
1159 }
1160
1161 std::vector<std::string> message_handler_base::fatal_message(const message_position& position,
1162 const std::string& id,
1163 const std::string& arg1,
1164 const std::string& arg2,
1165 const std::string& arg3)
1166 throw(message_handler_id_error,message_handler_format_error)
1167 {
1168 std::vector<std::string> args;
1169 args.push_back(arg1);
1170 args.push_back(arg2);
1171 args.push_back(arg3);
1172 return fatal_message(position, id, args);
1173 }
1174
1175 ////////////////////////////////////////////////////////////////////////////////
1176 // supplemental messages
1177
1178 void message_handler_base::push_supplement(const std::string& id,
1179 const std::vector<std::string>& args)
1180 throw(message_handler_id_error,message_handler_format_error)
1181 {
1182 push_supplement(message_position(), id, args);
1183 }
1184
1185 void message_handler_base::push_supplement(const std::string& id)
1186 throw(message_handler_id_error,message_handler_format_error)
1187 {
1188 std::vector<std::string> args;
1189 push_supplement(id, args);
1190 }
1191
1192 void message_handler_base::push_supplement(const std::string& id,
1193 const std::string& arg1)
1194 throw(message_handler_id_error,message_handler_format_error)
1195 {
1196 std::vector<std::string> args;
1197 args.push_back(arg1);
1198 push_supplement(id, args);
1199 }
1200
1201 void message_handler_base::push_supplement(const std::string& id,
1202 const std::string& arg1,
1203 const std::string& arg2)
1204 throw(message_handler_id_error,message_handler_format_error)
1205 {
1206 std::vector<std::string> args;
1207 args.push_back(arg1);
1208 args.push_back(arg2);
1209 push_supplement(id, args);
1210 }
1211
1212 void message_handler_base::push_supplement(const std::string& id,
1213 const std::string& arg1,
1214 const std::string& arg2,
1215 const std::string& arg3)
1216 throw(message_handler_id_error,message_handler_format_error)
1217 {
1218 std::vector<std::string> args;
1219 args.push_back(arg1);
1220 args.push_back(arg2);
1221 args.push_back(arg3);
1222 push_supplement(id, args);
1223 }
1224
1225 void message_handler_base::push_supplement(const message_position& position,
1226 const std::string& id,
1227 const std::vector<std::string>& args)
1228 throw(message_handler_id_error,message_handler_format_error)
1229 {
1230 m_base_body->push_supplement(position, id, args);
1231 }
1232
1233 void message_handler_base::push_supplement(const message_position& position,
1234 const std::string& id)
1235 throw(message_handler_id_error,message_handler_format_error)
1236 {
1237 std::vector<std::string> args;
1238 push_supplement(position, id, args);
1239 }
1240
1241 void message_handler_base::push_supplement(const message_position& position,
1242 const std::string& id,
1243 const std::string& arg1)
1244 throw(message_handler_id_error,message_handler_format_error)
1245 {
1246 std::vector<std::string> args;
1247 args.push_back(arg1);
1248 push_supplement(position, id, args);
1249 }
1250
1251 void message_handler_base::push_supplement(const message_position& position,
1252 const std::string& id,
1253 const std::string& arg1,
1254 const std::string& arg2)
1255 throw(message_handler_id_error,message_handler_format_error)
1256 {
1257 std::vector<std::string> args;
1258 args.push_back(arg1);
1259 args.push_back(arg2);
1260 push_supplement(position, id, args);
1261 }
1262
1263 void message_handler_base::push_supplement(const message_position& position,
1264 const std::string& id,
1265 const std::string& arg1,
1266 const std::string& arg2,
1267 const std::string& arg3)
1268 throw(message_handler_id_error,message_handler_format_error)
1269 {
1270 std::vector<std::string> args;
1271 args.push_back(arg1);
1272 args.push_back(arg2);
1273 args.push_back(arg3);
1274 push_supplement(position, id, args);
1275 }
1276
1277 ////////////////////////////////////////////////////////////////////////////////
1278 // context
1279
1280 void message_handler_base::push_context (const std::string& id,
1281 const std::vector<std::string>& args)
1282 throw(message_handler_id_error,message_handler_format_error)
1283 {
1284 push_context(message_position(), id, args);
1285 }
1286
1287 void message_handler_base::push_context (const std::string& id)
1288 throw(message_handler_id_error,message_handler_format_error)
1289 {
1290 std::vector<std::string> args;
1291 push_context(id, args);
1292 }
1293
1294 void message_handler_base::push_context (const std::string& id,
1295 const std::string& arg1)
1296 throw(message_handler_id_error,message_handler_format_error)
1297 {
1298 std::vector<std::string> args;
1299 args.push_back(arg1);
1300 push_context(id, args);
1301 }
1302
1303 void message_handler_base::push_context (const std::string& id,
1304 const std::string& arg1,
1305 const std::string& arg2)
1306 throw(message_handler_id_error,message_handler_format_error)
1307 {
1308 std::vector<std::string> args;
1309 args.push_back(arg1);
1310 args.push_back(arg2);
1311 push_context(id, args);
1312 }
1313
1314 void message_handler_base::push_context (const std::string& id,
1315 const std::string& arg1,
1316 const std::string& arg2,
1317 const std::string& arg3)
1318 throw(message_handler_id_error,message_handler_format_error)
1319 {
1320 std::vector<std::string> args;
1321 args.push_back(arg1);
1322 args.push_back(arg2);
1323 args.push_back(arg3);
1324 push_context(id, args);
1325 }
1326
1327 void message_handler_base::push_context (const message_position& position,
1328 const std::string& id,
1329 const std::vector<std::string>& args)
1330 throw(message_handler_id_error,message_handler_format_error)
1331 {
1332 m_base_body->push_context(position, id, args);
1333 }
1334
1335 void message_handler_base::push_context (const message_position& position,
1336 const std::string& id)
1337 throw(message_handler_id_error,message_handler_format_error)
1338 {
1339 std::vector<std::string> args;
1340 push_context(position, id, args);
1341 }
1342
1343 void message_handler_base::push_context (const message_position& position,
1344 const std::string& id,
1345 const std::string& arg1)
1346 throw(message_handler_id_error,message_handler_format_error)
1347 {
1348 std::vector<std::string> args;
1349 args.push_back(arg1);
1350 push_context(position, id, args);
1351 }
1352
1353 void message_handler_base::push_context (const message_position& position,
1354 const std::string& id,
1355 const std::string& arg1,
1356 const std::string& arg2)
1357 throw(message_handler_id_error,message_handler_format_error)
1358 {
1359 std::vector<std::string> args;
1360 args.push_back(arg1);
1361 args.push_back(arg2);
1362 push_context(position, id, args);
1363 }
1364
1365 void message_handler_base::push_context (const message_position& position,
1366 const std::string& id,
1367 const std::string& arg1,
1368 const std::string& arg2,
1369 const std::string& arg3)
1370 throw(message_handler_id_error,message_handler_format_error)
1371 {
1372 std::vector<std::string> args;
1373 args.push_back(arg1);
1374 args.push_back(arg2);
1375 args.push_back(arg3);
1376 push_context(position, id, args);
1377 }
1378
1379 void message_handler_base::pop_context(void) throw()
1380 {
1381 m_base_body->pop_context(m_base_body->context_depth()-1);
1382 }
1383
1384 void message_handler_base::pop_context(unsigned depth) throw()
1385 {
1386 m_base_body->pop_context(depth);
1387 }
1388
1389 unsigned message_handler_base::context_depth(void) const
1390 throw()
1391 {
1392 return m_base_body->context_depth();
1393 }
1394
1395 message_context message_handler_base::auto_push_context(const std::string& id, const std::vector<std::string>& args)
1396 throw(message_handler_id_error,message_handler_format_error)
1397 {
1398 return auto_push_context(message_position(), id, args);
1399 }
1400
1401 message_context message_handler_base::auto_push_context(const std::string& id)
1402 throw(message_handler_id_error,message_handler_format_error)
1403 {
1404 std::vector<std::string> args;
1405 return auto_push_context(id, args);
1406 }
1407
1408 message_context message_handler_base::auto_push_context(const std::string& id,
1409 const std::string& arg1)
1410 throw(message_handler_id_error,message_handler_format_error)
1411 {
1412 std::vector<std::string> args;
1413 args.push_back(arg1);
1414 return auto_push_context(id, args);
1415 }
1416
1417 message_context message_handler_base::auto_push_context (const std::string& id,
1418 const std::string& arg1,
1419 const std::string& arg2)
1420 throw(message_handler_id_error,message_handler_format_error)
1421 {
1422 std::vector<std::string> args;
1423 args.push_back(arg1);
1424 args.push_back(arg2);
1425 return auto_push_context(id, args);
1426 }
1427
1428 message_context message_handler_base::auto_push_context(const std::string& id,
1429 const std::string& arg1,
1430 const std::string& arg2,
1431 const std::string& arg3)
1432 throw(message_handler_id_error,message_handler_format_error)
1433 {
1434 std::vector<std::string> args;
1435 args.push_back(arg1);
1436 args.push_back(arg2);
1437 args.push_back(arg3);
1438 return auto_push_context(id, args);
1439 }
1440
1441 message_context message_handler_base::auto_push_context(const message_position& position,
1442 const std::string& id,
1443 const std::vector<std::string>& args)
1444 throw(message_handler_id_error,message_handler_format_error)
1445 {
1446 message_context result(*this);
1447 m_base_body->push_context(position, id, args);
1448 return result;
1449 }
1450
1451 message_context message_handler_base::auto_push_context(const message_position& position,
1452 const std::string& id)
1453 throw(message_handler_id_error,message_handler_format_error)
1454 {
1455 std::vector<std::string> args;
1456 return auto_push_context(position, id, args);
1457 }
1458
1459 message_context message_handler_base::auto_push_context(const message_position& position,
1460 const std::string& id,
1461 const std::string& arg1)
1462 throw(message_handler_id_error,message_handler_format_error)
1463 {
1464 std::vector<std::string> args;
1465 args.push_back(arg1);
1466 return auto_push_context(position, id, args);
1467 }
1468
1469 message_context message_handler_base::auto_push_context(const message_position& position,
1470 const std::string& id,
1471 const std::string& arg1,
1472 const std::string& arg2)
1473 throw(message_handler_id_error,message_handler_format_error)
1474 {
1475 std::vector<std::string> args;
1476 args.push_back(arg1);
1477 args.push_back(arg2);
1478 return auto_push_context(position, id, args);
1479 }
1480
1481 message_context message_handler_base::auto_push_context(const message_position& position,
1482 const std::string& id,
1483 const std::string& arg1,
1484 const std::string& arg2,
1485 const std::string& arg3)
1486 throw(message_handler_id_error,message_handler_format_error)
1487 {
1488 std::vector<std::string> args;
1489 args.push_back(arg1);
1490 args.push_back(arg2);
1491 args.push_back(arg3);
1492 return auto_push_context(position, id, args);
1493 }
1494
1495 ////////////////////////////////////////////////////////////////////////////////
1496 // iostream-based derivative uses the above base class to generate messages then uses iostream to print them
1497 ////////////////////////////////////////////////////////////////////////////////
1498
1499 class message_handler_body
1500 {
1501 private:
1502 std::ostream* m_device; // TextIO output device
1503 unsigned m_limit; // error limit
1504 unsigned m_errors; // error count
1505
1506 public:
1507 message_handler_body(std::ostream& device, unsigned limit) :
1508 m_device(&device), m_limit(limit), m_errors(0)
1509 {
1510 }
1511
1512 ~message_handler_body(void)
1513 {
1514 device().flush();
1515 }
1516
1517 std::ostream& device(void)
1518 {
1519 return *m_device;
1520 }
1521
1522 unsigned limit(void) const
1523 {
1524 return m_limit;
1525 }
1526
1527 void set_limit(unsigned limit)
1528 {
1529 m_limit = limit;
1530 }
1531
1532 unsigned count(void) const
1533 {
1534 return m_errors;
1535 }
1536
1537 void set_count(unsigned count)
1538 {
1539 m_errors = count;
1540 }
1541
1542 void error_increment(void)
1543 {
1544 ++m_errors;
1545 }
1546
1547 bool limit_reached(void) const
1548 {
1549 return m_limit > 0 && m_errors >= m_limit;
1550 }
1551
1552 private:
1553 message_handler_body(const message_handler_body&);
1554 message_handler_body& operator=(const message_handler_body&);
1555 };
1556
1557 ////////////////////////////////////////////////////////////////////////////////
1558
1559 message_handler::message_handler(std::ostream& device, unsigned limit, bool show)
1560 throw() :
1561 message_handler_base(show), m_body(new message_handler_body(device, limit))
1562 {
1563 }
1564
1565 message_handler::message_handler(std::ostream& device,
1566 const std::string& message_file, unsigned limit, bool show)
1567 throw(message_handler_read_error) :
1568 message_handler_base(message_file,show), m_body(new message_handler_body(device, limit))
1569 {
1570 }
1571
1572 message_handler::message_handler(std::ostream& device, const std::vector<std::string>& message_files, unsigned limit, bool show)
1573 throw(message_handler_read_error) :
1574 message_handler_base(message_files,show), m_body(new message_handler_body(device, limit))
1575 {
1576 }
1577
1578 message_handler::~message_handler(void)
1579 throw()
1580 {
1581 }
1582
1583 ////////////////////////////////////////////////////////////////////////////////
1584 // error count
1585
1586 void message_handler::set_error_limit(unsigned error_limit)
1587 throw()
1588 {
1589 m_body->set_limit(error_limit);
1590 }
1591
1592 unsigned message_handler::error_limit(void) const
1593 throw()
1594 {
1595 return m_body->limit();
1596 }
1597
1598 void message_handler::reset_error_count(void)
1599 throw()
1600 {
1601 m_body->set_count(0);
1602 }
1603
1604 unsigned message_handler::error_count(void) const
1605 throw()
1606 {
1607 return m_body->count();
1608 }
1609
1610 std::ostream& message_handler::device(void)
1611 {
1612 return m_body->device();
1613 }
1614
1615 ////////////////////////////////////////////////////////////////////////////////
1616 // information messages
1617
1618 bool message_handler::information(const std::string& id,
1619 const std::vector<std::string>& args)
1620 throw(message_handler_id_error,message_handler_format_error)
1621 {
1622 device() << information_message(id, args);
1623 return true;
1624 }
1625
1626 bool message_handler::information(const std::string& id)
1627 throw(message_handler_id_error,message_handler_format_error)
1628 {
1629 device() << information_message(id);
1630 return true;
1631 }
1632
1633 bool message_handler::information(const std::string& id,
1634 const std::string& arg1)
1635 throw(message_handler_id_error,message_handler_format_error)
1636 {
1637 device() << information_message(id, arg1);
1638 return true;
1639 }
1640
1641 bool message_handler::information(const std::string& id,
1642 const std::string& arg1,
1643 const std::string& arg2)
1644 throw(message_handler_id_error,message_handler_format_error)
1645 {
1646 device() << information_message(id, arg1, arg2);
1647 return true;
1648 }
1649
1650 bool message_handler::information(const std::string& id,
1651 const std::string& arg1,
1652 const std::string& arg2,
1653 const std::string& arg3)
1654 throw(message_handler_id_error,message_handler_format_error)
1655 {
1656 device() << information_message(id, arg1, arg2, arg3);
1657 return true;
1658 }
1659
1660 bool message_handler::information(const message_position& position,
1661 const std::string& id,
1662 const std::vector<std::string>& args)
1663 throw(message_handler_id_error,message_handler_format_error)
1664 {
1665 device() << information_message(position, id, args);
1666 return true;
1667 }
1668
1669 bool message_handler::information(const message_position& position,
1670 const std::string& id)
1671 throw(message_handler_id_error,message_handler_format_error)
1672 {
1673 device() << information_message(position, id);
1674 return true;
1675 }
1676
1677 bool message_handler::information(const message_position& position,
1678 const std::string& id,
1679 const std::string& arg1)
1680 throw(message_handler_id_error,message_handler_format_error)
1681 {
1682 device() << information_message(position, id, arg1);
1683 return true;
1684 }
1685
1686 bool message_handler::information(const message_position& position,
1687 const std::string& id,
1688 const std::string& arg1,
1689 const std::string& arg2)
1690 throw(message_handler_id_error,message_handler_format_error)
1691 {
1692 device() << information_message(position, id, arg1, arg2);
1693 return true;
1694 }
1695
1696 bool message_handler::information(const message_position& position,
1697 const std::string& id,
1698 const std::string& arg1,
1699 const std::string& arg2,
1700 const std::string& arg3)
1701 throw(message_handler_id_error,message_handler_format_error)
1702 {
1703 device() << information_message(position, id, arg1, arg2, arg3);
1704 return true;
1705 }
1706
1707 ////////////////////////////////////////////////////////////////////////////////
1708 // warning messages
1709
1710 bool message_handler::warning(const std::string& id,
1711 const std::vector<std::string>& args)
1712 throw(message_handler_id_error,message_handler_format_error)
1713 {
1714 device() << warning_message(id, args);
1715 return true;
1716 }
1717
1718 bool message_handler::warning(const std::string& id)
1719 throw(message_handler_id_error,message_handler_format_error)
1720 {
1721 device() << warning_message(id);
1722 return true;
1723 }
1724
1725 bool message_handler::warning(const std::string& id,
1726 const std::string& arg1)
1727 throw(message_handler_id_error,message_handler_format_error)
1728 {
1729 device() << warning_message(id, arg1);
1730 return true;
1731 }
1732
1733 bool message_handler::warning(const std::string& id,
1734 const std::string& arg1,
1735 const std::string& arg2)
1736 throw(message_handler_id_error,message_handler_format_error)
1737 {
1738 device() << warning_message(id, arg1, arg2);
1739 return true;
1740 }
1741
1742 bool message_handler::warning(const std::string& id,
1743 const std::string& arg1,
1744 const std::string& arg2,
1745 const std::string& arg3)
1746 throw(message_handler_id_error,message_handler_format_error)
1747 {
1748 device() << warning_message(id, arg1, arg2, arg3);
1749 return true;
1750 }
1751
1752 bool message_handler::warning(const message_position& position,
1753 const std::string& id,
1754 const std::vector<std::string>& args)
1755 throw(message_handler_id_error,message_handler_format_error)
1756 {
1757 device() << warning_message(position, id, args);
1758 return true;
1759 }
1760
1761 bool message_handler::warning(const message_position& position,
1762 const std::string& id)
1763 throw(message_handler_id_error,message_handler_format_error)
1764 {
1765 device() << warning_message(position, id);
1766 return true;
1767 }
1768
1769 bool message_handler::warning(const message_position& position,
1770 const std::string& id,
1771 const std::string& arg1)
1772 throw(message_handler_id_error,message_handler_format_error)
1773 {
1774 device() << warning_message(position, id, arg1);
1775 return true;
1776 }
1777
1778 bool message_handler::warning(const message_position& position,
1779 const std::string& id,
1780 const std::string& arg1,
1781 const std::string& arg2)
1782 throw(message_handler_id_error,message_handler_format_error)
1783 {
1784 device() << warning_message(position, id, arg1, arg2);
1785 return true;
1786 }
1787
1788 bool message_handler::warning(const message_position& position,
1789 const std::string& id,
1790 const std::string& arg1,
1791 const std::string& arg2,
1792 const std::string& arg3)
1793 throw(message_handler_id_error,message_handler_format_error)
1794 {
1795 device() << warning_message(position, id, arg1, arg2, arg3);
1796 return true;
1797 }
1798
1799 ////////////////////////////////////////////////////////////////////////////////
1800 // error messages
1801
1802 bool message_handler::error(const std::string& id,
1803 const std::vector<std::string>& args)
1804 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1805 {
1806 device() << error_message(id, args);
1807 m_body->error_increment();
1808 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1809 return false;
1810 }
1811
1812 bool message_handler::error(const std::string& id)
1813 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1814 {
1815 device() << error_message(id);
1816 m_body->error_increment();
1817 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1818 return false;
1819 }
1820
1821 bool message_handler::error(const std::string& id,
1822 const std::string& arg1)
1823 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1824 {
1825 device() << error_message(id, arg1);
1826 m_body->error_increment();
1827 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1828 return false;
1829 }
1830
1831 bool message_handler::error(const std::string& id,
1832 const std::string& arg1,
1833 const std::string& arg2)
1834 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1835 {
1836 device() << error_message(id, arg1, arg2);
1837 m_body->error_increment();
1838 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1839 return false;
1840 }
1841
1842 bool message_handler::error(const std::string& id,
1843 const std::string& arg1,
1844 const std::string& arg2,
1845 const std::string& arg3)
1846 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1847 {
1848 device() << error_message(id, arg1, arg2, arg3);
1849 m_body->error_increment();
1850 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1851 return false;
1852 }
1853
1854 bool message_handler::error(const message_position& position,
1855 const std::string& id,
1856 const std::vector<std::string>& args)
1857 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1858 {
1859 device() << error_message(position, id, args);
1860 m_body->error_increment();
1861 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1862 return false;
1863 }
1864
1865 bool message_handler::error(const message_position& position,
1866 const std::string& id)
1867 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1868 {
1869 device() << error_message(position, id);
1870 m_body->error_increment();
1871 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1872 return false;
1873 }
1874
1875 bool message_handler::error(const message_position& position,
1876 const std::string& id,
1877 const std::string& arg1)
1878 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1879 {
1880 device() << error_message(position, id, arg1);
1881 m_body->error_increment();
1882 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1883 return false;
1884 }
1885
1886 bool message_handler::error(const message_position& position,
1887 const std::string& id,
1888 const std::string& arg1,
1889 const std::string& arg2)
1890 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1891 {
1892 device() << error_message(position, id, arg1, arg2);
1893 m_body->error_increment();
1894 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1895 return false;
1896 }
1897
1898 bool message_handler::error(const message_position& position,
1899 const std::string& id,
1900 const std::string& arg1,
1901 const std::string& arg2,
1902 const std::string& arg3)
1903 throw(message_handler_id_error,message_handler_format_error,message_handler_limit_error)
1904 {
1905 device() << error_message(position, id, arg1, arg2, arg3);
1906 m_body->error_increment();
1907 if (m_body->limit_reached()) throw message_handler_limit_error(m_body->limit());
1908 return false;
1909 }
1910
1911 ////////////////////////////////////////////////////////////////////////////////
1912 // fatal messages
1913
1914 bool message_handler::fatal(const std::string& id,
1915 const std::vector<std::string>& args)
1916 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1917 {
1918 device() << fatal_message(id, args);
1919 throw message_handler_fatal_error(id);
1920 }
1921
1922 bool message_handler::fatal(const std::string& id)
1923 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1924 {
1925 device() << fatal_message(id);
1926 throw message_handler_fatal_error(id);
1927 }
1928
1929 bool message_handler::fatal(const std::string& id,
1930 const std::string& arg1)
1931 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1932 {
1933 device() << fatal_message(id, arg1);
1934 throw message_handler_fatal_error(id);
1935 }
1936
1937 bool message_handler::fatal(const std::string& id,
1938 const std::string& arg1,
1939 const std::string& arg2)
1940 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1941 {
1942 device() << fatal_message(id, arg1, arg2);
1943 throw message_handler_fatal_error(id);
1944 }
1945
1946 bool message_handler::fatal(const std::string& id,
1947 const std::string& arg1,
1948 const std::string& arg2,
1949 const std::string& arg3)
1950 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1951 {
1952 device() << fatal_message(id, arg1, arg2, arg3);
1953 throw message_handler_fatal_error(id);
1954 }
1955
1956 bool message_handler::fatal(const message_position& position,
1957 const std::string& id,
1958 const std::vector<std::string>& args)
1959 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1960 {
1961 device() << fatal_message(position, id, args);
1962 throw message_handler_fatal_error(id);
1963 }
1964
1965 bool message_handler::fatal(const message_position& position,
1966 const std::string& id)
1967 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1968 {
1969 device() << fatal_message(position, id);
1970 throw message_handler_fatal_error(id);
1971 }
1972
1973 bool message_handler::fatal(const message_position& position,
1974 const std::string& id,
1975 const std::string& arg1)
1976 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1977 {
1978 device() << fatal_message(position, id, arg1);
1979 throw message_handler_fatal_error(id);
1980 }
1981
1982 bool message_handler::fatal(const message_position& position,
1983 const std::string& id,
1984 const std::string& arg1,
1985 const std::string& arg2)
1986 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1987 {
1988 device() << fatal_message(position, id, arg1, arg2);
1989 throw message_handler_fatal_error(id);
1990 }
1991
1992 bool message_handler::fatal(const message_position& position,
1993 const std::string& id,
1994 const std::string& arg1,
1995 const std::string& arg2,
1996 const std::string& arg3)
1997 throw(message_handler_id_error,message_handler_format_error,message_handler_fatal_error)
1998 {
1999 device() << fatal_message(position, id, arg1, arg2, arg3);
2000 throw message_handler_fatal_error(id);
2001 }
2002
2003 ///////////////////////////////////////////////////////////////////////////////
2004 // plain text
2005
2006 bool message_handler::plaintext(const std::string& text)
2007 {
2008 device() << text << std::endl;
2009 return true;
2010 }
2011
2012 ////////////////////////////////////////////////////////////////////////////////
2013
2014 } // end namespace stlplus
This page took 0.135418 seconds and 4 git commands to generate.