IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
LogMessageManager.h
1 // LogMessageManager.h:
3 // --------------------
4 //
17 
18 #ifndef __IPSDKUTIL_LOGMESSAGEMANAGER_H__
19 #define __IPSDKUTIL_LOGMESSAGEMANAGER_H__
20 
21 // suppression warnings
22 // warning C4275: interface non dll class 'boost::noncopyable_::noncopyable' utilisée comme base d'une interface dll class 'ipsdk::LogMessageManager'
23 // warning C4251: 'ipsdk::LogMessageManager::_libraryName' : class 'std::basic_string<_Elem,_Traits,_Ax>' nécessite une interface DLL pour être utilisé(e) par les clients de class 'ipsdk::LogMessageManager'
24 #pragma warning (push)
25 #pragma warning (disable : 4275 4251)
26 
28 #include <IPSDKUtil/BaseTypes.h>
30 #include <boost/noncopyable.hpp>
31 #include <boost/checked_delete.hpp> // Anticipating Boost 1.75
32 #include <map>
33 
34 namespace boost {
35  template<typename Target, typename Source>
36  Target lexical_cast(const Source &arg);
37 }
38 
39 namespace ipsdk {
40 
43 
44 class IPSDKUTIL_API LogMessageManager : boost::noncopyable
45 {
46  // friend function for members access
47  template<class T>
48  friend void boost::checked_delete(T * x) BOOST_NOEXCEPT;
49 
50 public:
52  static LogMessageManager& getInstance(const std::string& libraryName);
53 
54 protected:
57  LogMessageManager(const std::string& libraryName);
60 
61 // methods
62 public:
64  const std::string& getLibraryName() const;
65 
67  template <typename EnumT>
68  bool existsMessage(const EnumT& messageId) const
69  {
70  return existsMessage(typeid(EnumT).name(), (ipInt32)messageId);
71  }
72 
74  bool existsMessage(const std::string& enumTypeStr,
75  ipInt32 messageId) const;
76 
79  template <typename EnumT>
80  const std::string& getMessage(const EnumT& messageId)
81  {
82  return getMessage(typeid(EnumT).name(), (ipInt32)messageId);
83  }
84 
87  const std::string& getMessage(const std::string& enumTypeStr,
88  ipInt32 messageId) const;
89 
91  void clear();
92 
95  template <typename EnumT>
96  void removeMessage(const EnumT& messageId)
97  {
98  removeMessage(typeid(EnumT).name(), (ipInt32)messageId);
99  }
100 
103  void removeMessage(const std::string& enumTypeStr,
104  ipInt32 messageId);
105 
108  template <typename EnumT>
109  void addMessage(const EnumT& messageId,
110  const std::string& messageStr)
111  {
112  addMessage(typeid(EnumT).name(), (ipInt32)messageId, messageStr);
113  }
114 
117  void addMessage(const std::string& enumTypeStr,
118  ipInt32 messageId,
119  const std::string& messageStr);
120 
132  void readFile(const boost::filesystem::path& msgFilePath,
133  bool bAppend,
134  EnumStringToIntFunc enumStringToIntFunction =
135  boost::lexical_cast<ipInt32, const std::string&>);
136 
137 // attributes
138 protected:
140  std::string _libraryName;
141 
143  typedef std::map<ipInt32, std::string> MessageMap;
144 
146  typedef std::map<std::string, MessageMap> MessageColl;
147 
150 };
151 
154 
155 } // end of namespace ipsdk
156 
157 #pragma warning (pop)
158 
159 #endif // __IPSDKUTIL_LOGMESSAGEMANAGER_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
MessageColl _messageColl
message map associating ids with corresponding message
Definition: LogMessageManager.h:149
ipInt32(* EnumStringToIntFunc)(const std::string &enumStrValue)
defining a function type for string to integer convertions
Definition: EnumUtils.h:27
int32_t ipInt32
Base types definition.
Definition: BaseTypes.h:52
Definition: DataItemNodeHdrMacrosDetails.h:48
Base types for multiplatform compatibility.
std::map< std::string, MessageMap > MessageColl
map associating a string (an enumerate typeid) to a MessageMap
Definition: LogMessageManager.h:146
bool existsMessage(const EnumT &messageId) const
template member for easy check whether a message is associated to a given id
Definition: LogMessageManager.h:68
#define IPSDKUTIL_API
Import/Export macro for library IPSDKUtil.
Definition: IPSDKUtilExports.h:27
std::map< ipInt32, std::string > MessageMap
map associating a message id to a string
Definition: LogMessageManager.h:143
Log message manager for ipsdk libraries.
Definition: LogMessageManager.h:44
std::string _libraryName
library name for message manager
Definition: LogMessageManager.h:140
Definition of import/export macro for library.
void addMessage(const EnumT &messageId, const std::string &messageStr)
template member for easy add a new message
Definition: LogMessageManager.h:109
void removeMessage(const EnumT &messageId)
template member for easy remove an existing message
Definition: LogMessageManager.h:96
const std::string & getMessage(const EnumT &messageId)
template member for easy retrieve a message given an id
Definition: LogMessageManager.h:80
Utility functions for enumerate manipulation.