1 /*=========================================================================
4 Module: $RCSfile: bbtkMessageManager.cxx,v $
6 Date: $Date: 2008/03/20 09:51:28 $
7 Version: $Revision: 1.4 $
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 bbtk (code)
22 #include "bbtkMessageManager.h"
27 MessageManager::MessageManager()
28 : mMaxMessageLength(8), mAllLevel(0)
33 mMessageLevel[key] = 0;
34 mMessageHelp[key] = "Messages generated by the core classes of the lib";
35 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
37 mMessageLevel[key] = 0;
38 mMessageHelp[key] = "Messages related to box processing";
39 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
41 mMessageLevel[key] = 1;
42 mMessageHelp[key] = "Help messages";
43 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
45 mMessageLevel[key] = 0;
46 mMessageHelp[key] = "Error messages";
47 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
49 mMessageLevel[key] = 1;
50 mMessageHelp[key] = "Warning messages";
51 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
53 mMessageLevel[key] = 1;
54 mMessageHelp[key] = "Output messages";
55 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
57 mMessageLevel[key] = 0;
58 mMessageHelp[key] = "Debug messages";
59 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
61 mMessageLevel[key] = 0;
62 mMessageHelp[key] = "Configuration related messages";
63 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
65 mMessageLevel[key] = 0;
66 mMessageHelp[key] = "Data related messages";
67 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
69 mMessageLevel[key] = 0;
70 mMessageHelp[key] = "Widgets related messages";
71 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
73 mMessageLevel[key] = 0;
74 mMessageHelp[key] = "Graphical user interface related messages";
75 if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
81 MessageManager::~MessageManager()
83 // std::cout << "~MessageManager"<<std::endl;
88 MessageManager* MessageManager::GetInstance()
90 static MessageManager* m = 0;
91 if (!m) m = new MessageManager();
95 void MessageManager::RegisterMessageType(std::string key,
97 unsigned char default_level)
99 GetInstance()->mMessageLevel[key] = default_level;
100 GetInstance()->mMessageHelp[key] = help;
101 if (GetInstance()->mMaxMessageLength<key.length())
102 GetInstance()->mMaxMessageLength = key.length();
107 void MessageManager::SetMessageLevel(std::string key,
110 std::map<std::string,int>::iterator i;
111 if (key==std::string("All")) {
112 GetInstance()->mAllLevel = level;
114 for (i=GetInstance()->mMessageLevel.begin();
115 i!=GetInstance()->mMessageLevel.end();
121 i = GetInstance()->mMessageLevel.find(key);
122 if (i!=GetInstance()->mMessageLevel.end()) {
126 bbtkWarning("MessageManager::SetMessageLevel : message type=<"
127 <<key<<"> unregistered");
134 int MessageManager::GetMessageLevel(std::string key)
136 int l = GetInstance()->mAllLevel;
137 std::map<std::string,int>::iterator i =
138 GetInstance()->mMessageLevel.find(key);
139 if (i!=GetInstance()->mMessageLevel.end()) {
140 if ( (*i).second > l ) l = (*i).second;
147 void MessageManager::PrintInfo()
149 bbtkMessage("Help",1,"================ Messages ================="
151 bbtkMessage("Help",1, "Kind");
153 k<(int)(GetInstance()->mMaxMessageLength-8);
155 bbtkMessageCont("Help",1," ");
157 bbtkMessageCont("Help",1,"Level Nature" << bbtkendl);
158 std::map<std::string,int>::iterator i;
159 std::map<std::string,std::string>::iterator j;
160 for (i=GetInstance()->mMessageLevel.begin(),
161 j=GetInstance()->mMessageHelp.begin();
162 i!=GetInstance()->mMessageLevel.end();++i,++j) {
163 bbtkMessage("Help",1, (*i).first);
165 k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
167 bbtkMessageCont("Help",1," ");
169 bbtkMessageCont("Help",1, (*i).second << "\t"
170 << (*j).second << bbtkendl);
172 bbtkMessage("Help",1,"==========================================="