Kea: isc::log::MessageDictionary Class Reference

| Kea 3.2.0-git

isc::log::MessageDictionary Class Reference

Message Dictionary. More...

`#include <message_dictionary.h>`

## Public Types
typedef Dictionary::const_iterator | const_iterator
typedef std::map< std::string, std::string > | Dictionary

## Public Member Functions
| MessageDictionary ()
| Constructor.
virtual | ~MessageDictionary ()
| Virtual Destructor.
virtual bool | add (const MessageID &ident, const std::string &text)
| Add Message.
virtual bool | add (const std::string &ident, const std::string &text)
| Add Message.
const_iterator | begin () const
| Return begin() iterator of internal map.
const_iterator | end () const
| Return end() iterator of internal map.
virtual bool | erase (const std::string &ident, const std::string &text)
| Removes the specified message from the dictionary.
virtual const std::string & | getText (const MessageID &ident) const
| Get Message Text.
virtual const std::string & | getText (const std::string &ident) const
| Get Message Text.
virtual std::vector< std::string > | load (const char *elements[])
| Load Dictionary.
virtual bool | replace (const MessageID &ident, const std::string &text)
| Replace Message.
virtual bool | replace (const std::string &ident, const std::string &text)
| Replace Message.
virtual size_t | size () const
| Number of Items in Dictionary.

## Static Public Member Functions
static const MessageDictionaryPtr & | globalDictionary ()
| Return Global Dictionary.

## Detailed Description

Message Dictionary.

The message dictionary is a wrapper around a std::map object, and allows message text to be retrieved given the string identification.

Adding text occurs in two modes:

Through the "Add" method, ID/text mappings are added to the dictionary unless the ID already exists. This is designed for use during program initialization, where a local message may supplant a compiled-in message.

Through the "Replace" method, ID/text mappings are added to the dictionary only if the ID already exists. This is for use when a message file is supplied to replace messages provided with the program.

Although the class can be used stand-alone, it does supply a static method to return a particular instance - the "global" dictionary.

Definition at line 47 of file message_dictionary.h.

## Member Typedef Documentation

## ◆ const_iterator

typedef Dictionary::const_iterator isc::log::MessageDictionary::const_iterator

Definition at line 51 of file message_dictionary.h.

## ◆ Dictionary

typedef std::map<std::string, std::string> isc::log::MessageDictionary::Dictionary

Definition at line 50 of file message_dictionary.h.

## Constructor & Destructor Documentation

## ◆ MessageDictionary()

isc::log::MessageDictionary::MessageDictionary | ( |  | ) |

Constructor.

Definition at line 20 of file message_dictionary.cc.

Referenced by globalDictionary().

## ◆ ~MessageDictionary()

isc::log::MessageDictionary::~MessageDictionary | ( |  | ) |
| virtual

Virtual Destructor.

Definition at line 25 of file message_dictionary.cc.

## Member Function Documentation

## ◆ add() [1/2]

virtual bool isc::log::MessageDictionary::add | ( | const MessageID & | ident,
|  | const std::string & | text )
| inlinevirtual

Add Message.

Adds a message to the dictionary. If the ID already exists, the ID is added to the overflow vector.

Parameters

  ident | Identification of the message to add
  text | Message text

Returns
  true if the message was added to the dictionary, false if the message existed and it was not added.

Definition at line 69 of file message_dictionary.h.

References add().

Referenced by add(), and load().

Here is the call graph for this function:

## ◆ add() [2/2]

bool isc::log::MessageDictionary::add | ( | const std::string & | ident,
|  | const std::string & | text )
| virtual

Add Message.

Alternate signature.

Parameters

  ident | Identification of the message to add
  text | Message text

Returns
  true if the message was added to the dictionary, false if the message existed and it was not added.

Definition at line 31 of file message_dictionary.cc.

## ◆ begin()

const_iterator isc::log::MessageDictionary::begin | ( |  | ) | const
| inline

Return begin() iterator of internal map.

Definition at line 182 of file message_dictionary.h.

## ◆ end()

const_iterator isc::log::MessageDictionary::end | ( |  | ) | const
| inline

Return end() iterator of internal map.

