Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9536 for code/branches


Ignore:
Timestamp:
Mar 4, 2013, 10:47:26 PM (12 years ago)
Author:
landauf
Message:

small refactoring: un-singletonized ConsoleWriter, LogWriter, and MemoryWriter - instead the instances are now kept by OutputManager

Location:
code/branches/testing/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • code/branches/testing/src/libraries/core/Core.cc

    r9224 r9536  
    5555#include "util/Exception.h"
    5656#include "util/output/LogWriter.h"
     57#include "util/output/OutputManager.h"
    5758#include "util/Scope.h"
    5859#include "util/ScopedSingletonManager.h"
     
    180181
    181182        // Set the correct log path and rewrite the log file with the correct log levels
    182         LogWriter::getInstance().setLogPath(PathConfig::getLogPathString());
     183        OutputManager::getInstance().getLogWriter().setLogPath(PathConfig::getLogPathString());
    183184
    184185#if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN)
     
    258259    void Core::setConfigValues()
    259260    {
    260         SetConfigValueExternal(LogWriter::getInstance().configurableMaxLevel_,
    261                                LogWriter::getInstance().getConfigurableSectionName(),
    262                                LogWriter::getInstance().getConfigurableMaxLevelName(),
    263                                LogWriter::getInstance().configurableMaxLevel_)
     261        SetConfigValueExternal(OutputManager::getInstance().getLogWriter().configurableMaxLevel_,
     262                               OutputManager::getInstance().getLogWriter().getConfigurableSectionName(),
     263                               OutputManager::getInstance().getLogWriter().getConfigurableMaxLevelName(),
     264                               OutputManager::getInstance().getLogWriter().configurableMaxLevel_)
    264265            .description("The maximum level of output shown in the log file")
    265             .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableLevel);
    266         SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContextsMaxLevel_,
    267                                LogWriter::getInstance().getConfigurableSectionName(),
    268                                LogWriter::getInstance().getConfigurableAdditionalContextsMaxLevelName(),
    269                                LogWriter::getInstance().configurableAdditionalContextsMaxLevel_)
     266            .callback(static_cast<BaseWriter*>(&OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableLevel);
     267        SetConfigValueExternal(OutputManager::getInstance().getLogWriter().configurableAdditionalContextsMaxLevel_,
     268                               OutputManager::getInstance().getLogWriter().getConfigurableSectionName(),
     269                               OutputManager::getInstance().getLogWriter().getConfigurableAdditionalContextsMaxLevelName(),
     270                               OutputManager::getInstance().getLogWriter().configurableAdditionalContextsMaxLevel_)
    270271            .description("The maximum level of output shown in the log file for additional contexts")
    271             .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
    272         SetConfigValueExternal(LogWriter::getInstance().configurableAdditionalContexts_,
    273                                LogWriter::getInstance().getConfigurableSectionName(),
    274                                LogWriter::getInstance().getConfigurableAdditionalContextsName(),
    275                                LogWriter::getInstance().configurableAdditionalContexts_)
     272            .callback(static_cast<BaseWriter*>(&OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContextsLevel);
     273        SetConfigValueExternal(OutputManager::getInstance().getLogWriter().configurableAdditionalContexts_,
     274                               OutputManager::getInstance().getLogWriter().getConfigurableSectionName(),
     275                               OutputManager::getInstance().getLogWriter().getConfigurableAdditionalContextsName(),
     276                               OutputManager::getInstance().getLogWriter().configurableAdditionalContexts_)
    276277            .description("Additional output contexts shown in the log file")
    277             .callback(static_cast<BaseWriter*>(&LogWriter::getInstance()), &BaseWriter::changedConfigurableAdditionalContexts);
     278            .callback(static_cast<BaseWriter*>(&OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);
    278279
    279280        SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
  • code/branches/testing/src/libraries/core/command/IOConsolePOSIX.cc

    r8858 r9536  
    3838#include "util/Math.h"
    3939#include "util/output/ConsoleWriter.h"
     40#include "util/output/OutputManager.h"
    4041#include "core/Game.h"
    4142#include "core/input/InputBuffer.h"
     
    7576
    7677        // Disable standard std::cout logging
    77         ConsoleWriter::getInstance().disable();
     78        OutputManager::getInstance().getConsoleWriter().disable();
    7879        // Redirect std::cout to an ostringstream
    7980        // (Other part is in the initialiser list)
     
    103104        std::cout.rdbuf(this->cout_.rdbuf());
    104105        // Enable standard std::cout logging again
    105         ConsoleWriter::getInstance().enable();
     106        OutputManager::getInstance().getConsoleWriter().enable();
    106107    }
    107108
  • code/branches/testing/src/libraries/core/command/IOConsoleWindows.cc

    r8858 r9536  
    3535#include "util/Math.h"
    3636#include "util/output/ConsoleWriter.h"
     37#include "util/output/OutputManager.h"
    3738#include "core/Game.h"
    3839#include "core/input/InputBuffer.h"
     
    5354    {
    5455        // Disable standard this->cout_ logging
    55         ConsoleWriter::getInstance().disable();
     56        OutputManager::getInstance().getConsoleWriter().disable();
    5657        // Redirect std::cout to an ostringstream
    5758        // (Other part is in the initialiser list)
     
    109110        std::cout.rdbuf(this->cout_.rdbuf());
    110111        // Enable standard this->cout_ logging again
    111         ConsoleWriter::getInstance().enable();
     112        OutputManager::getInstance().getConsoleWriter().enable();
    112113
    113114        resetTerminalMode();
  • code/branches/testing/src/libraries/core/command/Shell.cc

    r9225 r9536  
    8888
    8989        // Get the previous output and add it to the Shell
    90         MemoryWriter::getInstance().resendOutput(this);
     90        OutputManager::getInstance().getMemoryWriter().resendOutput(this);
    9191    }
    9292
  • code/branches/testing/src/libraries/util/UtilPrereqs.h

    r9533 r9536  
    8585{
    8686    class AdditionalContextListener;
     87    class BaseWriter;
    8788    class Clock;
     89    class ConsoleWriter;
    8890    class Exception;
    8991    class ExprParser;
     92    class LogWriter;
     93    class MemoryWriter;
    9094    class MultiType;
    9195    class OutputListener;
     
    102106    template <class T>
    103107    class Singleton;
     108    class SubcontextOutputListener;
    104109    class SubString;
    105110}
  • code/branches/testing/src/libraries/util/output/ConsoleWriter.cc

    r9531 r9536  
    6666
    6767    /**
    68         @brief Returns the only existing instance of this class.
    69     */
    70     /*static*/ ConsoleWriter& ConsoleWriter::getInstance()
    71     {
    72         static ConsoleWriter instance;
    73         return instance;
    74     }
    75 
    76     /**
    7768        @brief Inherited function from BaseWriter, writes output to the console using std::cout.
    7869    */
  • code/branches/testing/src/libraries/util/output/ConsoleWriter.h

    r9535 r9536  
    5454            virtual ~ConsoleWriter();
    5555
    56             static ConsoleWriter& getInstance();
    57 
    5856            void enable();
    5957            void disable();
  • code/branches/testing/src/libraries/util/output/LogWriter.cc

    r8858 r9536  
    7676
    7777    /**
    78         @brief Returns the only existing instance of this class.
    79     */
    80     /*static*/ LogWriter& LogWriter::getInstance()
    81     {
    82         static LogWriter instance;
    83         return instance;
    84     }
    85 
    86     /**
    8778        @brief Opens the log-file in order to write output to it.
    8879    */
     
    133124
    134125        // request old output from MemoryWriter
    135         MemoryWriter::getInstance().resendOutput(this);
     126        OutputManager::getInstance().getMemoryWriter().resendOutput(this);
    136127    }
    137128
  • code/branches/testing/src/libraries/util/output/LogWriter.h

    r9535 r9536  
    6161            virtual ~LogWriter();
    6262
    63             static LogWriter& getInstance();
    64 
    6563            void setLogPath(const std::string& path);
    6664
  • code/branches/testing/src/libraries/util/output/MemoryWriter.cc

    r8858 r9536  
    5353
    5454    /**
    55         @brief Returns the only existing instance of this singleton class.
    56     */
    57     /*static*/ MemoryWriter& MemoryWriter::getInstance()
    58     {
    59         static MemoryWriter instance;
    60         return instance;
    61     }
    62 
    63     /**
    6455        @brief Implementation of the output() function inherited from OutputListener, stores the received output in memory.
    6556    */
  • code/branches/testing/src/libraries/util/output/MemoryWriter.h

    r9535 r9536  
    7171            virtual ~MemoryWriter();
    7272
    73             static MemoryWriter& getInstance();
    74 
    7573            void resendOutput(OutputListener* listener) const;
    7674            void disable();
  • code/branches/testing/src/libraries/util/output/OutputManager.cc

    r9533 r9536  
    8888        static OutputManager& instance = OutputManager::getInstance();
    8989
    90         static MemoryWriter& memoryWriterInstance = MemoryWriter::getInstance(); (void)memoryWriterInstance;
    91         static ConsoleWriter& consoleWriterInstance = ConsoleWriter::getInstance(); (void)consoleWriterInstance;
    92         static LogWriter& logWriterInstance = LogWriter::getInstance(); (void)logWriterInstance;
    93 
     90        static MemoryWriter& memoryWriterInstance = OutputManager::getInstance().getMemoryWriter(); (void)memoryWriterInstance;
     91        static ConsoleWriter& consoleWriterInstance = OutputManager::getInstance().getConsoleWriter(); (void)consoleWriterInstance;
     92        static LogWriter& logWriterInstance = OutputManager::getInstance().getLogWriter(); (void)logWriterInstance;
     93
     94        return instance;
     95    }
     96
     97    /**
     98     * @brief Returns the main instance of MemoryWriter which is managed by the OutputManager singleton.
     99     * @note If OutputManager is ever un-singletonized, this instance must not remain static.
     100     */
     101    MemoryWriter& OutputManager::getMemoryWriter()
     102    {
     103        static MemoryWriter instance;
     104        return instance;
     105    }
     106
     107    /**
     108     * @brief Returns the main instance of ConsoleWriter which is managed by the OutputManager singleton.
     109     * @note If OutputManager is ever un-singletonized, this instance must not remain static.
     110     */
     111    ConsoleWriter& OutputManager::getConsoleWriter()
     112    {
     113        static ConsoleWriter instance;
     114        return instance;
     115    }
     116
     117    /**
     118     * @brief Returns the main instance of LogWriter which is managed by the OutputManager singleton.
     119     * @note If OutputManager is ever un-singletonized, this instance must not remain static.
     120     */
     121    LogWriter& OutputManager::getLogWriter()
     122    {
     123        static LogWriter instance;
    94124        return instance;
    95125    }
  • code/branches/testing/src/libraries/util/output/OutputManager.h

    r9535 r9536  
    7272            static OutputManager& getInstanceAndCreateListeners();
    7373
     74            MemoryWriter& getMemoryWriter();
     75            ConsoleWriter& getConsoleWriter();
     76            LogWriter& getLogWriter();
     77
    7478            void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message);
    7579
  • code/branches/testing/src/orxonox/overlays/InGameConsole.cc

    r8858 r9536  
    4747#include "util/ScopedSingletonManager.h"
    4848#include "util/output/MemoryWriter.h"
     49#include "util/output/OutputManager.h"
    4950#include "core/CoreIncludes.h"
    5051#include "core/ConfigValueIncludes.h"
     
    9596        // Output buffering is not anymore needed. Not the best solution to do
    9697        // this here, but there isn't much of another way.
    97         MemoryWriter::getInstance().disable();
     98        OutputManager::getInstance().getMemoryWriter().disable();
    9899    }
    99100
Note: See TracChangeset for help on using the changeset viewer.