Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8515


Ignore:
Timestamp:
May 20, 2011, 3:53:21 AM (13 years ago)
Author:
rgrieder
Message:

The output listener writing to the memory as buffer should record input of ALL levels, but instead be deactivated when not needed anymore.

Location:
code/branches/unity_build/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/unity_build/src/libraries/core/command/Shell.cc

    r8079 r8515  
    8484
    8585        // Get the previous output and add it to the Shell
    86         for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();
    87             it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)
     86        OutputHandler::OutputVector::const_iterator it = OutputHandler::getInstance().getOutput().begin();
     87        for (;it != OutputHandler::getInstance().getOutput().end(); ++it)
    8888        {
    8989            if (it->first <= this->getSoftDebugLevel())
  • code/branches/unity_build/src/libraries/util/OutputHandler.cc

    r7401 r8515  
    147147        OutputListener that writes all the output piece by piece to an array
    148148        associated with the corresponding output level.
     149        Used as buffer until all output devices have been initialised.
    149150    @note
    150         Only output below or equal to the current soft debug level is written
    151         to minimise huge arrays for the normal run.
     151        At some point, OutputHandler::disableMemoryLog() has to be called in
     152        order to avoid large memory footprints of this class.
    152153    */
    153154    class MemoryLogWriter : public OutputListener
     
    156157        friend class OutputHandler;
    157158
    158         /**
    159         @brief
    160             Sets the right soft debug level and registers itself
    161         */
    162159        MemoryLogWriter()
    163160            : OutputListener("memoryLog")
     
    166163        }
    167164
    168         //! Pushed the just written output to the internal array
     165        //! Push the just written output to the internal array
    169166        void outputChanged(int level)
    170167        {
     
    180177
    181178    private:
    182         std::ostringstream                        buffer_; //!< Stream object used to process the output
    183         std::vector<std::pair<int, std::string> > output_; //!< Vector containing ALL output
     179        std::ostringstream          buffer_; //!< Stream object used to process the output
     180        OutputHandler::OutputVector output_; //!< Vector containing ALL output
    184181    };
    185182
     
    212209        this->registerOutputListener(this->consoleWriter_);
    213210
    214         this->output_ = new MemoryLogWriter();
    215         // We capture as much input as the listener with the highest level
    216         this->output_->softDebugLevel_ = getSoftDebugLevel();
    217         this->registerOutputListener(this->output_);
     211        this->memoryBuffer_ = new MemoryLogWriter();
     212        // Write everything, e.g. use hardDebugLevel
     213        this->memoryBuffer_->softDebugLevel_ = hardDebugLevel;
     214        this->registerOutputListener(this->memoryBuffer_);
    218215    }
    219216
     
    223220        delete this->logFile_;
    224221        delete this->consoleWriter_;
    225         delete this->output_;
     222        delete this->memoryBuffer_; // Might already be NULL
    226223    }
    227224
     
    267264    }
    268265
    269     OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorBegin() const
    270     {
    271         return this->output_->output_.begin();
    272     }
    273 
    274     OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorEnd() const
    275     {
    276         return this->output_->output_.end();
     266    void OutputHandler::disableMemoryLog()
     267    {
     268        this->unregisterOutputListener(this->memoryBuffer_);
     269        // Only clear the buffer so we can still reference the vector
     270        this->memoryBuffer_->output_.clear();
     271    }
     272
     273    const OutputHandler::OutputVector& OutputHandler::getOutput() const
     274    {
     275        return this->memoryBuffer_->output_;
    277276    }
    278277
  • code/branches/unity_build/src/libraries/util/OutputHandler.h

    r7401 r8515  
    103103                { return OutputHandler::getInstance().setOutputLevel(level); }
    104104
    105             typedef std::vector<std::pair<int, std::string> >::const_iterator OutputVectorIterator;
    106             //! Returns an iterator to the beginning of the all-output vector
    107             OutputVectorIterator getOutputVectorBegin() const;
    108             //! Returns an iterator to the end of the all-output vector
    109             OutputVectorIterator getOutputVectorEnd() const;
     105            typedef std::vector<std::pair<int, std::string> > OutputVector;
     106            //! Returns all output written so far (empty if disableMemoryLog() was called)
     107            const OutputVector& getOutput() const;
    110108
    111109            //! Writes to all output devices
     
    140138            //! Enables the std::cout stream for output (startup behaviour)
    141139            void enableCout();
     140            //! Stop writing to the memory buffer (call this as soon as possible to minimise memory usage)
     141            void disableMemoryLog();
    142142
    143143            //! Sets the level of the incoming output and returns the OutputHandler
     
    225225            LogFileWriter*             logFile_;          //!< Listener that writes to the log file
    226226            ConsoleWriter*             consoleWriter_;    //!< Listener for std::cout (just program beginning)
    227             MemoryLogWriter*           output_;           //!< Listener that Stores ALL output below the current soft debug level
     227            MemoryLogWriter*           memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
    228228            static int                 softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
    229229    };
  • code/branches/unity_build/src/orxonox/overlays/InGameConsole.cc

    r8079 r8515  
    9191        this->setConfigValues();
    9292        this->initialise();
     93
     94        // Output buffering is not anymore needed. Not the best solution to do
     95        // this here, but there isn't much of another way.
     96        OutputHandler::getInstance().disableMemoryLog();
    9397    }
    9498
Note: See TracChangeset for help on using the changeset viewer.