bbtkMessageManager.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkMessageManager.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/17 08:18:13 $
00006   Version:   $Revision: 1.12 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00035 #include "bbtkMessageManager.h"
00036 
00037 namespace bbtk 
00038 {
00039 
00040   MessageManager::MessageManager() 
00041     : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9)
00042     
00043   {
00044     std::string key;
00045     key ="all";
00046     mMessageLevel[key] = 0;
00047     mMessageHelp[key] = "Minimum level for all kind of messages";
00048     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00049     key ="max";
00050     mMessageLevel[key] = 9;
00051     mMessageHelp[key] = "Maximum level for all kind of messages";
00052     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00053     key ="Kernel";
00054     mMessageLevel[key] = 0;
00055     mMessageHelp[key] = "Messages generated by the core classes of the lib";
00056     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00057     key ="process";
00058     mMessageLevel[key] = 0;
00059     mMessageHelp[key] = "Messages related to box processing";
00060     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00061     key = "Help";
00062     mMessageLevel[key] = 1;
00063     mMessageHelp[key] = "Help messages";
00064     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00065     key = "Error";
00066     mMessageLevel[key] = 0;
00067     mMessageHelp[key] = "Error messages";
00068     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00069     key = "Warning";
00070     mMessageLevel[key] = 1;
00071     mMessageHelp[key] = "Warning messages";
00072     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00073     key = "Output";
00074     mMessageLevel[key] = 1;
00075     mMessageHelp[key] = "Output messages";
00076     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00077     key = "debug";
00078     mMessageLevel[key] = 0;
00079     mMessageHelp[key] = "Debug messages";
00080     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00081     key = "Config";
00082     mMessageLevel[key] = 0;
00083     mMessageHelp[key] = "Configuration related messages";
00084     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00085     key = "data";
00086     mMessageLevel[key] = 0;
00087     mMessageHelp[key] = "Data related messages";
00088     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00089     key = "wx";
00090     mMessageLevel[key] = 0;
00091     mMessageHelp[key] = "Widgets related messages";
00092     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00093     key = "gui";
00094     mMessageLevel[key] = 0;
00095     mMessageHelp[key] = "Graphical user interface related messages";
00096     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00097     key = "object";
00098     mMessageLevel[key] = 0;
00099     mMessageHelp[key] = "object memory related messages";
00100     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00101     key = "package";
00102     mMessageLevel[key] = 0;
00103     mMessageHelp[key] = "Packages related messages";
00104     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00105     key = "connection";
00106     mMessageLevel[key] = 0;
00107     mMessageHelp[key] = "Connections related messages";
00108     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00109     key = "modified";
00110     mMessageLevel[key] = 0;
00111     mMessageHelp[key] = "Modified related messages";
00112     if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
00113    }
00114 
00115 
00116 
00117 
00118   MessageManager::~MessageManager() 
00119   {
00120     //      std::cout << "~MessageManager"<<std::endl;
00121   }
00122   
00123 
00124 
00125   MessageManager* MessageManager::GetInstance() 
00126   { 
00127     static MessageManager* m = 0;
00128     if (!m) m = new MessageManager();
00129     return m; 
00130   }
00131 
00132   void MessageManager::RegisterMessageType(std::string key, 
00133                                                   std::string help,
00134                                                   unsigned char default_level) 
00135   {
00136     GetInstance()->mMessageLevel[key] = default_level;
00137     GetInstance()->mMessageHelp[key] = help;
00138     if (GetInstance()->mMaxMessageLength<key.length()) 
00139       GetInstance()->mMaxMessageLength = key.length();
00140   }
00141 
00142 
00143 
00144   void MessageManager::SetMessageLevel(std::string key, 
00145                                               unsigned char level) 
00146   {
00147     std::map<std::string,int>::iterator i;
00148     i = GetInstance()->mMessageLevel.find(key);
00149     if (i!=GetInstance()->mMessageLevel.end()) 
00150       {
00151         (*i).second = level;
00152       }
00153     else 
00154       {
00155         bbtkWarning("MessageManager::SetMessageLevel : message type=<"
00156                     <<key<<"> unregistered");
00157       }
00158     
00159   }
00160   
00161   
00162   
00163   int MessageManager::GetMessageLevel(std::string key) 
00164   {
00165     int l = GetInstance()->mMessageLevel["all"];
00166     std::map<std::string,int>::iterator i = 
00167       GetInstance()->mMessageLevel.find(key);
00168     if (i!=GetInstance()->mMessageLevel.end()) {
00169       if ( (*i).second > l ) l = (*i).second;      
00170     }
00171     int m = GetInstance()->mMessageLevel["max"];
00172     if (l>m) l=m;
00173     return l;
00174   }
00175 
00176 
00177 
00178   void MessageManager::PrintInfo() 
00179   {
00180     bbtkMessage("Help",1,"================ Messages =================" 
00181                 << bbtkendl);
00182     bbtkMessage("Help",1, "Kind");
00183     for (int k=0;
00184          k<(int)(GetInstance()->mMaxMessageLength-2);
00185          k++) 
00186       {
00187         bbtkMessageCont("Help",1," "); 
00188       }
00189     bbtkMessageCont("Help",1,"Level  Nature" << bbtkendl);
00190     std::map<std::string,int>::iterator i;
00191     std::map<std::string,std::string>::iterator j;  
00192     for (i=GetInstance()->mMessageLevel.begin(),
00193            j=GetInstance()->mMessageHelp.begin();
00194          i!=GetInstance()->mMessageLevel.end();++i,++j) {
00195       bbtkMessage("Help",1, (*i).first);
00196       for (int k=0;
00197            k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length());
00198            k++) {
00199         bbtkMessageCont("Help",1," ");
00200       }
00201       bbtkMessageCont("Help",1, (*i).second << "\t" 
00202                       << (*j).second << bbtkendl);
00203     }
00204     bbtkMessage("Help",1,"===========================================" 
00205                 << bbtkendl);
00206   }
00207   
00208 
00209 }

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6