Browse Source

[trac558] Return reference to the global dictionary, not a pointer

Stephen Morris 14 years ago
parent
commit
3cddfb8bd9

+ 2 - 2
src/lib/log/compiler/message.cc

@@ -513,10 +513,10 @@ main(int argc, char** argv) {
     }
     catch (MessageException& e) {
         // Create an error message from the ID and the text
-        MessageDictionary* global = MessageDictionary::globalDictionary();
+        MessageDictionary& global = MessageDictionary::globalDictionary();
         string text = e.id();
         text += ", ";
-        text += global->getText(e.id());
+        text += global.getText(e.id());
 
         // Format with arguments
         text = isc::strutil::format(text, e.arguments());

+ 2 - 2
src/lib/log/logger.cc

@@ -116,8 +116,8 @@ const size_t MESSAGE_SIZE = 512;
 
 #define FORMAT_MESSAGE(message) \
     { \
-    MessageDictionary* global = MessageDictionary::globalDictionary(); \
-    string format = global->getText(ident); \
+    MessageDictionary& global = MessageDictionary::globalDictionary(); \
+    string format = global.getText(ident); \
     va_list ap; \
     va_start(ap, ident); \
     vsnprintf(message, sizeof(message), format.c_str(), ap); \

+ 2 - 2
src/lib/log/logger_support.cc

@@ -55,8 +55,8 @@ Logger logger("log");
 static void
 readLocalMessageFile(const char* file) {
     
-    MessageDictionary* dictionary = MessageDictionary::globalDictionary();
-    MessageReader reader(dictionary);
+    MessageDictionary& dictionary = MessageDictionary::globalDictionary();
+    MessageReader reader(&dictionary);
     try {
         reader.readFile(file, MessageReader::REPLACE);
 

+ 2 - 2
src/lib/log/message_dictionary.cc

@@ -99,10 +99,10 @@ MessageDictionary::getText(const string& ident) const {
 
 // Return global dictionary
 
-MessageDictionary*
+MessageDictionary&
 MessageDictionary::globalDictionary() {
     static MessageDictionary global;
-    return (&global);
+    return (global);
 }
 
 

+ 1 - 1
src/lib/log/message_dictionary.h

@@ -178,7 +178,7 @@ public:
     /// Returns a pointer to the singleton global dictionary.
     ///
     /// \return Pointer to global dictionary.
-    static MessageDictionary* globalDictionary();
+    static MessageDictionary& globalDictionary();
 
 private:
     Dictionary       dictionary_;   ///< Holds the ID to text lookups

+ 2 - 2
src/lib/log/message_initializer.cc

@@ -22,8 +22,8 @@ namespace log {
 // associated text into it.
 
 MessageInitializer::MessageInitializer(const char* values[]) {
-    MessageDictionary* global = MessageDictionary::globalDictionary();
-    global->load(values);
+    MessageDictionary& global = MessageDictionary::globalDictionary();
+    global.load(values);
 }
 
 } // namespace log

+ 3 - 5
src/lib/log/tests/message_dictionary_unittest.cc

@@ -44,11 +44,9 @@ protected:
 // Check that the global dictionary is a singleton.
 
 TEST_F(MessageDictionaryTest, GlobalTest) {
-    MessageDictionary* global = MessageDictionary::globalDictionary();
-    EXPECT_FALSE(NULL == global);
-
-    MessageDictionary* global2 = MessageDictionary::globalDictionary();
-    EXPECT_EQ(global2, global);
+    MessageDictionary& global = MessageDictionary::globalDictionary();
+    MessageDictionary& global2 = MessageDictionary::globalDictionary();
+    EXPECT_TRUE(&global2 == &global);
 }
 
 // Check that adding messages works

+ 7 - 7
src/lib/log/tests/message_initializer_unittest.cc

@@ -59,12 +59,12 @@ protected:
 // messages.
 
 TEST_F(MessageInitializerTest, MessageTest) {
-    MessageDictionary* global = MessageDictionary::globalDictionary();
+    MessageDictionary& global = MessageDictionary::globalDictionary();
 
-    EXPECT_EQ(string("global message one"), global->getText("GLOBAL1"));
-    EXPECT_EQ(string("global message two"), global->getText("GLOBAL2"));
-    EXPECT_EQ(string("global message three"), global->getText("GLOBAL3"));
-    EXPECT_EQ(string("global message four"), global->getText("GLOBAL4"));
-    EXPECT_EQ(string("global message five"), global->getText("GLOBAL5"));
-    EXPECT_EQ(string("global message six"), global->getText("GLOBAL6"));
+    EXPECT_EQ(string("global message one"), global.getText("GLOBAL1"));
+    EXPECT_EQ(string("global message two"), global.getText("GLOBAL2"));
+    EXPECT_EQ(string("global message three"), global.getText("GLOBAL3"));
+    EXPECT_EQ(string("global message four"), global.getText("GLOBAL4"));
+    EXPECT_EQ(string("global message five"), global.getText("GLOBAL5"));
+    EXPECT_EQ(string("global message six"), global.getText("GLOBAL6"));
 }