1 /*=========================================================================
4 Module: $RCSfile: creaMessageManager.cxx,v $
6 Date: $Date: 2008/09/26 14:09:55 $
7 Version: $Revision: 1.1 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 * \brief class MessageManager : Manages the messages displayed by crea (code)
22 #include "creaMessageManager.h"
27 MessageManager::MessageManager()
28 : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9)
33 mMessageLevel[key] = 0;
34 mMessageHelp[key] = "Minimum level for all kind of messages";
35 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
37 mMessageLevel[key] = 9;
38 mMessageHelp[key] = "Maximum level for all kind of messages";
39 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
41 mMessageLevel[key] = 0;
42 mMessageHelp[key] = "Error messages";
43 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
45 mMessageLevel[key] = 0;
46 mMessageHelp[key] = "Warning messages";
47 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
49 mMessageLevel[key] = 0;
50 mMessageHelp[key] = "Debug messages";
51 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
53 mMessageLevel[key] = 1;
54 mMessageHelp[key] = "Information messages";
55 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
58 mMessageLevel[key] = 0;
59 mMessageHelp[key] = "Messages generated by the core classes of the lib";
60 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
62 mMessageLevel[key] = 0;
63 mMessageHelp[key] = "Messages related to box processing";
64 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
66 mMessageLevel[key] = 1;
67 mMessageHelp[key] = "Help messages";
68 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
70 mMessageLevel[key] = 0;
71 mMessageHelp[key] = "Error messages";
72 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
74 mMessageLevel[key] = 1;
75 mMessageHelp[key] = "Warning messages";
76 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
78 mMessageLevel[key] = 1;
79 mMessageHelp[key] = "Output messages";
80 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
82 mMessageLevel[key] = 0;
83 mMessageHelp[key] = "Debug messages";
84 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
86 mMessageLevel[key] = 0;
87 mMessageHelp[key] = "Configuration related messages";
88 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
90 mMessageLevel[key] = 0;
91 mMessageHelp[key] = "Data related messages";
92 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
94 mMessageLevel[key] = 0;
95 mMessageHelp[key] = "Widgets related messages";
96 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
98 mMessageLevel[key] = 0;
99 mMessageHelp[key] = "Graphical user interface related messages";
100 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
102 mMessageLevel[key] = 0;
103 mMessageHelp[key] = "object memory related messages";
104 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
106 mMessageLevel[key] = 0;
107 mMessageHelp[key] = "Packages related messages";
108 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
110 mMessageLevel[key] = 0;
111 mMessageHelp[key] = "Connections related messages";
112 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
114 mMessageLevel[key] = 0;
115 mMessageHelp[key] = "Modified related messages";
116 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
123 MessageManager::~MessageManager()
125 // std::cout << "~MessageManager"<<std::endl;
130 MessageManager* MessageManager::GetInstance()
132 static MessageManager* m = 0;
133 if (!m) m = new MessageManager();
137 void MessageManager::RegisterMessageType(std::string key,
139 unsigned char default_level)
141 GetInstance()->mMessageLevel[key] = default_level;
142 GetInstance()->mMessageHelp[key] = help;
143 if (GetInstance()->mMaxMessageLength<key.length())
144 GetInstance()->mMaxMessageLength = key.length();
149 void MessageManager::SetMessageLevel(std::string key,
152 std::map<std::string,int>::iterator i;
153 i = GetInstance()->mMessageLevel.find(key);
154 if (i!=GetInstance()->mMessageLevel.end())
160 creaWarning("MessageManager::SetMessageLevel : message type=<"
161 <<key<<"> unregistered");
168 int MessageManager::GetMessageLevel(std::string key)
170 int l = GetInstance()->mMessageLevel["all"];
171 std::map<std::string,int>::iterator i =
172 GetInstance()->mMessageLevel.find(key);
173 if (i!=GetInstance()->mMessageLevel.end()) {
174 if ( (*i).second > l ) l = (*i).second;
176 int m = GetInstance()->mMessageLevel["max"];
183 void MessageManager::PrintInfo()
185 creaMessage("info",1,"================ Messages ================="
187 creaMessage("info",1, "Kind");
189 k<(int)(GetInstance()->mMaxMessageLength-2);
192 creaMessageCont("info",1," ");
194 creaMessageCont("info",1,"Level Nature" << creaendl);
195 std::map<std::string,int>::iterator i;
196 std::map<std::string,std::string>::iterator j;
197 for (i=GetInstance()->mMessageLevel.begin(),
198 j=GetInstance()->mMessageHelp.begin();
199 i!=GetInstance()->mMessageLevel.end();++i,++j) {
200 creaMessage("info",1, (*i).first);
202 k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
204 creaMessageCont("info",1," ");
206 creaMessageCont("info",1, (*i).second << "\t"
207 << (*j).second << creaendl);
209 creaMessage("info",1,"==========================================="