Advanced Strategic Command
stdio-errorhandler.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 
12 #include <iostream>
13 
14 #include "stdio-errorhandler.h"
15 #include "util/messaginghub.h"
16 
17 void StdIoErrorHandler::printStdout( const ASCString& msg )
18 {
19  std::cout << msg << "\n";
20 }
21 void StdIoErrorHandler::printStderr( const ASCString& msg )
22 {
23  std::cerr << msg << "\n";
24 }
25 
26 void StdIoErrorHandler::messageLogger( const ASCString& msg, int level )
27 {
28  // std::cout << "L" << level << ": " << msg << "\n";
29  std::cout << msg << std::flush;
30 }
31 
32 StdIoErrorHandler::StdIoErrorHandler( bool quitOnFatalError )
33 {
34  MessagingHub::Instance().warning.connect( sigc::mem_fun( *this, &StdIoErrorHandler::printStderr ));
35  MessagingHub::Instance().error.connect( sigc::mem_fun( *this, &StdIoErrorHandler::printStderr ));
36  MessagingHub::Instance().fatalError.connect( sigc::mem_fun( *this, &StdIoErrorHandler::printStderr ));
37  MessagingHub::Instance().infoMessage.connect( sigc::mem_fun( *this, &StdIoErrorHandler::printStdout ));
38  MessagingHub::Instance().logMessage.connect( sigc::mem_fun( *this, &StdIoErrorHandler::messageLogger ));
39 
40  if ( quitOnFatalError )
41  MessagingHub::Instance().exitHandler.connect( sigc::bind( &exit , -1 ));
42 
43 }
44 
45 
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
StdIoErrorHandler(bool quitOnFatalError=true)