Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 10, 2008, 3:35:50 PM (16 years ago)
Author:
landauf
Message:

moved Debug.h, OutputHandler and OutputBuffer to util, to make COUT(x) available everywhere

Location:
code/branches/core3/src/util
Files:
4 edited
5 moved

Legend:

Unmodified
Added
Removed
  • code/branches/core3/src/util/CMakeLists.txt

    r1505 r1586  
    77  MultiTypeString.cc
    88  MultiTypeMath.cc
     9  OutputBuffer.cc
     10  OutputHandler.cc
    911  String.cc
    1012  SubString.cc
  • code/branches/core3/src/util/Convert.h

    r1505 r1586  
    4141
    4242#include "Math.h"
     43#include "Debug.h"
    4344#include "SubString.h"
    4445#include "MultiTypeMath.h"
     
    7475    enum { specialized = false };
    7576    static bool convert(ToType* output, const FromType& input)
    76     { return false; }
     77    {
     78        COUT(2) << "Warning: Couldn't convert a value." << std::endl;
     79        return false;
     80    }
    7781};
    7882
     
    139143    static bool convert(ToType* output, const FromType& input)
    140144    {
     145        COUT(2) << "Warning: Couldn't convert a value." << std::endl;
    141146        return false;
    142147    }
  • code/branches/core3/src/util/Debug.h

    r1585 r1586  
    3737#define _Debug_H__
    3838
    39 #include "CorePrereqs.h"
     39#include "UtilPrereqs.h"
    4040
    4141#include <stdio.h>
     
    4343#include "OutputHandler.h"
    4444
    45 extern "C" _CoreExport int getSoftDebugLevel();
     45
     46/**
     47    @brief Returns the soft debug level, stored in the only existing instance of the OutputHandler class, configured in the config-file.
     48    @return The soft debug level
     49*/
     50static inline int getSoftDebugLevel()
     51{
     52    return orxonox::OutputHandler::getSoftDebugLevel();
     53}
     54
    4655
    4756// DEFINE ERROR MODES
  • code/branches/core3/src/util/OutputBuffer.h

    r1574 r1586  
    3434#include <iostream>
    3535
    36 #include "CorePrereqs.h"
     36#include "UtilPrereqs.h"
    3737
    3838namespace orxonox
    3939{
    40     class _CoreExport OutputBufferListener
     40    class _UtilExport OutputBufferListener
    4141    {
    4242        friend class OutputBuffer;
     
    4949    };
    5050
    51     class _CoreExport OutputBuffer
     51    class _UtilExport OutputBuffer
    5252    {
    5353        public:
     
    5959            {
    6060                this->stream_ << object;
     61                this->callListeners();
     62                return *this;
     63            }
     64
     65            template <const OutputBuffer&>
     66            inline OutputBuffer& operator<<(const OutputBuffer& object)
     67            {
     68                this->stream_ << object.stream_;
    6169                this->callListeners();
    6270                return *this;
     
    97105            void unregisterListener(OutputBufferListener* listener);
    98106
     107            inline std::stringstream& getStream()
     108                { return this->stream_; }
     109
    99110        private:
    100111            void callListeners();
  • code/branches/core3/src/util/OutputHandler.cc

    r1574 r1586  
    3333
    3434#include "OutputHandler.h"
    35 #include "Core.h"
    36 #include "ConsoleCommand.h"
    37 #include "Shell.h"
    3835
    3936namespace orxonox
    4037{
    41     SetConsoleCommandShortcutGeneric(log,     createConsoleCommand(createFunctor(&OutputHandler::log),     "log"    ));
    42     SetConsoleCommandShortcutGeneric(error,   createConsoleCommand(createFunctor(&OutputHandler::error),   "error"  ));
    43     SetConsoleCommandShortcutGeneric(warning, createConsoleCommand(createFunctor(&OutputHandler::warning), "warning"));
    44     SetConsoleCommandShortcutGeneric(info,    createConsoleCommand(createFunctor(&OutputHandler::info),    "info"   ));
    45     SetConsoleCommandShortcutGeneric(debug,   createConsoleCommand(createFunctor(&OutputHandler::debug),   "debug"  ));
    46 
    4738    /**
    4839        @brief Constructor: Opens the logfile and writes the first line.
     
    5142    OutputHandler::OutputHandler(const std::string& logfilename)
    5243    {
     44        this->outputBuffer_ = &this->fallbackBuffer_;
     45        this->softDebugLevel_[0] = this->softDebugLevel_[1] = this->softDebugLevel_[2] = this->softDebugLevel_[3] = 2;
    5346        this->logfilename_ = logfilename;
    5447        this->logfile_.open(this->logfilename_.c_str(), std::fstream::out);
     
    7770
    7871    /**
     72        @brief Sets the soft debug level for a given output device.
     73        @param device The output device
     74        @param level The debug level
     75    */
     76    void OutputHandler::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
     77    {
     78        OutputHandler::getOutStream().softDebugLevel_[(unsigned int)device] = level;
     79    }
     80
     81    /**
    7982        @brief Returns the soft debug level for a given output device.
    8083        @param device The output device
     
    8386    int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device)
    8487    {
    85         return Core::getSoftDebugLevel(device);
     88        return OutputHandler::getOutStream().softDebugLevel_[(unsigned int)device];
    8689    }
    8790
    8891    /**
    89         @brief Returns the Shell's OutputBuffer. This is mere placed here to avoid
    90                recompiling the entire project when Shell.h changes.
    91         @return The OutputBuffer of the Shell
     92        @brief Sets the OutputBuffer, representing the third output stream.
     93        @param buffer The OutputBuffer
    9294    */
    93     OutputBuffer& OutputHandler::getShellOutputBuffer()
     95    void OutputHandler::setOutputBuffer(OutputBuffer& buffer)
    9496    {
    95         return Shell::getInstance().getOutputBuffer();
     97        buffer.getStream() >> this->outputBuffer_->getStream().rdbuf();
     98        this->outputBuffer_ = &buffer;
    9699    }
    97100
     
    113116
    114117        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    115             Shell::getInstance().getOutputBuffer() << sb;
     118            (*this->outputBuffer_) << sb;
    116119
    117120        return *this;
     
    135138
    136139        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    137             Shell::getInstance().getOutputBuffer() << manipulator;
     140            (*this->outputBuffer_) << manipulator;
    138141
    139142        return *this;
     
    157160
    158161        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    159             Shell::getInstance().getOutputBuffer() << manipulator;
     162            (*this->outputBuffer_) << manipulator;
    160163
    161164        return *this;
     
    179182
    180183        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    181             Shell::getInstance().getOutputBuffer() << manipulator;
     184            (*this->outputBuffer_) << manipulator;
    182185
    183186        return *this;
  • code/branches/core3/src/util/OutputHandler.h

    r1574 r1586  
    3838#define _OutputHandler_H__
    3939
    40 #include "CorePrereqs.h"
     40#include "UtilPrereqs.h"
    4141
    4242#include <iostream>
     
    4949{
    5050    //! The OutputHandler acts like std::cout, but redirects output to the console AND the logfile.
    51     class _CoreExport OutputHandler
     51    class _UtilExport OutputHandler
    5252    {
    5353        public:
    5454            enum OutputDevice
    5555            {
    56                 LD_All,
    57                 LD_Console,
    58                 LD_Logfile,
    59                 LD_Shell
     56                LD_All = 0,
     57                LD_Console = 1,
     58                LD_Logfile = 2,
     59                LD_Shell = 3
    6060            };
    6161
     
    8686                { return this->logfile_; }
    8787
     88            /** @brief Returns a pointer to the OutputBuffer. @return The OutputBuffer */
     89            inline OutputBuffer* getOutputBuffer()
     90                { return this->outputBuffer_; }
     91
    8892            /** @brief Sets the level of the incoming output. @param level The level of the incoming output @return The OutputHandler itself */
    8993            inline OutputHandler& setOutputLevel(int level)
     
    9498                { return this->outputLevel_; }
    9599
    96             static int getSoftDebugLevel(OutputHandler::OutputDevice device);
    97 
    98             OutputBuffer& getShellOutputBuffer();
     100            static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
     101            static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
     102
     103            void setOutputBuffer(OutputBuffer& buffer);
    99104
    100105            template <class T>
     
    136141            OutputHandler(const OutputHandler& oh);  // don't copy
    137142            virtual ~OutputHandler();
    138             std::ofstream logfile_;     //!< The logfile where the output is logged
    139             std::string logfilename_;   //!< The name of the logfile
    140             int outputLevel_;           //!< The level of the incoming output
     143
     144            std::ofstream logfile_;              //!< The logfile where the output is logged
     145            std::string logfilename_;            //!< The name of the logfile
     146            OutputBuffer fallbackBuffer_;        //!< The OutputBuffer that gets used if there is no other OutputBuffer
     147            OutputBuffer* outputBuffer_;         //!< The OutputBuffer to put output in (usually used by the Shell)
     148            int outputLevel_;                    //!< The level of the incoming output
     149            int softDebugLevel_[4];              //!< The soft debug level for each OutputDevice - the configurable maximal output level
    141150    };
    142151
     
    159168
    160169        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    161             OutputHandler::getOutStream().getShellOutputBuffer() << output;
     170            (*this->outputBuffer_) << output;
    162171
    163172        return *this;
     
    183192
    184193        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel())
    185             OutputHandler::getOutStream().getShellOutputBuffer() << output;
     194            (*out.getOutputBuffer()) << output;
    186195
    187196        return out;
    188197    }
    189 
    190198}
    191199
  • code/branches/core3/src/util/String.h

    r1505 r1586  
    129129            std::string input = "3.14";
    130130            float f;
    131             bool success = string2Number(&f, input);
     131            bool success = FromString(&f, input);
    132132        */
    133133        template <typename T>
     
    151151            std::string input = "3.14";
    152152            float f;
    153             bool success = string2Number(&f, input, 0.000000);
     153            bool success = FromString(&f, input, 0.000000);
    154154        */
    155155        template <typename T>
  • code/branches/core3/src/util/UtilPrereqs.h

    r1505 r1586  
    6565class MultiTypeString;
    6666class MultiTypeMath;
    67 template <class T>
    68 class String2Number;
     67class OutputHandler;
    6968class SubString;
    7069
     70namespace orxonox
     71{
     72    class OutputBuffer;
     73    class OutputBufferListener;
     74}
     75
    7176#endif /* _UtilPrereqs_H__ */
Note: See TracChangeset for help on using the changeset viewer.