+/*=========================================================================
+ Program: bbtk
+ Module: $RCSfile: bbtkMessageManager.h,v $
+ Language: C++
+ Date: $Date: 2009/05/28 08:12:06 $
+ Version: $Revision: 1.9 $
+=========================================================================*/
+
+/* ---------------------------------------------------------------------
+
+* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
+* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
+*
+* 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
- Warnings
- Errors
There are also "types" of messages which are strings which identify the nature of the message
- (for example : "Core" messages are generated by the core classes of the librairy, there can be a type of
+ (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 :
- bbtk::MessageManager::RegisterMessageType("Core","Messages generated by the core classes of the library",5);
+ bbtk::MessageManager::RegisterMessageType("Kernel","Messages generated by the core classes of the library",5);
where :
- -The first string is the type of the message (the keyword which will be used to generate a message of this type)
+ -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).
example :
- bbtkMessage("Core",4,"problem with "<<GetName()<<bbtkendl);
+ bbtkMessage("Kernel",4,"problem with "<<GetName()<<bbtkendl);
- will push the 3rd argument in std::cout if the message level of "Core" messages is greater or equal to 4.
+ will push the 3rd argument in std::cout if the message level of "Kernel" messages is greater or equal to 4.
which means that it generates a message of level 4 (0 : very important/always displayed ... 9 : deep debug message).
At run time, one is able to change the level of the messages displayed by using a command like :
- bbtk::MessageManager::SetMessageLevel("Core",5);
+ bbtk::MessageManager::SetMessageLevel("Kernel",5);
- which tells the manager to display all Core messages of level up to 5.
+ which tells the manager to display all Kernel messages of level up to 5.
Variants :
} \
else if (value<= __bbtkOnMessageLevelVariable)
+#define BBTK_PREPEND_MESSAGE_WITH_CODE
#ifdef BBTK_PREPEND_MESSAGE_WITH_CODE
-#define bbtkMessageCode \
- key[0] << key[1] << key[2] << value << " "
+#define bbtkMessageCode(key,value) \
+ bbtk::MessageManager::FormatKey(key,value)
#else
-#define bbtkMessageCode ""
+#define bbtkMessageCode(key,value) ""
#endif
#ifdef BBTK_PREPEND_MESSAGE_WITH_TAB
#define bbtkMessageTab ""
#endif
-#define BBTK_PREPEND_MESSAGE_WITH_SPACE
+//#define BBTK_PREPEND_MESSAGE_WITH_SPACE
#ifdef BBTK_PREPEND_MESSAGE_WITH_SPACE
#define bbtkMessageSpace(value) \
bbtk::MessageManager::GetSpace(value)
do { \
bbtkOnMessageLevel(key,value) \
{ \
- std::cout << bbtkMessageCode \
+ std::cout << bbtkMessageCode(key,value) \
<< bbtkMessageTab \
<< bbtkMessageSpace(value) \
<< MESSAGE; \
{ \
bbtkOnMessageLevel(key,value) \
{ \
- std::cout << bbtkMessageCode \
+ std::cout << bbtkMessageCode(key,value) \
<< bbtkMessageTab \
<< bbtkMessageSpace(value) \
<< MESSAGE; \
bbtkOnMessageLevel(key,value) \
{ \
bbtk::MessageManager::DecTab(); \
- std::cout << bbtkMessageCode \
+ std::cout << bbtkMessageCode(key,value) \
<< bbtkMessageTab \
<< bbtkMessageSpace(value) \
<< MESSAGE; \
{ \
bbtkOnMessageLevel(key,value) \
{ \
- std::cout << bbtkMessageCode \
+ std::cout << bbtkMessageCode(key,value) \
<< bbtkMessageTab \
<< bbtkMessageSpace(value) \
<< MESSAGE; \
{ \
bbtkOnMessageLevel(key,value) \
{ \
- std::cout << bbtkMessageCode \
+ std::cout << bbtkMessageCode(key,value) \
<< bbtkMessageTab \
<< bbtkMessageSpace(value) \
<< MESSAGE; \
bbtkOnMessageLevel(key,value) \
{ \
bbtk::MessageManager::DecTab(); \
- std::cout << bbtkMessageCode \
+ std::cout << bbtkMessageCode(key,value) \
<< bbtkMessageTab \
<< bbtkMessageSpace(value) \
<< MESSAGE; \
//===========================================================
#ifdef BBTK_COMPILE_ERROR_MESSAGES
-#include "bbtkWx.h"
+//#include "bbtkWx.h"
#define bbtkError(MESSAGE) \
do \
{ \
- bbtk::wx::ResetCursor(); \
std::ostringstream s; \
s << MESSAGE; \
std::ostringstream f; \
///
static MessageManager* GetInstance();
///
- static void RegisterMessageType(std::string key,
+ static bool RegisterMessageType(std::string key,
std::string help,
unsigned char default_level = 9);
///
///
static void PrintInfo();
+ static std::string FormatKey(const std::string& key, int value);
+
private:
std::map<std::string,int> mMessageLevel;
std::map<std::string,std::string> mMessageHelp;
unsigned int mMaxMessageLength;
- int mAllLevel;
};
//===========================================================