Advanced Strategic Command
messaginghub.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 "messaginghub.h"
13 
14 
16  : userData( NULL )
17 {
18  copy(smw);
19 }
20 
22 {
23  userData = new UserData;
24 }
25 
26 
28 {
29  if ( userData ) {
30  userData->counter -= 1;
31  if ( userData->counter <= 0 ) {
32  delete userData;
33  userData = NULL;
34  }
35  }
36 }
37 
39 {
40  if ( smw.userData ) {
41  unlink();
42  userData = smw.userData;
43  userData->counter += 1;
44  } else {
45  userData = new UserData;
46  }
47 }
48 
50 {
51  unlink();
52 }
53 
55 {
56  if ( userData )
57  userData->SetText( text );
58 }
59 
60 
62 {
63  copy(smw);
64  return *this;
65 }
66 
67 
69 {
70  unlink();
71 }
72 
75 }
76 
77 
78 void MessagingHubBase::message( MessageType type, const ASCString& message )
79 {
80  switch ( type ) {
81  case FatalError: fatalError( message );
82  exitHandler();
83  break;
84  case Error: error ( message ); break;
85  case Warning: warning( message ); break;
86  case InfoMessage: infoMessage( message ); break;
87  case StatusInfo: statusInformation( message ); break;
88  case LogMessage: logMessage( message, 0 ); break;
89  };
90 
91 }
92 
93 void MessagingHubBase::setLoggingCategory( const ASCString& category, bool enable )
94 {
95  if ( enable ) {
96  if ( enabledLogCategories.find( category ) == enabledLogCategories.end())
97  enabledLogCategories.insert( category );
98  } else {
99  if ( enabledLogCategories.find( category ) != enabledLogCategories.end())
100  enabledLogCategories.erase( category );
101  }
102 }
103 
104 
105 void MessagingHubBase::message( MessageType type, const char* msg, ... )
106 {
107  va_list arglist;
108  va_start ( arglist, msg );
109 
110  ASCString my_message;
111  my_message.vaformat( msg, arglist );
112 
113  message( type, my_message );
114 
115  va_end ( arglist );
116 }
117 
118 
119 void displayLogMessage ( int msgVerbosity, const char* message, ... )
120 {
121  va_list arglist;
122  va_start ( arglist, message );
123  if ( msgVerbosity <= MessagingHub::Instance().getVerbosity() ) {
124  char buf[10000];
125  vsprintf ( buf, message, arglist );
126 
127  displayLogMessage( msgVerbosity, ASCString(buf) );
128  }
129  va_end ( arglist );
130 }
131 
132 void displayLogMessage ( int msgVerbosity, const ASCString& message )
133 {
134  if ( msgVerbosity <= MessagingHub::Instance().getVerbosity() )
135  MessagingHub::Instance().logMessage( message, msgVerbosity );
136 
137 }
138 
139 
141 {
142  return enabledLogCategories.find( category ) != enabledLogCategories.end();
143 }
144 
145 void logMessage ( const ASCString& category, const ASCString& message )
146 {
147  if ( MessagingHub::Instance().logCategoryEnabled( category ) )
148  MessagingHub::Instance().logCategorizedMessage( category, message );
149 }
150 
151 void fatalError ( const ASCString& string )
152 {
153  MessagingHub::Instance().message( MessagingHubBase::FatalError, string );
154 }
155 
156 void fatalError ( const char* msg, ... )
157 {
158  va_list arglist;
159  va_start ( arglist, msg );
160 
161  ASCString message;
162  message.vaformat( msg, arglist );
163 
164  fatalError( message );
165 
166  va_end ( arglist );
167 }
168 
169 
170 void warning ( const ASCString& str )
171 {
172  MessagingHub::Instance().message( MessagingHubBase::Warning, str );
173 }
174 
175 void warningMessage ( const ASCString& str )
176 {
177  MessagingHub::Instance().message( MessagingHubBase::Warning, str );
178 }
179 
180 void errorMessage ( const ASCString& string )
181 {
182  MessagingHub::Instance().message( MessagingHubBase::Error, string );
183 }
184 
185 void infoMessage ( const ASCString& string )
186 {
187  MessagingHub::Instance().message( MessagingHubBase::InfoMessage, string );
188 }
189 
190 void statusMessage ( const ASCString& string )
191 {
192  MessagingHub::Instance().message( MessagingHubBase::StatusInfo, string );
193 }
194 
void statusMessage(const ASCString &string)
sigc::signal< void, const ASCString & > warning
displays a warning
Definition: messaginghub.h:87
bool logCategoryEnabled(const ASCString &category)
sigc::signal< void, const ASCString & > fatalError
displays an error message and aborts the game
Definition: messaginghub.h:78
void logMessage(const ASCString &category, const ASCString &message)
sigc::signal< void, const ASCString &, int > logMessage
prints a message to the logging file
Definition: messaginghub.h:96
ASCString & vaformat(const charT *pFormat, va_list ap)
Definition: ascstring.cpp:91
sigc::signal< void, const ASCString & > error
displays an error message and continues game
Definition: messaginghub.h:84
void message(MessageType type, const char *msg,...)
displays any kind of message, as specified by parameter
void warningMessage(const ASCString &str)
A class that hols a MessageWindow. This class ensures that the window is removed if the last copy of ...
Definition: messaginghub.h:34
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void displayLogMessage(int msgVerbosity, const char *message,...)
sigc::signal< void > exitHandler
exits the program
Definition: messaginghub.h:81
void setLoggingCategory(const ASCString &category, bool enable)
void errorMessage(const ASCString &string)
sigc::signal< StatusMessageWindowHolder, const ASCString & > messageWindowFactory
prints a message to the logging file
Definition: messaginghub.h:120
StatusMessageWindowHolder & operator=(const StatusMessageWindowHolder &smw)
virtual ~StatusMessageWindowHolder()
StatusMessageWindowHolder infoMessageWindow(const ASCString &msg)
Displays a status window.
sigc::signal< void, const ASCString & > statusInformation
displays a message in the message line
Definition: messaginghub.h:93
void SetText(const ASCString &text)
virtual void SetText(const ASCString &text)
Definition: messaginghub.h:42
void warning(const ASCString &str)
void fatalError(const ASCString &string)
void copy(const StatusMessageWindowHolder &smw)
void infoMessage(const ASCString &string)
sigc::signal< void, const ASCString & > infoMessage
displays an informational message
Definition: messaginghub.h:90