Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 10, 2013, 11:29:44 AM (12 years ago)
Author:
landauf
Message:

some refactoring in OutputManager - for unittests it is sometimes necessary to create a new instance of OutputManager (or a mock), hence we should avoid storing dead references

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/testing/src/libraries/util/output/OutputManager.cc

    r9539 r9540  
    5555
    5656        this->subcontextCounter_ = 0;
     57
     58        this->isInitialized_ = false;
     59        this->memoryWriterInstance_ = 0;
     60        this->consoleWriterInstance_ = 0;
     61        this->logWriterInstance_ = 0;
    5762    }
    5863
     
    6267    OutputManager::~OutputManager()
    6368    {
     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_;
    6478    }
    6579
     
    88102    /*static*/ OutputManager& OutputManager::getInstanceAndCreateListeners()
    89103    {
    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
    126113        return instance;
    127114    }
Note: See TracChangeset for help on using the changeset viewer.