X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaMessageManager.cxx;h=ae10284760e73d7ee61d127f5c590f9ea3e7d575;hb=c8a0837d54a0c9004e53eb92ff652a8e996a2fad;hp=dc187102932b1970f8dc98f49e87a6630af14538;hpb=596488a9529ffbedea2e6693e32e9b19f042b7e7;p=crea.git diff --git a/src/creaMessageManager.cxx b/src/creaMessageManager.cxx index dc18710..ae10284 100644 --- a/src/creaMessageManager.cxx +++ b/src/creaMessageManager.cxx @@ -1,14 +1,37 @@ - /*========================================================================= +/* +# --------------------------------------------------------------------- +# +# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image +# pour la Santé) +# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton +# Previous Authors : Laurent Guigues, Jean-Pierre Roux +# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil +# +# This software is governed by the CeCILL-B license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL-B +# license as circulated by CEA, CNRS and INRIA at the following URL +# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +# or in the file LICENSE.txt. +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL-B license and that you accept its terms. +# ------------------------------------------------------------------------ +*/ + +/*========================================================================= Program: crea Module: $RCSfile: creaMessageManager.cxx,v $ Language: C++ - Date: $Date: 2008/09/26 14:09:55 $ - Version: $Revision: 1.1 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + Date: $Date: 2012/11/15 10:43:26 $ + Version: $Revision: 1.4 $ This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR @@ -24,15 +47,30 @@ namespace crea { + //=========================================================================== MessageManager::MessageManager() - : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9) - + : mMaxMessageLength(8), + mSendToCout(true) { std::string key; + key ="all"; - mMessageLevel[key] = 0; - mMessageHelp[key] = "Minimum level for all kind of messages"; + mMessageMap[key] = new MessageType(0,"Minimum level for all kind of messages"); if (mMaxMessageLengthsecond; + } } - + //=========================================================================== + //=========================================================================== MessageManager* MessageManager::GetInstance() { static MessageManager* m = 0; if (!m) m = new MessageManager(); return m; } + //=========================================================================== - void MessageManager::RegisterMessageType(std::string key, - std::string help, - unsigned char default_level) + //=========================================================================== + void MessageManager::RegisterMessageType(const std::string& key, + const std::string& help, + unsigned char default_level) { - GetInstance()->mMessageLevel[key] = default_level; - GetInstance()->mMessageHelp[key] = help; + GetInstance()->mMessageMap[key] = new MessageType(default_level,help); + if (GetInstance()->mMaxMessageLengthmMaxMessageLength = key.length(); } + //=========================================================================== - - - void MessageManager::SetMessageLevel(std::string key, - unsigned char level) + //=========================================================================== + void MessageManager::SetMessageLevel(const std::string& key, + unsigned char level) { - std::map::iterator i; - i = GetInstance()->mMessageLevel.find(key); - if (i!=GetInstance()->mMessageLevel.end()) + MessageMapType::iterator i; + i = GetInstance()->mMessageMap.find(key); + if (i!=GetInstance()->mMessageMap.end()) { - (*i).second = level; + (*i).second->Level = level; } else { @@ -162,24 +149,48 @@ namespace crea } } + //=========================================================================== - - - int MessageManager::GetMessageLevel(std::string key) + //=========================================================================== + int MessageManager::GetMessageLevel(const std::string& key) { - int l = GetInstance()->mMessageLevel["all"]; - std::map::iterator i = - GetInstance()->mMessageLevel.find(key); - if (i!=GetInstance()->mMessageLevel.end()) { - if ( (*i).second > l ) l = (*i).second; + int l = GetInstance()->mMessageMap["all"]->Level; + MessageMapType::iterator i = GetInstance()->mMessageMap.find(key); + if (i!=GetInstance()->mMessageMap.end()) { + if ( (*i).second->Level > l ) l = (*i).second->Level; } - int m = GetInstance()->mMessageLevel["max"]; + int m = GetInstance()->mMessageMap["max"]->Level; if (l>m) l=m; return l; } + //=========================================================================== + //=========================================================================== + void MessageManager::SendMessagesToCout(bool v) + { + GetInstance()->mSendToCout = v; + } + //=========================================================================== + //=========================================================================== + void MessageManager::SendMessage(const std::string& key, const std::string& mess) + { + if (GetInstance()->mSendToCout) + { + std::cout << mess; + } + GetInstance()->mMessageMap[key]->Signal(mess); + } + //=========================================================================== + //=========================================================================== + void MessageManager::AddMessageObserver( const std::string& key, MessageCallbackType callback ) + { + GetInstance()->mMessageMap[key]->Signal.connect(callback); + } + //=========================================================================== + + //=========================================================================== void MessageManager::PrintInfo() { creaMessage("info",1,"================ Messages =================" @@ -192,23 +203,23 @@ namespace crea creaMessageCont("info",1," "); } creaMessageCont("info",1,"Level Nature" << creaendl); - std::map::iterator i; - std::map::iterator j; - for (i=GetInstance()->mMessageLevel.begin(), - j=GetInstance()->mMessageHelp.begin(); - i!=GetInstance()->mMessageLevel.end();++i,++j) { - creaMessage("info",1, (*i).first); - for (int k=0; - k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length()); - k++) { - creaMessageCont("info",1," "); - } - creaMessageCont("info",1, (*i).second << "\t" - << (*j).second << creaendl); + MessageMapType::iterator i; + for (i=GetInstance()->mMessageMap.begin(); + i!=GetInstance()->mMessageMap.end(); + ++i) + { + creaMessage("info",1, (*i).first); + for (int k=0; + k<(int)(GetInstance()->mMaxMessageLength+2-(*i).first.length()); + k++) { + creaMessageCont("info",1," "); + } + creaMessageCont("info",1, (*i).second->Level << "\t" + << (*i).second->Help << creaendl); } creaMessage("info",1,"===========================================" << creaendl); } - + //=========================================================================== }