torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MessageTable.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_MESSAGETABLE_HPP
17 #define TORC_GENERIC_MESSAGETABLE_HPP
18 
20 #include "torc/generic/Error.hpp"
22 
23 namespace torc { namespace generic { class Message; } }
24 
25 namespace torc {
26 namespace generic {
27 
28 /**
29  * Table of messages for this library. This is used for retrieving a message for a given MessageId.
30  * @note getMessage method is a read only method, and as such it is thread-safe. However, the
31  * changeMessageSeverity() and changeMessageSeverity() are not thread-safe. Typically they are not
32  * meant to be used in a multi-threaded context. If required however, for some reason, they need to
33  * be protected by proper locking contexts
34  */
35 class MessageTable {
36 public:
37  typedef std::map<MessageId, Message> MessageContainer;
38 
39 public:
40  /**
41  * Get the message string corresponding to the message id. This is constructed using the actual
42  * message string and the currently set severity of this message.
43  *
44  * @param[in] inId MessageId object to denote the message.
45  * @return Formatted message string. Empty string is returned if there was some error.
46  */
47  std::string getMessage(MessageId inId) const;
48 
49  /**
50  * Change the message string for a given Id.
51  *
52  * @param[in] inId MessageId that needs to be changed
53  * @param[in] inMessage New message that needs to be set.
54  */
55  void changeMessageString(MessageId inId, const Message& inMessage) throw (Error);
56 
57  /**
58  * Change the message severity for a given Id.
59  *
60  * @param[in] inId MessageId that needs to be changed
61  * @param[in] inSeverity New severity that needs to be set.
62  */
63  void changeMessageSeverity(MessageId inId, MessageSeverity inSeverity);
64 
65  /**
66  * Get a pointer to the singleton MessageTable object.
67  */
68  static MessageTable* instance();
69 
70 private:
71  explicit MessageTable();
72 
73 public:
74  ~MessageTable() throw ();
75 
76 private:
77  MessageTable(const MessageTable& source);
78 
79  MessageTable& operator=(const MessageTable& source);
80 
81  void operator delete(void *); //block
82 
83 private:
85 };
86 
87 } // namespace generic
88 } // namespace torc
89 
90 #endif // TORC_GENERIC_MESSAGETABLE_HPP
MessageContainer mMessages
static MessageTable * instance()
void changeMessageSeverity(MessageId inId, MessageSeverity inSeverity)
std::map< MessageId, Message > MessageContainer
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void changeMessageString(MessageId inId, const Message &inMessage)
std::string getMessage(MessageId inId) const