Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5991 for code


Ignore:
Timestamp:
Oct 24, 2009, 11:35:31 PM (15 years ago)
Author:
rgrieder
Message:

Replaced the load of macros in Debug.h with just two, doing almost exactly the same. The only difference is that the compiler can now completely eliminate COUT with a level higher than the hard debug level.

Location:
code/branches/console/src/libraries
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/libraries/core/OrxonoxClass.h

    r5929 r5991  
    4242#include <set>
    4343#include <vector>
     44
     45/**
     46@def CCOUT
     47    Acts almost exactly like COUT(x), but prepends "ClassName: "
     48*/
     49#define CCOUT(level) \
     50    COUT(level) << this->getIdentifier()->getName() << ": "
    4451
    4552namespace orxonox
  • code/branches/console/src/libraries/core/input/InputManager.cc

    r5929 r5991  
    190190            // Exception-safety
    191191            Loki::ScopeGuard guard = Loki::MakeGuard(OIS::InputManager::destroyInputSystem, oisInputManager_);
    192             CCOUT(ORX_DEBUG) << "Created OIS input manager." << std::endl;
     192            CCOUT(4) << "Created OIS input manager." << std::endl;
    193193
    194194            if (oisInputManager_->getNumberOfDevices(OIS::OISKeyboard) > 0)
     
    232232        }
    233233        else
    234             CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
     234            CCOUT(2) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
    235235    }
    236236
  • code/branches/console/src/libraries/util/Debug.h

    r5738 r5991  
    2121 *
    2222 *   Author:
    23  *      Benjamin Grauer
     23 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    25  *      Fabian 'x3n' Landau
     26 *      ...
    2627 *
    2728 */
    2829
    2930/**
    30     @file
    31     @brief Handles different output-levels of errors, warnings, infos and debug information.
     31@file
     32@brief
     33    Handles different output-levels of errors, warnings, infos and debug information.
    3234
    3335    The COUT(level) macro acts like std::cout, but the output is only performed if the given
     
    3537
    3638    There are two used values in this file:
    37      - The hard debug level is used during compiletime. It describes the highest allowed output level.
     39     - The hard debug level is used during compile time. It describes the highest allowed output level.
    3840     - The soft debug level is used during runtime and is the maximum of the three configurable
    39        output-levels for console, logfile and ingame shell.
     41       output-levels for console, log file and in game shell.
    4042
    4143    The separation between the three devices is done by the OutputHandler.
     
    5052     6: Crazy debug information
    5153
    52     @example
     54@example
    5355    COUT(0) << "Very important output" << std::endl;
    5456    COUT(1) << "Error: Something went wrong!" << std::endl;
    5557    COUT(2) << "Warning: There might be a problem." << std::endl;
    56     COUT(3) << "Info: It's monday" << std::endl;
     58    COUT(3) << "Info: It's Monday" << std::endl;
    5759    COUT(4) << "Debug: x is 1.23456" << std::endl;
    58  */
     60*/
    5961
    60 #ifndef _Debug_H__
    61 #define _Debug_H__
     62#ifndef _Util_Debug_H__
     63#define _Util_Debug_H__
    6264
    6365#include "UtilPrereqs.h"
    64 
    6566#include "OutputHandler.h"
    6667
    6768namespace orxonox
    6869{
    69     /**
    70         @brief Returns the soft debug level, stored in the only existing instance of the OutputHandler class, configured in the config-file.
    71         @return The soft debug level
    72     */
    73     inline int getSoftDebugLevel()
    74     {
    75         return OutputHandler::getSoftDebugLevel();
    76     }
     70    // Just for convenience
     71    using std::endl;
    7772
    78     using std::endl;
     73    //! Adjust to discard certain output with level > hardDebugLevel at compile time
     74    const int hardDebugLevel = OutputLevel::Verbose;
    7975}
    8076
    81 // DEFINE ERROR MODES
    82 #define ORX_NONE            0
    83 #define ORX_ERROR           1
    84 #define ORX_WARNING         2
    85 #define ORX_INFO            3
    86 #define ORX_DEBUG           4
    87 #define ORX_VERBOSE         5
    88 #define ORX_ULTRA           6
     77/**
     78@def COUT
     79    Logs text output: use exactly like std::cout, but specify an output
     80    level as argument. For example COUT(3) << "Some info" << std::endl;
     81@note
     82    The ? : operator requires both possible results to have the type of
     83    the first. This is achieved by the int conversion operator dummy
     84    in the OutputHandler.
     85*/
     86#define COUT(level)                                                    \
     87    /*if*/ (level > orxonox::hardDebugLevel) ?                         \
     88        0                                                              \
     89    /*else*/ :                                                         \
     90        /*if*/ (level > orxonox::OutputHandler::getSoftDebugLevel()) ? \
     91            0                                                          \
     92        /*else*/ :                                                     \
     93            orxonox::OutputHandler::getOutStream(level)
    8994
    90 //definitions
    91 #define ORX_PRINT_DEBUG_OUTPUT 1
    92 #define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE
    93 
    94 #define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x)
    95 
    96 ////////////////////////////////////////////////////////
    97 ///  COUT: just prints output as is with std::cout   ///
    98 ////////////////////////////////////////////////////////
    99 #define COUTORX_NONE    COUT0
    100 #define COUTORX_ERROR   COUT1
    101 #define COUTORX_WARNING COUT2
    102 #define COUTORX_INFO    COUT3
    103 #define COUTORX_DEBUG   COUT4
    104 #define COUTORX_VERBOSE COUT5
    105 #define COUTORX_ULTRA   COUT6
    106 
    107 #ifndef COUT
    108  #if ORX_PRINT_DEBUG_OUTPUT
    109   #define COUT(x) \
    110    COUT ## x
    111 
    112   #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
    113    #define COUT0 \
    114    (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0)
    115   #else
    116    #define COUT0 \
    117     false ? COUT_EXEC(0) : COUT_EXEC(0)
    118   #endif
    119 
    120   #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
    121    #define COUT1 \
    122     (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1)
    123   #else
    124    #define COUT1 \
    125     false ? COUT_EXEC(1) : COUT_EXEC(1)
    126   #endif
    127 
    128   #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
    129    #define COUT2 \
    130     (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2)
    131   #else
    132    #define COUT2 \
    133     false ? COUT_EXEC(2) : COUT_EXEC(2)
    134   #endif
    135 
    136   #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
    137    #define COUT3 \
    138     (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3)
    139   #else
    140    #define COUT3 \
    141     false ? COUT_EXEC(3) : COUT_EXEC(3)
    142   #endif
    143 
    144   #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
    145    #define COUT4 \
    146     (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4)
    147   #else
    148    #define COUT4 \
    149     false ? COUT_EXEC(4) : COUT_EXEC(4)
    150   #endif
    151 
    152   #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
    153    #define COUT5 \
    154     (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5)
    155   #else
    156    #define COUT5 \
    157     false ? COUT_EXEC(5) : COUT_EXEC(5)
    158   #endif
    159 
    160   #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
    161    #define COUT6 \
    162     (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6)
    163   #else
    164    #define COUT6 \
    165     false ? COUT_EXEC(6) : COUT_EXEC(6)
    166   #endif
    167 
    168  #else /* if ORX_PRINT_DEBUG_OUTPUT */
    169   #define COUT(x) \
    170     false ? COUT_EXEC(6) : COUT_EXEC(6)
    171  #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    172 
    173 #endif /* ifndef COUT */
    174 
    175 
    176 /////////////////////////////////////////////////////////////////////
    177 ///  CCOUT: Prints output with std::cout and adds the classname   ///
    178 /////////////////////////////////////////////////////////////////////
    179 #define CCOUTORX_NONE    CCOUT0
    180 #define CCOUTORX_ERROR   CCOUT1
    181 #define CCOUTORX_WARNING CCOUT2
    182 #define CCOUTORX_INFO    CCOUT3
    183 #define CCOUTORX_DEBUG   CCOUT4
    184 #define CCOUTORX_VERBOSE CCOUT5
    185 #define CCOUTORX_ULTRA   CCOUT6
    186 
    187 #define CCOUT_EXEC(x) \
    188   orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
    189   << this->getIdentifier()->getName() << ": "
    190 
    191 #ifndef CCOUT
    192  #if ORX_PRINT_DEBUG_OUTPUT
    193   #define CCOUT(x) \
    194    CCOUT ## x
    195 
    196   #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
    197    #define CCOUT0 \
    198     (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0)
    199   #else
    200    #define CCOUT0 \
    201     false ? COUT_EXEC(0) : CCOUT_EXEC(0)
    202   #endif
    203 
    204   #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
    205    #define CCOUT1 \
    206     (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1)
    207   #else
    208    #define CCOUT1 \
    209     false ? COUT_EXEC(1) : CCOUT_EXEC(1)
    210   #endif
    211 
    212   #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
    213    #define CCOUT2 \
    214     (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2)
    215   #else
    216    #define CCOUT2 \
    217     false ? COUT_EXEC(2) : CCOUT_EXEC(2)
    218   #endif
    219 
    220   #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
    221    #define CCOUT3 \
    222     (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3)
    223   #else
    224    #define CCOUT3 \
    225     false ? COUT_EXEC(3) : CCOUT_EXEC(3)
    226   #endif
    227 
    228   #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
    229    #define CCOUT4 \
    230     (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4)
    231   #else
    232    #define CCOUT4 \
    233     false ? COUT_EXEC(4) : CCOUT_EXEC(4)
    234   #endif
    235 
    236   #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
    237    #define CCOUT5 \
    238     (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5)
    239   #else
    240    #define CCOUT5 \
    241     false ? COUT_EXEC(5) : CCOUT_EXEC(5)
    242   #endif
    243 
    244   #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
    245    #define CCOUT6 \
    246     (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6)
    247   #else
    248    #define CCOUT6 \
    249     false ? COUT_EXEC(6) : CCOUT_EXEC(6)
    250   #endif
    251 
    252  #else /* if ORX_PRINT_DEBUG_OUTPUT */
    253   #define CCOUT(x) \
    254    false ? CCOUT_EXEC(6) : CCOUT_EXEC(6)
    255  #endif /* if ORX_PRINT_DEBUG_OUTPUT */
    256 
    257 #endif /* ifndef CCOUT */
    258 
    259 #endif /* _Debug_H__ */
     95#endif /* _Util_Debug_H__ */
  • code/branches/console/src/libraries/util/OutputHandler.h

    r5983 r5991  
    4848namespace orxonox
    4949{
     50    namespace OutputLevel
     51    {
     52        enum Value
     53        {
     54            None    = 0,
     55            Error   = 1,
     56            Warning = 2,
     57            Info    = 3,
     58            Debug   = 4,
     59            Verbose = 5,
     60            Ultra   = 6,
     61        };
     62    }
     63
    5064    //! The OutputHandler acts like std::cout, but redirects output to the console, the logfile and the ingame shell.
    5165    class _UtilExport OutputHandler
     
    6175
    6276            static OutputHandler& getOutStream();
     77            static inline OutputHandler& getOutStream(int level)
     78                { return OutputHandler::getOutStream().setOutputLevel(level); }
    6379
    6480            /** @brief Puts some text on the outstream. @param text The text */
     
    142158            OutputHandler& operator<<(std::ios& (*manipulator)(std::ios&));
    143159            OutputHandler& operator<<(std::ios_base& (*manipulator)(std::ios_base&));
     160
     161            /** @brief Dummy operator required by Debug.h for the ternary operator */
     162            inline operator int() { return 0; }
    144163
    145164        private:
Note: See TracChangeset for help on using the changeset viewer.