torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::MessageTable Class Reference

#include <MessageTable.hpp>

Public Types

typedef std::map< MessageId,
Message
MessageContainer
 

Public Member Functions

std::string getMessage (MessageId inId) const
 
void changeMessageString (MessageId inId, const Message &inMessage) throw (Error)
 
void changeMessageSeverity (MessageId inId, MessageSeverity inSeverity)
 
 ~MessageTable () throw ()
 

Static Public Member Functions

static MessageTableinstance ()
 

Private Member Functions

 MessageTable ()
 
 MessageTable (const MessageTable &source)
 
MessageTableoperator= (const MessageTable &source)
 
void operator delete (void *)
 

Private Attributes

MessageContainer mMessages
 

Detailed Description

Table of messages for this library. This is used for retrieving a message for a given MessageId.

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

Definition at line 35 of file MessageTable.hpp.

Member Typedef Documentation

Definition at line 37 of file MessageTable.hpp.

Constructor & Destructor Documentation

torc::generic::MessageTable::MessageTable ( )
explicitprivate

Definition at line 99 of file MessageTable.cpp.

99  : mMessages() {
100  //Populate message table
102  "Array index size does not match array dimensions", eMessageSeverityError);
103 
104  mMessages[eMessageIdErrorArrayIndexOutOfBounds] = Message("Array index out of bounds",
106 
107  mMessages[eMessageIdErrorEmptyArray] = Message("Empty array", eMessageSeverityError);
108 
109  mMessages[eMessageIdErrorNullChildfactory] = Message("Null child factory",
111 
112  mMessages[eMessageIdErrorEmptyItemName] = Message("Empty item name", eMessageSeverityError);
113 
114  mMessages[eMessageIdErrorItemAlreadyExists] = Message("Item already exists",
116 
117  mMessages[eMessageIdErrorItemNotFound] = Message("Item not found", eMessageSeverityError);
118 
119  mMessages[eMessageIdErrorPointerToItemDoesNotExist] = Message("Pointer to item does not exist",
121 
122  mMessages[eMessageIdErrorItemSizeMismatch] = Message("Item size does not match",
124 
125  mMessages[eMessageIdErrorConnectionInvalid] = Message("Provided connection is invalid",
127 
128  mMessages[eMessageIdErrorTypeCast] = Message("Type cast not possible", eMessageSeverityError);
129 
130  mMessages[eMessageIdErrorValueNotSet] = Message("Value not set", eMessageSeverityError);
131 
132  mMessages[eMessageIdErrorCompositionTypeMismatch] = Message("Composition type mismatch",
134  mMessages[eMessageIdParserError] = Message("Error from parser", eMessageSeverityError);
135 
136  mMessages[eMessageIdParserWarning] = Message("Warning from parser", eMessageSeverityWarning);
137  mMessages[eMessageIdErrorNullPointer] = Message("Null Pointer detected", eMessageSeverityError);
138  mMessages[eMessageIdErrorUnsupoortedOperation] = Message("Operation is unsupported on class",
140 }
MessageContainer mMessages
torc::generic::MessageTable::~MessageTable ( )
throw (
)

Definition at line 142 of file MessageTable.cpp.

142 {}
torc::generic::MessageTable::MessageTable ( const MessageTable source)
private

Member Function Documentation

void torc::generic::MessageTable::changeMessageSeverity ( MessageId  inId,
MessageSeverity  inSeverity 
)

Change the message severity for a given Id.

Parameters
[in]inIdMessageId that needs to be changed
[in]inSeverityNew severity that needs to be set.

Definition at line 84 of file MessageTable.cpp.

84  {
85  MessageContainer::const_iterator msg = mMessages.find(inId);
86  if(msg != mMessages.end()) {
87  mMessages[inId].setSeverity(inSeverity);
88  }
89 }
MessageContainer mMessages
void torc::generic::MessageTable::changeMessageString ( MessageId  inId,
const Message inMessage 
)
throw (Error
)

Change the message string for a given Id.

Parameters
[in]inIdMessageId that needs to be changed
[in]inMessageNew message that needs to be set.

Definition at line 74 of file MessageTable.cpp.

74  {
75  mMessages[inId] = inMessage;
76 }
MessageContainer mMessages
std::string torc::generic::MessageTable::getMessage ( MessageId  inId) const

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.

Parameters
[in]inIdMessageId object to denote the message.
Returns
Formatted message string. Empty string is returned if there was some error.

Get the message string corresponding to the message inId. This is constructed using the actual message string and the currently set severity of this message.

Parameters
[in]inIdMessageId object to denote the message.

Definition at line 34 of file MessageTable.cpp.

34  {
35  MessageContainer::const_iterator msg = mMessages.find(inId);
36  if(msg == mMessages.end()) {
37  return std::string();
38  }
39  const Message message((*msg).second);
40  char msgString[BUFSIZ];
41  int nbytes = 0;
42  switch(message.getSeverity()) {
44  nbytes = snprintf(msgString, BUFSIZ, "SUPPRESSED ");
45  break;
46  }
47  case eMessageSeverityInfo: {
48  nbytes = snprintf(msgString, BUFSIZ, "INFO ");
49  break;
50  }
51  case eMessageSeverityError: {
52  nbytes = snprintf(msgString, BUFSIZ, "ERROR ");
53  break;
54  }
56  nbytes = snprintf(msgString, BUFSIZ, "WARNING ");
57  break;
58  }
59  }
60  const std::string& actualMsg = message.getMessage();
61  nbytes = snprintf(msgString + nbytes, BUFSIZ - nbytes, "%d : %s", inId, actualMsg.c_str());
62  if(nbytes >= BUFSIZ) {
63  return std::string();
64  }
65  return msgString;
66 }
MessageContainer mMessages
std::string string

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MessageTable * torc::generic::MessageTable::instance ( )
static

Get a pointer to the singleton MessageTable object.

Definition at line 94 of file MessageTable.cpp.

94  {
95  static MessageTable singletonObject;
96  return &singletonObject;
97 }

+ Here is the caller graph for this function:

void torc::generic::MessageTable::operator delete ( void *  )
private
MessageTable& torc::generic::MessageTable::operator= ( const MessageTable source)
private

Field Documentation

MessageContainer torc::generic::MessageTable::mMessages
private

Definition at line 84 of file MessageTable.hpp.


The documentation for this class was generated from the following files: