\brief Manages the messages displayed by crea
*/
+
#ifndef __creaMessageManager_h__
#define __creaMessageManager_h__
#include <map>
#include <iostream>
#include <sstream>
+
+
+
+namespace crea
+{
+ class CREA_EXPORT MessageManager
+ {
+ public:
+ //=============================================
+ typedef boost::signals2::signal<void (const std::string&)> 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<std::string,MessageType*> MessageMapType;
+ MessageMapType mMessageMap;
+ unsigned int mMaxMessageLength;
+ bool mSendToCout;
+ };
+ //===========================================================
+}
+
+
+
+
+
+
+
+
// Comment out these symbols to prevent compilation
//#define CREA_COMPILE_MESSAGES
//#define CREA_COMPILE_DEBUG_MESSAGES
<< creaMessageTab \
<< creaMessageSpace(value) \
<< MESSAGE; \
- crea::MessageManager::SendMessage(key,s.str()); \
+ crea::MessageManager::HSendMessage(key,s.str()); \
} \
} \
while (0)
{ \
std::ostringstream s; \
s << MESSAGE; \
- crea::MessageManager::SendMessage(key,s.str()); \
+ crea::MessageManager::HSendMessage(key,s.str()); \
} \
} \
while (0)
<< creaMessageTab \
<< creaMessageSpace(value) \
<< MESSAGE; \
- crea::MessageManager::SendMessage(key,s.str()); \
+ crea::MessageManager::HSendMessage(key,s.str()); \
crea::MessageManager::IncTab(); \
} \
} \
<< creaMessageTab \
<< creaMessageSpace(value) \
<< MESSAGE; \
- crea::MessageManager::SendMessage(key,s.str()); \
+ crea::MessageManager::HSendMessage(key,s.str()); \
} \
} \
while (0)
-namespace crea
-
-{
-
-
-
- class CREA_EXPORT MessageManager
-
- {
-
- public:
-
- //=============================================
-
- typedef boost::signals2::signal<void (const std::string&)> 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<std::string,MessageType*> MessageMapType;
-
- MessageMapType mMessageMap;
-
- unsigned int mMaxMessageLength;
-
- bool mSendToCout;
-
- };
-
- //===========================================================
-
-
-
-}