X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaMessageManager.h;h=54dd93efcc954ff73cb1f9b7b81cf5397b4809b1;hb=b4cd33464fc8cc5658da64fe75c3f689169f0cb0;hp=618feae2d6b79beebbc1c409d1a290175adf4994;hpb=17824854619941a12697fea8524f4218f9a14ef9;p=crea.git diff --git a/src/creaMessageManager.h b/src/creaMessageManager.h index 618feae..54dd93e 100644 --- a/src/creaMessageManager.h +++ b/src/creaMessageManager.h @@ -4,6 +4,8 @@ # 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, @@ -20,7 +22,8 @@ # # 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 @@ -58,6 +61,7 @@ \brief Manages the messages displayed by crea */ + #ifndef __creaMessageManager_h__ #define __creaMessageManager_h__ @@ -66,12 +70,64 @@ #include "creaSystem.h" #include "creaRTTI.h" // for CREA_GET_CURRENT_OBJECT_NAME // Signal/slot mechanism for message events -#include +#include #include #include #include #include #include + + + +namespace crea +{ + class CREA_EXPORT MessageManager + { + public: + //============================================= + typedef boost::signals2::signal 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 HSendMessage(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; + }; + //=========================================================== +} + + + + + + + + // Comment out these symbols to prevent compilation //#define CREA_COMPILE_MESSAGES //#define CREA_COMPILE_DEBUG_MESSAGES @@ -126,7 +182,7 @@ << creaMessageTab \ << creaMessageSpace(value) \ << MESSAGE; \ - crea::MessageManager::SendMessage(key,s.str()); \ + crea::MessageManager::HSendMessage(key,s.str()); \ } \ } \ while (0) @@ -142,7 +198,7 @@ { \ std::ostringstream s; \ s << MESSAGE; \ - crea::MessageManager::SendMessage(key,s.str()); \ + crea::MessageManager::HSendMessage(key,s.str()); \ } \ } \ while (0) @@ -156,7 +212,7 @@ << creaMessageTab \ << creaMessageSpace(value) \ << MESSAGE; \ - crea::MessageManager::SendMessage(key,s.str()); \ + crea::MessageManager::HSendMessage(key,s.str()); \ crea::MessageManager::IncTab(); \ } \ } \ @@ -174,7 +230,7 @@ << creaMessageTab \ << creaMessageSpace(value) \ << MESSAGE; \ - crea::MessageManager::SendMessage(key,s.str()); \ + crea::MessageManager::HSendMessage(key,s.str()); \ } \ } \ while (0) @@ -371,127 +427,6 @@ -namespace crea - -{ - - - - class CREA_EXPORT MessageManager - - { - - public: - - //============================================= - - typedef boost::signal 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; - - }; - - //=========================================================== - - - -}