Changeset 9540 for code/branches
- Timestamp:
- Mar 10, 2013, 11:29:44 AM (12 years ago)
- Location:
- code/branches/testing
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/output/LogWriter.cc
r9538 r9540 118 118 119 119 // request old output from MemoryWriter 120 OutputManager::getInstance().getMemoryWriter().resendOutput(this); 120 if (&OutputManager::getInstance().getMemoryWriter()) 121 OutputManager::getInstance().getMemoryWriter().resendOutput(this); 121 122 } 122 123 -
code/branches/testing/src/libraries/util/output/OutputDefinitions.h
r9535 r9540 48 48 */ 49 49 #define REGISTER_OUTPUT_CONTEXT(name) \ 50 const OutputContextContainer& name() { static const OutputContextContainer&context = registerContext(#name); return context; }50 const OutputContextContainer& name() { static OutputContextContainer context = registerContext(#name); return context; } 51 51 52 52 /** -
code/branches/testing/src/libraries/util/output/OutputManager.cc
r9539 r9540 55 55 56 56 this->subcontextCounter_ = 0; 57 58 this->isInitialized_ = false; 59 this->memoryWriterInstance_ = 0; 60 this->consoleWriterInstance_ = 0; 61 this->logWriterInstance_ = 0; 57 62 } 58 63 … … 62 67 OutputManager::~OutputManager() 63 68 { 69 while (!this->listeners_.empty()) 70 this->unregisterListener(this->listeners_[0]); 71 72 if (this->memoryWriterInstance_) 73 delete this->memoryWriterInstance_; 74 if (this->consoleWriterInstance_) 75 delete this->consoleWriterInstance_; 76 if (this->logWriterInstance_) 77 delete this->logWriterInstance_; 64 78 } 65 79 … … 88 102 /*static*/ OutputManager& OutputManager::getInstanceAndCreateListeners() 89 103 { 90 static OutputManager& instance = OutputManager::getInstance(); 91 92 static MemoryWriter& memoryWriterInstance = OutputManager::getInstance().getMemoryWriter(); (void)memoryWriterInstance; 93 static ConsoleWriter& consoleWriterInstance = OutputManager::getInstance().getConsoleWriter(); (void)consoleWriterInstance; 94 static LogWriter& logWriterInstance = OutputManager::getInstance().getLogWriter(); (void)logWriterInstance; 95 96 return instance; 97 } 98 99 /** 100 * @brief Returns the main instance of MemoryWriter which is managed by the OutputManager singleton. 101 * @note If OutputManager is ever un-singletonized, this instance must not remain static. 102 */ 103 MemoryWriter& OutputManager::getMemoryWriter() 104 { 105 static MemoryWriter instance; 106 return instance; 107 } 108 109 /** 110 * @brief Returns the main instance of ConsoleWriter which is managed by the OutputManager singleton. 111 * @note If OutputManager is ever un-singletonized, this instance must not remain static. 112 */ 113 ConsoleWriter& OutputManager::getConsoleWriter() 114 { 115 static ConsoleWriter instance(std::cout); 116 return instance; 117 } 118 119 /** 120 * @brief Returns the main instance of LogWriter which is managed by the OutputManager singleton. 121 * @note If OutputManager is ever un-singletonized, this instance must not remain static. 122 */ 123 LogWriter& OutputManager::getLogWriter() 124 { 125 static LogWriter instance; 104 OutputManager& instance = *OutputManager::Testing::getInstancePointer(); 105 106 if (!instance.isInitialized_) { 107 instance.isInitialized_ = true; 108 instance.memoryWriterInstance_ = new MemoryWriter(); 109 instance.consoleWriterInstance_ = new ConsoleWriter(std::cout); 110 instance.logWriterInstance_ = new LogWriter(); 111 } 112 126 113 return instance; 127 114 } -
code/branches/testing/src/libraries/util/output/OutputManager.h
r9536 r9540 72 72 static OutputManager& getInstanceAndCreateListeners(); 73 73 74 MemoryWriter& getMemoryWriter();75 ConsoleWriter& getConsoleWriter();76 LogWriter& getLogWriter();74 inline MemoryWriter& getMemoryWriter() { return *this->memoryWriterInstance_; } 75 inline ConsoleWriter& getConsoleWriter() { return *this->consoleWriterInstance_; } 76 inline LogWriter& getLogWriter() { return *this->logWriterInstance_; } 77 77 78 v oid pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message);78 virtual void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message); 79 79 80 80 virtual void registerListener(OutputListener* listener); … … 125 125 OutputContextSubID subcontextCounter_; ///< Counts the number of sub-contexts (and generates their IDs) 126 126 127 bool isInitialized_; ///< Becomes true once the following instances were created 128 MemoryWriter* memoryWriterInstance_; ///< The main instance of MemoryWriter, managed by OutputManager 129 ConsoleWriter* consoleWriterInstance_; ///< The main instance of ConsoleWriter, managed by OutputManager 130 LogWriter* logWriterInstance_; ///< The main instance of LogWriter, managed by OutputManager 131 127 132 public: 128 133 struct _UtilExport Testing -
code/branches/testing/test/util/output/ConsoleWriterTest.cc
r9538 r9540 65 65 TEST(ConsoleWriterTest, DefaultConsoleWriterUsesCout) 66 66 { 67 OutputManager::getInstanceAndCreateListeners(); 67 68 EXPECT_EQ(std::cout, OutputManager::getInstance().getConsoleWriter().getOutputStream()); 68 69 }
Note: See TracChangeset
for help on using the changeset viewer.