Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.