Definition at line 188 of file message_dictionary.h.

## ◆ erase()

bool isc::log::MessageDictionary::erase | ( | const std::string & | ident,
|  | const std::string & | text )
| virtual

Removes the specified message from the dictionary.

Checks if both the message identifier and the text match the message in the dictionary before removal. If the text doesn't match it is an indication that the message which removal is requested is a duplicate of another message. This may occur when two Kea modules register messages with the same identifier. When one of the modules is unloaded and the relevant messages are unregistered, there is a need to make sure that the message registered by the other module is not accidentally removed. Hence, the additional check for the text match is needed.

Parameters

  ident | Identification of the message to remove.
  text | Message text

Returns
  true of the message has been removed, false if the message couldn't be found.

Definition at line 59 of file message_dictionary.cc.

## ◆ getText() [1/2]

virtual const std::string & isc::log::MessageDictionary::getText | ( | const MessageID & | ident | ) | const
| inlinevirtual

Get Message Text.

Given an ID, retrieve associated message text.

Parameters

  ident | Message identification

Returns
  Text associated with message or empty string if the ID is not recognized. (Note: this precludes an ID being associated with an empty string.)

Definition at line 156 of file message_dictionary.h.

References getText().

Referenced by getText(), and writeProgramFile().

Here is the call graph for this function:

## ◆ getText() [2/2]

const string & isc::log::MessageDictionary::getText | ( | const std::string & | ident | ) | const
| virtual

Get Message Text.

Alternate signature.

Parameters

  ident | Message identification

Returns
  Text associated with message or empty string if the ID is not recognized. (Note: this precludes an ID being associated with an empty string.)

Definition at line 100 of file message_dictionary.cc.

## ◆ globalDictionary()

const MessageDictionaryPtr & isc::log::MessageDictionary::globalDictionary | ( |  | ) |
| static

Return Global Dictionary.

Returns a pointer to the singleton global dictionary.

Returns
  Pointer to global dictionary.

Definition at line 112 of file message_dictionary.cc.

References MessageDictionary().

Referenced by isc::log::MessageInitializer::loadDictionary(), isc::log::LoggerImpl::lookupMessage(), main(), and isc::log::LoggerManager::readLocalMessageFile().

Here is the call graph for this function:

## ◆ load()

vector< std::string > isc::log::MessageDictionary::load | ( | const char * | elements[] | ) |
| virtual

Load Dictionary.

Designed to be used during the initialization of programs, this accepts a set of (ID, text) pairs as a one-dimensional array of const char* and adds them to the dictionary. The messages are added using "Add".

Parameters

  elements | null-terminated array of const char* alternating ID and message text. This should be an odd number of elements long, the last element being NULL. If it is an even number of elements long, the last ID is ignored.

Returns
  Vector of message IDs that were not loaded because an ID of the same name already existing in the dictionary. This vector may be empty.

Definition at line 72 of file message_dictionary.cc.

References add().

Here is the call graph for this function:

## ◆ replace() [1/2]

virtual bool isc::log::MessageDictionary::replace | ( | const MessageID & | ident,
|  | const std::string & | text )
| inlinevirtual

Replace Message.

Replaces a message in the dictionary. If the ID does not exist, it is added to the overflow vector.

Parameters

  ident | Identification of the message to replace
  text | Message text

Returns
  true if the message was added to the dictionary, false if the message did not exist and it was not added.

Definition at line 95 of file message_dictionary.h.

References replace().

Referenced by replace().

Here is the call graph for this function:

## ◆ replace() [2/2]

bool isc::log::MessageDictionary::replace | ( | const std::string & | ident,
|  | const std::string & | text )
| virtual

Replace Message.

Alternate signature.

Parameters

  ident | Identification of the message to replace
  text | Message text

Returns
  true if the message was added to the dictionary, false if the message did not exist and it was not added.

Definition at line 46 of file message_dictionary.cc.

## ◆ size()

virtual size_t isc::log::MessageDictionary::size | ( |  | ) | const
| inlinevirtual

Number of Items in Dictionary.

Returns
  Number of items in the dictionary

Definition at line 176 of file message_dictionary.h.

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

- message_dictionary.h
- message_dictionary.cc