X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaMessageManager.h;h=5aaa6ec7526db1998699a29100fad4d8d2736468;hb=cf2e11cdafb5f71b1f978f06b08a1478d4cdcfa1;hp=37fe5bf1e65a0acdf678b97b1c9a73a0de4dfe22;hpb=c8309c53e6790e4f63cf7c43109eba8a2ba5878b;p=crea.git diff --git a/src/creaMessageManager.h b/src/creaMessageManager.h index 37fe5bf..5aaa6ec 100644 --- a/src/creaMessageManager.h +++ b/src/creaMessageManager.h @@ -1,376 +1,506 @@ - -/*! \file - - \brief Class creaMessageManager and Macros for outputing messages in crea - - There are 4 kinds of messages : - - Messages (normal messages) - - Debug messages (not compiled in release) - - Warnings - - Errors - There are also "types" of messages which are strings which identify the nature of the message - (for example : "Kernel" messages are generated by the core classes of the library, there can be a type of - message for each type of Node, and so on...) - A type of message must be declared by registering it into the MessageManager. This is done by a line like : - crea::MessageManager::RegisterMessageType("Kernel","Messages generated by the core classes of the library",5); - where : - -The first string is the type of the message (the category which will be used to generate a message of this type) - -The second string is help string - -The integer is the initial level for the messages of this type (see below). - - To generate a message of a known type then use one of the macros : - creaMessage, creaDebugMessage, creaWarning, creaError or their variants. - - example : - - creaMessage("Kernel",4,"problem with "< -#include - -#include -#include -#include -#include - -// Comment out these symbols to prevent compilation -//#define CREA_COMPILE_MESSAGES -//#define CREA_COMPILE_DEBUG_MESSAGES -//#define CREA_COMPILE_WARNING_MESSAGES -//#define CREA_COMPILE_ERROR_MESSAGES - - -#define creaOnMessageLevel(key,value) \ - int __creaOnMessageLevelVariable = \ - crea::MessageManager::GetMessageLevel(key); \ - if ( __creaOnMessageLevelVariable<0) \ - { \ - creaWarning("message type '"<0) \ - { \ - std::cerr << "!! WARNING !! " << MESSAGE << std::endl; \ - if (lev >1) \ - { \ - std::cerr << "!! WARNING !! In file '"<<__FILE__ \ - <<"' ; Line "<<__LINE__< MessageSignalType; - typedef MessageSignalType::slot_function_type MessageCallbackType; - //============================================= - /// - MessageManager(); - /// - ~MessageManager(); - /// - static MessageManager* GetInstance(); - /// - static void RegisterMessageType(const std::string& key, - const std::string& help, - unsigned char default_level = 9); - /// - static void SetMessageLevel(const std::string& key, unsigned char level); - /// - static int GetMessageLevel(const std::string& key); - /// - static void SendMessage(const std::string& key, const std::string& mess); - /// - static void AddMessageObserver(const std::string& key, MessageCallbackType callback ); - /// - static void SendMessagesToCout(bool v = true); - /// - static std::string& GetTab() { static std::string s; return s; } - /// - static std::string GetSpace(int n) { - std::string s; s.insert(0," ",n); return s; } - /// - static void IncTab() { GetTab() += std::string(" "); } - /// - static void DecTab() { GetTab() = GetTab().substr(0,GetTab().length()-1); } - /// - static void ResetTab() { GetTab() = std::string(""); } - /// - static void PrintInfo(); - /// - - private: - struct MessageType - { - MessageType(int l, const std::string& h) : Level(l), Help(h) {} - int Level; - std::string Help; - MessageSignalType Signal; - }; - typedef std::map MessageMapType; - MessageMapType mMessageMap; - unsigned int mMaxMessageLength; - bool mSendToCout; - }; - //=========================================================== - -} - -#include "creaException.h" - -#endif +/* +# --------------------------------------------------------------------- +# +# 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. +# ------------------------------------------------------------------------ +*/ + +/*! \file + \brief Class creaMessageManager and Macros for outputing messages in crea + There are 4 kinds of messages : + - Messages (normal messages) + - Debug messages (not compiled in release) + - Warnings + - Errors + There are also "types" of messages which are strings which identify the nature of the message + (for example : "Kernel" messages are generated by the core classes of the library, there can be a type of + message for each type of Node, and so on...) + A type of message must be declared by registering it into the MessageManager. This is done by a line like : + crea::MessageManager::RegisterMessageType("Kernel","Messages generated by the core classes of the library",5); + where : + -The first string is the type of the message (the category which will be used to generate a message of this type) + -The second string is help string + -The integer is the initial level for the messages of this type (see below). + To generate a message of a known type then use one of the macros : + creaMessage, creaDebugMessage, creaWarning, creaError or their variants. + example : + creaMessage("Kernel",4,"problem with "< +#include +#include +#include +#include +#include +// Comment out these symbols to prevent compilation +//#define CREA_COMPILE_MESSAGES +//#define CREA_COMPILE_DEBUG_MESSAGES +//#define CREA_COMPILE_WARNING_MESSAGES +//#define CREA_COMPILE_ERROR_MESSAGES +#define creaOnMessageLevel(key,value) \ + int __creaOnMessageLevelVariable = \ + crea::MessageManager::GetMessageLevel(key); \ + if ( __creaOnMessageLevelVariable<0) \ + { \ + creaWarning("message type '"<0) \ + { \ + std::cerr << "!! WARNING !! " << MESSAGE << std::endl; \ + if (lev >1) \ + { \ + std::cerr << "!! WARNING !! In file '"<<__FILE__ \ + <<"' ; Line "<<__LINE__< MessageSignalType; + + typedef MessageSignalType::slot_function_type MessageCallbackType; + + //============================================= + + /// + + MessageManager(); + + /// + + ~MessageManager(); + + /// + + static MessageManager* GetInstance(); + + /// + + static void RegisterMessageType(const std::string& key, + + const std::string& help, + + unsigned char default_level = 9); + + /// + + static void SetMessageLevel(const std::string& key, unsigned char level); + + /// + + static int GetMessageLevel(const std::string& key); + + /// + + static void SendMessage(const std::string& key, const std::string& mess); + + /// + + static void AddMessageObserver(const std::string& key, MessageCallbackType callback ); + + /// + + static void SendMessagesToCout(bool v = true); + + /// + + static std::string& GetTab() { static std::string s; return s; } + + /// + + static std::string GetSpace(int n) { + + std::string s; s.insert(0," ",n); return s; } + + /// + + static void IncTab() { GetTab() += std::string(" "); } + + /// + + static void DecTab() { GetTab() = GetTab().substr(0,GetTab().length()-1); } + + /// + + static void ResetTab() { GetTab() = std::string(""); } + + /// + + static void PrintInfo(); + + /// + + + + private: + + struct MessageType + + { + + MessageType(int l, const std::string& h) : Level(l), Help(h) {} + + int Level; + + std::string Help; + + MessageSignalType Signal; + + }; + + typedef std::map MessageMapType; + + MessageMapType mMessageMap; + + unsigned int mMaxMessageLength; + + bool mSendToCout; + + }; + + //=========================================================== + + + +} + + + +#include "creaException.h" + + + +#endif +