00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/generic/util/MessageTable.hpp $ 00003 // $Id: MessageTable.hpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 #ifndef TORC_GENERIC_UTIL_MESSAGETABLE_HPP 00017 #define TORC_GENERIC_UTIL_MESSAGETABLE_HPP 00018 00019 #include "torc/generic/util/MessageId.hpp" 00020 #include "torc/generic/util/Error.hpp" 00021 #include "torc/generic/util/MessageSeverity.hpp" 00022 00023 namespace torc { namespace generic { class Message; } } 00024 00025 namespace torc { 00026 00027 namespace generic { 00028 00029 /** 00030 * Table of messages for this library. This is used for retreiving a message for a given MessageId. 00031 * @note getMessage method is a read only method, and as such it is thread-safe. However, the changeMessageSeverity() and changeMessageSeverity() are not thread-safe. Typically they are not meant to be used in a multi-threaded context. If required however, for some reason, they need to be protected by proper locking contexts 00032 */ 00033 class MessageTable 00034 { 00035 public: 00036 typedef std::map<MessageId,Message> MessageContainer; 00037 00038 public: 00039 /** 00040 * Get the message string corresponding to the message id. This is constructed using the actual message string and the currently set severity of this message. 00041 * 00042 * @param[in] inId MessageId object to denote the message. 00043 * @return Formatted message string. Empty string is returned if there was some error. 00044 */ 00045 std::string 00046 getMessage(MessageId inId) const throw(); 00047 00048 /** 00049 * Change the message string for a given Id. 00050 * 00051 * @param[in] inId MessageId that needs to be changed 00052 * @param[in] inMessage New message that needs to be set. 00053 */ 00054 void 00055 changeMessageString(MessageId inId, 00056 const Message & inMessage) throw(Error); 00057 00058 /** 00059 * Change the message severity for a given Id. 00060 * 00061 * @param[in] inId MessageId that needs to be changed 00062 * @param[in] inSeverity New severity that needs to be set. 00063 */ 00064 void changeMessageSeverity(MessageId inId, 00065 MessageSeverity inSeverity) throw(); 00066 00067 /** 00068 * Get a pointer to the singleton MessageTable object. 00069 */ 00070 static MessageTable * 00071 instance(); 00072 00073 00074 private: 00075 explicit MessageTable(); 00076 00077 00078 public: 00079 ~MessageTable() throw(); 00080 00081 00082 private: 00083 MessageTable(const MessageTable & source); 00084 00085 MessageTable & operator=( 00086 const MessageTable & source) throw(); 00087 00088 void 00089 operator delete( void *); //block 00090 00091 private: 00092 MessageContainer mMessages; 00093 }; 00094 00095 } // namespace torc::generic 00096 00097 } // namespace torc 00098 #endif // TORC_GENERIC_UTIL_MESSAGETABLE_HPP