Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2009, 1:18:03 PM (15 years ago)
Author:
dafrick
Message:

Merged presentation2 branch into pickup2 branch.

Location:
code/branches/pickup2
Files:
3 deleted
25 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/pickup2

  • code/branches/pickup2/src/libraries/util/CMakeLists.txt

    r5929 r6412  
    2929  CRC32.cc
    3030  ExprParser.cc
    31   OutputBuffer.cc
    3231  OutputHandler.cc
    3332  SignalHandler.cc
  • code/branches/pickup2/src/libraries/util/Clipboard.cc

    r5781 r6412  
    7878        {
    7979            COUT(1) << "Error: Unable to copy the following text to the clipboard:" << std::endl;
    80             COUT(1) << "       \"" << text << "\"" << std::endl;
     80            COUT(1) << "       \"" << text << '"' << std::endl;
    8181        }
    8282        return false;
     
    9494            {
    9595                HANDLE hData = GetClipboardData(CF_TEXT);
    96                 std::string output = static_cast<char*>(GlobalLock(hData));
     96                if (hData == NULL)
     97                    return "";
     98                std::string output(static_cast<char*>(GlobalLock(hData)));
    9799                GlobalUnlock(hData);
    98100                CloseClipboard();
     
    117119namespace orxonox
    118120{
    119     static std::string clipboard = ""; //!< Keeps the text of our internal clipboard
     121    static std::string clipboard; //!< Keeps the text of our internal clipboard
    120122
    121123    /**
  • code/branches/pickup2/src/libraries/util/Clock.cc

    r5929 r6412  
    3434    Clock::Clock()
    3535        : timer_(new Ogre::Timer())
    36         , storedTime_(0)
    3736        , tickTime_(0)
    3837        , tickDt_(0)
    3938        , tickDtFloat_(0.0f)
    40         , lastTimersTime_(0)
    4139    {
    4240    }
     
    4644        delete timer_;
    4745    }
    48    
     46
     47    /**
     48    @remarks
     49        Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned
     50        long, which will eventually overflow. But if you use the subtraction of
     51        the current time minus the last time the timer gave us and sum these up to
     52        a 64 bit integer, we get the desired result.
     53        Also mind that we don't have to store the last timer's time as unsigned long
     54        as well because (unsigned long)tickTime_ will do exactly that.
     55    */
    4956    void Clock::capture()
    5057    {
    51         unsigned long timersTime = timer_->getMicroseconds();
    52         tickTime_ = storedTime_ + timersTime;
    53         tickDt_ = timersTime - lastTimersTime_;
     58        tickDt_ = timer_->getMicroseconds() - (unsigned long)tickTime_;
     59        tickTime_ += tickDt_;
    5460        tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
    55 
    56         if (timersTime > 0xFFFFFFFF/4)
    57         {
    58             // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
    59             storedTime_ += timersTime;
    60             lastTimersTime_ = 0;
    61             timer_->reset();
    62         }
    63         else
    64         {
    65             lastTimersTime_ = timersTime;
    66         }
    6761    }
    6862
    6963    unsigned long long Clock::getRealMicroseconds() const
    7064    {
    71         return this->timer_->getMicroseconds() + this->storedTime_;
     65        return tickTime_ + (timer_->getMicroseconds() - (unsigned long)tickTime_);
    7266    }
    7367}
  • code/branches/pickup2/src/libraries/util/Clock.h

    r5929 r6412  
    5757
    5858        Ogre::Timer*       timer_;
    59         unsigned long long storedTime_;
    6059        unsigned long long tickTime_;
    6160        long               tickDt_;
    6261        float              tickDtFloat_;
    63         unsigned long      lastTimersTime_;
    6462    };
    6563}
  • code/branches/pickup2/src/libraries/util/Convert.h

    r5738 r6412  
    4343
    4444#include "Debug.h"
    45 #include "StringUtils.h"
    4645#include "TemplateUtils.h"
    4746
     
    336335        FORCEINLINE static bool convert(std::string* output, const char input)
    337336        {
    338             *output = std::string(1, input);
     337            *output = input;
    339338            return true;
    340339        }
     
    345344        FORCEINLINE static bool convert(std::string* output, const unsigned char input)
    346345        {
    347             *output = std::string(1, input);
     346            *output = input;
    348347            return true;
    349348        }
     
    352351    struct ConverterExplicit<std::string, char>
    353352    {
    354         FORCEINLINE static bool convert(char* output, const std::string input)
    355         {
    356             if (input != "")
     353        FORCEINLINE static bool convert(char* output, const std::string& input)
     354        {
     355            if (!input.empty())
    357356                *output = input[0];
    358357            else
     
    364363    struct ConverterExplicit<std::string, unsigned char>
    365364    {
    366         FORCEINLINE static bool convert(unsigned char* output, const std::string input)
    367         {
    368             if (input != "")
     365        FORCEINLINE static bool convert(unsigned char* output, const std::string& input)
     366        {
     367            if (!input.empty())
    369368                *output = input[0];
    370369            else
     
    389388    };
    390389
     390    // Declarations to avoid StringUtils.h include
     391    _UtilExport std::string removeTrailingWhitespaces(const std::string& str);
     392    _UtilExport std::string getLowercase(const std::string& str);
     393
    391394    // std::string to bool
    392395    template <>
     
    395398        static bool convert(bool* output, const std::string& input)
    396399        {
    397             std::string stripped = getLowercase(removeTrailingWhitespaces(input));
     400            const std::string& stripped = getLowercase(removeTrailingWhitespaces(input));
    398401            if (stripped == "true" || stripped == "on" || stripped == "yes")
    399402            {
    400               *output = true;
    401               return true;
     403                *output = true;
     404                return true;
    402405            }
    403406            else if (stripped == "false" || stripped == "off" || stripped == "no")
    404407            {
    405               *output = false;
    406               return true;
     408                *output = false;
     409                return true;
    407410            }
    408411
  • code/branches/pickup2/src/libraries/util/Debug.h

    r5738 r6412  
    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()
     70    // Just for convenience
     71    using std::endl;
     72
     73    // Adjust this to discard certain output with level > hardDebugLevel at compile time already
     74#ifdef ORXONOX_RELEASE
     75    const int hardDebugLevel = OutputLevel::Verbose
     76#elif defined(NDEBUG)
     77    const int hardDebugLevel = OutputLevel::Verbose;
     78#else
     79    //! Maximum level for debug output that should be even processed at run time
     80    const int hardDebugLevel = OutputLevel::Ultra;
     81#endif
     82
     83    //! This function simply returns 0 and helps to suppress the "statement has no effect" compiler warning
     84    inline int debugDummyFunction()
    7485    {
    75         return OutputHandler::getSoftDebugLevel();
     86        return 0;
    7687    }
    77 
    78     using std::endl;
    7988}
    8089
    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
     90/**
     91@brief
     92    Logs text output: use exactly like std::cout, but specify an output
     93    level as argument.
     94@details
     95    (a > b ? 0 : c << "text") is equivalent to (a > b ? 0 : (c << "text"))
     96    where (a > b ? 0 : ) stands for COUT(x). This should explain how
     97    this macro magic can possibly even work ;)
     98@example
     99    COUT(3) << "Some info" << std::endl;
     100@note
     101    The ? : operator requires both possible results to have the type of
     102    the first. This is achieved by the int conversion operator dummy
     103    in the OutputHandler.
     104*/
     105#define COUT(level)                                                    \
     106    /*if*/ (level > orxonox::hardDebugLevel) ?                         \
     107        orxonox::debugDummyFunction()                                  \
     108    /*else*/ :                                                         \
     109        /*if*/ (level > orxonox::OutputHandler::getSoftDebugLevel()) ? \
     110            orxonox::debugDummyFunction()                              \
     111        /*else*/ :                                                     \
     112            orxonox::OutputHandler::getOutStream(level)
    89113
    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__ */
     114#endif /* _Util_Debug_H__ */
  • code/branches/pickup2/src/libraries/util/Exception.cc

    r5781 r6412  
    4949        : description_(description)
    5050        , lineNumber_(0)
    51         , functionName_("")
    52         , filename_("")
    5351    { }
    5452
     
    6159    const std::string& Exception::getFullDescription() const
    6260    {
    63         if (fullDescription_ == "")
     61        if (fullDescription_.empty())
    6462        {
    6563            std::ostringstream fullDesc;
     
    6765            fullDesc << this->getTypeName() << "Exception";
    6866
    69             if (this->filename_ != "")
     67            if (!this->filename_.empty())
    7068            {
    7169                fullDesc << " in " << this->filename_;
    7270                if (this->lineNumber_)
    73                     fullDesc << "(" << this->lineNumber_ << ")";
     71                    fullDesc << '(' << this->lineNumber_ << ')';
    7472            }
    7573
    76             if (this->functionName_ != "")
    77                 fullDesc << " in function '" << this->functionName_ << "'";
     74            if (!this->functionName_.empty())
     75                fullDesc << " in function '" << this->functionName_ << '\'';
    7876
    7977            fullDesc << ": ";
    80             if (this->description_ != "")
     78            if (!this->description_.empty())
    8179                fullDesc << this->description_;
    8280            else
    8381                fullDesc << "No description available.";
    8482
    85             this->fullDescription_ = std::string(fullDesc.str());
     83            this->fullDescription_ = fullDesc.str();
    8684        }
    8785
  • code/branches/pickup2/src/libraries/util/Exception.h

    r5747 r6412  
    131131    CREATE_ORXONOX_EXCEPTION(PluginsNotFound);
    132132    CREATE_ORXONOX_EXCEPTION(InitialisationFailed);
     133    CREATE_ORXONOX_EXCEPTION(InitialisationAborted);
    133134    CREATE_ORXONOX_EXCEPTION(NotImplemented);
    134135    CREATE_ORXONOX_EXCEPTION(GameState);
  • code/branches/pickup2/src/libraries/util/ExprParser.cc

    r5738 r6412  
    4747namespace orxonox
    4848{
    49     ExprParser::ExprParser(const std::string& str)
     49    ExprParser::ExprParser()
    5050    {
    5151        this->failed_ = false;
     52        this->variables_["pi"] = 3.1415926535897932;
     53        this->variables_["e"] = 2.7182818284590452;
     54    }
     55
     56    void ExprParser::setVariable(const std::string& varname, double value)
     57    {
     58        this->variables_[varname] = value;
     59    }
     60
     61    void ExprParser::parse(const std::string& str)
     62    {
    5263        this->reading_stream = str.c_str();
    5364        if (str.size() == 0 || *reading_stream == '\0')
     
    343354            else
    344355            {
    345 #define SWITCH word
    346                 CASE_1("pi")
    347                     value = 3.1415926535897932;
    348                 CASE("e")
    349                     value = 2.7182818284590452;
    350                 CASE_ELSE
     356                std::map<std::string, double>::const_iterator it = this->variables_.find(word);
     357                if (it != this->variables_.end())
     358                    value = it->second;
     359                else
    351360                {
    352361                    this->failed_ = true;
     
    358367        }
    359368        else if (*reading_stream == 40)
    360         {  // expresion in paranthesis
     369        {  // expression in parenthesis
    361370            ++reading_stream;
    362371            value = parse_last_argument();
  • code/branches/pickup2/src/libraries/util/ExprParser.h

    r5738 r6412  
    3636
    3737#include "UtilPrereqs.h"
     38
     39#include <map>
    3840#include <string>
    3941
     
    7173
    7274
    73         ExprParser(const std::string& str);
     75        ExprParser();
     76        void parse(const std::string& str);
    7477        const std::string& getRemains() { return  this->remains_; }
    7578        double             getResult()  { return  this->result_; }
    7679        bool               getSuccess() { return !this->failed_; }
     80
     81        void setVariable(const std::string& varname, double value);
    7782
    7883    private:
     
    97102        double result_;
    98103        std::string remains_;
    99 
     104        std::map<std::string, double> variables_;
    100105    };
    101106
  • code/branches/pickup2/src/libraries/util/Math.cc

    r5738 r6412  
    4343namespace orxonox
    4444{
     45#if OGRE_VERSION < 0x010603
    4546    /**
    4647        @brief Function for writing a Radian to a stream.
     
    5152        return out;
    5253    }
     54
     55    /**
     56        @brief Function for writing a Degree to a stream.
     57    */
     58    std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree)
     59    {
     60        out << degree.valueDegrees();
     61        return out;
     62    }
     63#endif
    5364
    5465    /**
     
    6172        radian = temp;
    6273        return in;
    63     }
    64 
    65     /**
    66         @brief Function for writing a Degree to a stream.
    67     */
    68     std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree)
    69     {
    70         out << degree.valueDegrees();
    71         return out;
    7274    }
    7375
     
    136138                return orxonox::Vector2(0, 1);
    137139        }
    138        
     140
    139141        float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
    140142        float sin_value = sqrt( 1 - cos_value*cos_value );
    141        
     143
    142144        if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
    143145            return orxonox::Vector2( sin_value, cos_value );
     
    177179        }
    178180        //float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
    179        
     181
    180182        float cos_value = clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1);
    181183        float sin_value = sqrt( 1 - cos_value*cos_value );
  • code/branches/pickup2/src/libraries/util/Math.h

    r5738 r6412  
    5959namespace orxonox
    6060{
     61#if OGRE_VERSION < 0x010603
    6162    _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian);
     63    _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
     64#endif
    6265    _UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian);
    63     _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
    6466    _UtilExport std::istream& operator>>(std::istream& in, orxonox::Degree& degree);
    6567
     
    163165    template <> inline bool                 zeroise<bool>()                 { return 0; }
    164166    template <> inline void*                zeroise<void*>()                { return 0; }
    165     template <> inline std::string          zeroise<std::string>()          { return ""; }
     167    template <> inline std::string          zeroise<std::string>()          { return std::string(); }
    166168    template <> inline orxonox::Radian      zeroise<orxonox::Radian>()      { return orxonox::Radian(0.0f); }
    167169    template <> inline orxonox::Degree      zeroise<orxonox::Degree>()      { return orxonox::Degree(0.0f); }
  • code/branches/pickup2/src/libraries/util/MathConvert.h

    r5738 r6412  
    5353        {
    5454            std::ostringstream ostream;
    55             if (ostream << input.x << "," << input.y)
     55            if (ostream << input.x << ',' << input.y)
    5656            {
    5757                (*output) = ostream.str();
     
    6969        {
    7070            std::ostringstream ostream;
    71             if (ostream << input.x << "," << input.y << "," << input.z)
     71            if (ostream << input.x << ',' << input.y << ',' << input.z)
    7272            {
    7373                (*output) = ostream.str();
     
    8585        {
    8686            std::ostringstream ostream;
    87             if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)
     87            if (ostream << input.x << ',' << input.y << ',' << input.z << ',' << input.w)
    8888            {
    8989                (*output) = ostream.str();
     
    101101        {
    102102            std::ostringstream ostream;
    103             if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)
     103            if (ostream << input.w << ',' << input.x << ',' << input.y << ',' << input.z)
    104104            {
    105105                (*output) = ostream.str();
     
    117117        {
    118118            std::ostringstream ostream;
    119             if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)
     119            if (ostream << input.r << ',' << input.g << ',' << input.b << ',' << input.a)
    120120            {
    121121                (*output) = ostream.str();
  • code/branches/pickup2/src/libraries/util/MultiType.h

    r5738 r6412  
    232232
    233233            virtual void toString(std::ostream& outstream) const = 0;
    234            
     234
    235235            virtual void importData( uint8_t*& mem )=0;
    236236            virtual void exportData( uint8_t*& mem ) const=0;
     
    339339            template <typename T> inline bool isType()                    const { return false; } // Only works for specialized values - see below
    340340            std::string                       getTypename()               const;
    341            
     341
    342342            /** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */
    343343            inline void                       exportData(uint8_t*& mem) const { assert(sizeof(MT_Type::Value)<=8); *static_cast<uint8_t*>(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); }
  • code/branches/pickup2/src/libraries/util/MultiTypeValue.h

    r5738 r6412  
    150150        /** @brief Puts the current value on the stream */
    151151        inline void toString(std::ostream& outstream) const { outstream << this->value_; }
    152        
     152
    153153        /** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */
    154154        inline void importData( uint8_t*& mem )         { loadAndIncrease( /*(const T&)*/this->value_, mem ); }
     
    160160        T value_; //!< The stored value
    161161    };
    162    
     162
    163163    // Import / Export specialisation
    164164    // ColourValue
  • code/branches/pickup2/src/libraries/util/OrxAssert.h

    r5738 r6412  
    4444#ifndef NDEBUG
    4545#define OrxAssert(Assertion, ErrorMessage) \
    46     Assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream().setOutputLevel(1) << ErrorMessage << std::endl); \
     46    Assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream(1) << ErrorMessage << std::endl); \
    4747    assert(Assertion)
    4848#else
  • code/branches/pickup2/src/libraries/util/OutputHandler.cc

    r5738 r6412  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
    2828
    2929/**
    30     @file
    31     @brief Implementation of the OutputHandler class.
     30@file
     31@brief
     32    Definition of classes related to output (logging).
    3233*/
    3334
    3435#include "OutputHandler.h"
    3536
     37#include <algorithm>
    3638#include <ctime>
    3739#include <cstdlib>
     40#include <fstream>
     41#include <iostream>
     42#include <sstream>
     43
     44#include "Debug.h"
    3845
    3946namespace orxonox
    4047{
     48    //! How the log file shall be named on the filesystem
     49    const std::string logFileBaseName_g = "orxonox.log";
     50
     51    /////////////////////////
     52    ///// LogFileWriter /////
     53    /////////////////////////
    4154    /**
    42         @brief Constructor: Opens the logfile and writes the first line.
    43         @param logfilename The name of the logfile
     55    @brief
     56        Writes the output to the log file.
     57    @note
     58        As long as the correct log path is not yet known (for pre main code), the
     59        LogFileWriter will write to a temporary file in /temp (Unix) or %TEMP% (Windows).
     60        As soon as you set the correct path setLogPath the content of the temporary file
     61        is read and put into the new file as well.
    4462    */
     63    class LogFileWriter : public OutputListener
     64    {
     65    public:
     66        /**
     67        @brief
     68            Gets temporary log path and starts the log file
     69        @param outputHandler
     70            This is only required to avoid another call to getInstance (this c'tor was
     71            called from getInstance!)
     72        */
     73        LogFileWriter()
     74            : OutputListener(OutputHandler::logFileOutputListenerName_s)
     75        {
     76            // Get path for a temporary file
     77#ifdef ORXONOX_PLATFORM_WINDOWS
     78            char* pTempDir = getenv("TEMP");
     79            this->logFilename_ = std::string(pTempDir) + '/' + logFileBaseName_g;
     80#else
     81            this->logFilename_ = std::string("/tmp/") + logFileBaseName_g;
     82#endif
     83
     84            // Get current time
     85            time_t rawtime;
     86            struct tm* timeinfo;
     87            time(&rawtime);
     88            timeinfo = localtime(&rawtime);
     89
     90            this->logFile_.open(this->logFilename_.c_str(), std::fstream::out);
     91            this->logFile_ << "Started log on " << asctime(timeinfo) << std::endl;
     92            this->logFile_.flush();
     93
     94            this->outputStream_ = &this->logFile_;
     95        }
     96
     97        //! Closes the log file
     98        ~LogFileWriter()
     99        {
     100            this->logFile_ << "Closed log" << std::endl;
     101            this->logFile_.close();
     102        }
     103
     104        //! Changes the log path
     105        void setLogPath(const std::string& path)
     106        {
     107            this->logFile_.close();
     108            // Read old file into a buffer
     109            std::ifstream old(this->logFilename_.c_str());
     110            this->logFilename_ = path + logFileBaseName_g;
     111            // Open the new file and feed it the content of the old one
     112            this->logFile_.open(this->logFilename_.c_str(), std::fstream::out);
     113            this->logFile_ << old.rdbuf();
     114            this->logFile_.flush();
     115            old.close();
     116        }
     117
     118    private:
     119        std::ofstream logFile_;     //! File handle for the log file
     120        std::string   logFilename_; //! Filename of the log file
     121    };
     122
     123
     124    /////////////////////////
     125    ///// ConsoleWriter /////
     126    /////////////////////////
     127    /**
     128    @brief
     129        Writes the output to std::cout.
     130    @note
     131        This listener will usually be disable once an actual shell with console is instantiated.
     132    */
     133    class ConsoleWriter : public OutputListener
     134    {
     135    public:
     136        //! Only assigns the output stream with std::cout
     137        ConsoleWriter()
     138            : OutputListener("consoleLog")
     139        {
     140            this->outputStream_ = &std::cout;
     141        }
     142    };
     143
     144
     145    ///////////////////////////
     146    ///// MemoryLogWriter /////
     147    ///////////////////////////
     148    /**
     149    @brief
     150        OutputListener that writes all the output piece by piece to an array
     151        associated with the corresponding output level.
     152    @note
     153        Only output below or equal to the current soft debug level is written
     154        to minimise huge arrays for the normal run.
     155    */
     156    class MemoryLogWriter : public OutputListener
     157    {
     158    public:
     159        friend class OutputHandler;
     160
     161        /**
     162        @brief
     163            Sets the right soft debug level and registers itself
     164        @param outputHandler
     165            This is only required to avoid another call to getInstance (this c'tor was
     166            called from getInstance!)
     167        */
     168        MemoryLogWriter()
     169            : OutputListener("memoryLog")
     170        {
     171            this->outputStream_ = &this->buffer_;
     172        }
     173
     174        //! Pushed the just written output to the internal array
     175        void outputChanged(int level)
     176        {
     177            if (!this->buffer_.str().empty())
     178            {
     179                // Read ostringstream and store it
     180                this->output_.push_back(std::make_pair(level, this->buffer_.str()));
     181                // Clear content and flags
     182                this->buffer_.str(std::string());
     183            }
     184            this->buffer_.clear();
     185        }
     186
     187    private:
     188        std::ostringstream                        buffer_; //! Stream object used to process the output
     189        std::vector<std::pair<int, std::string> > output_; //! Vector containing ALL output
     190    };
     191
     192
     193    /////////////////////////
     194    ///// OutputHandler /////
     195    /////////////////////////
     196    const std::string OutputHandler::logFileOutputListenerName_s = "logFile";
     197          int         OutputHandler::softDebugLevel_s = hardDebugLevel;
     198
     199    //! Creates the LogFileWriter and the MemoryLogWriter
    45200    OutputHandler::OutputHandler()
    46     {
    47 #ifdef ORXONOX_PLATFORM_WINDOWS
    48         char* pTempDir = getenv("TEMP");
    49         this->logfilename_ = std::string(pTempDir) + "/orxonox.log";
     201        : outputLevel_(OutputLevel::Verbose)
     202    {
     203#ifdef ORXONOX_RELEASE
     204        const OutputLevel::Value defaultLevelConsole = OutputLevel::Error;
     205        const OutputLevel::Value defaultLevelLogFile = OutputLevel::Info;
    50206#else
    51         this->logfilename_ = "/tmp/orxonox.log";
     207        const OutputLevel::Value defaultLevelConsole = OutputLevel::Info;
     208        const OutputLevel::Value defaultLevelLogFile = OutputLevel::Debug;
    52209#endif
    53 #ifdef NDEBUG
    54         this->softDebugLevel_[LD_All] = this->softDebugLevel_[LD_Logfile] = 2;
    55         this->softDebugLevel_[LD_Console] = this->softDebugLevel_[LD_Shell] = 1;
    56 #else
    57         this->softDebugLevel_[LD_All] = this->softDebugLevel_[LD_Logfile] = 3;
    58         this->softDebugLevel_[LD_Console] = this->softDebugLevel_[LD_Shell] = 2;
    59 #endif
    60 
    61         this->outputBuffer_ = &this->fallbackBuffer_;
    62         this->logfile_.open(this->logfilename_.c_str(), std::fstream::out);
    63 
    64         time_t rawtime;
    65         struct tm* timeinfo;
    66         time(&rawtime);
    67         timeinfo = localtime(&rawtime);
    68 
    69         this->logfile_ << "Started log on " << asctime(timeinfo) << std::endl;
    70         this->logfile_.flush();
    71     }
    72 
    73     /**
    74         @brief Destructor: Writes the last line to the logfile and closes it.
    75     */
     210
     211        this->logFile_ = new LogFileWriter();
     212        // Use default level until we get the configValue from the Core
     213        this->logFile_->softDebugLevel_ = defaultLevelLogFile;
     214        this->registerOutputListener(this->logFile_);
     215
     216        this->consoleWriter_ = new ConsoleWriter();
     217        this->consoleWriter_->softDebugLevel_ = defaultLevelConsole;
     218        this->registerOutputListener(this->consoleWriter_);
     219
     220        this->output_ = new MemoryLogWriter();
     221        // We capture as much input as the listener with the highest level
     222        this->output_->softDebugLevel_ = getSoftDebugLevel();
     223        this->registerOutputListener(this->output_);
     224    }
     225
     226    //! Destroys the LogFileWriter and the MemoryLogWriter
    76227    OutputHandler::~OutputHandler()
    77228    {
    78         this->logfile_ << "Closed log" << std::endl;
    79         this->logfile_.close();
    80     }
    81 
    82     /**
    83         @brief Returns a reference to the only existing instance of the OutputHandler class.
    84         @return The instance
    85     */
    86     OutputHandler& OutputHandler::getOutStream()
     229        delete this->logFile_;
     230        delete this->consoleWriter_;
     231        delete this->output_;
     232    }
     233
     234    OutputHandler& OutputHandler::getInstance()
    87235    {
    88236        static OutputHandler orxout;
     
    90238    }
    91239
    92     /**
    93         @brief Sets the soft debug level for a given output device.
    94         @param device The output device
    95         @param level The debug level
    96     */
    97     void OutputHandler::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
    98     {
    99         OutputHandler::getOutStream().softDebugLevel_[static_cast<unsigned int>(device)] = level;
    100     }
    101 
    102     /**
    103         @brief Returns the soft debug level for a given output device.
    104         @param device The output device
    105         @return The debug level
    106     */
    107     int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device)
    108     {
    109         return OutputHandler::getOutStream().softDebugLevel_[static_cast<unsigned int>(device)];
    110     }
    111 
    112     /**
    113         @brief Sets the OutputBuffer, representing the third output stream.
    114         @param buffer The OutputBuffer
    115     */
    116     void OutputHandler::setOutputBuffer(OutputBuffer* buffer)
    117     {
    118         if (buffer == NULL)
    119             this->outputBuffer_ = &this->fallbackBuffer_;
    120         else
    121         {
    122             buffer->getStream() >> this->outputBuffer_->getStream().rdbuf();
    123             this->outputBuffer_ = buffer;
    124         }
    125     }
    126 
    127     /**
    128         @brief Sets the path where to create orxonox.log
    129         @param Path string with trailing slash
    130     */
     240    void OutputHandler::registerOutputListener(OutputListener* listener)
     241    {
     242        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     243        {
     244            if ((*it)->name_ == listener->name_)
     245            {
     246                COUT(2) << "OutputHandler, Warning: Trying to register two listeners with the same name!" << std::endl;
     247                return;
     248            }
     249        }
     250        this->listeners_.push_back(listener);
     251        // Update global soft debug level
     252        this->setSoftDebugLevel(listener->getOutputListenerName(), listener->getSoftDebugLevel());
     253    }
     254
     255    void OutputHandler::unregisterOutputListener(OutputListener* listener)
     256    {
     257        this->listeners_.remove(listener);
     258    }
     259
    131260    void OutputHandler::setLogPath(const std::string& path)
    132261    {
    133         OutputHandler::getOutStream().logfile_.close();
    134         // store old content
    135         std::ifstream old;
    136         old.open(OutputHandler::getOutStream().logfilename_.c_str());
    137         OutputHandler::getOutStream().logfilename_ = path + "orxonox.log";
    138         OutputHandler::getOutStream().logfile_.open(OutputHandler::getOutStream().logfilename_.c_str(), std::fstream::out);
    139         OutputHandler::getOutStream().logfile_ << old.rdbuf();
    140         old.close();
    141         OutputHandler::getOutStream().logfile_.flush();
    142     }
    143 
    144     /**
    145         @brief Overloaded << operator, redirects the output to the console and the logfile.
    146         @param sb The streambuffer that should be shown in the console
    147         @return A reference to the OutputHandler itself
    148     */
    149     OutputHandler& OutputHandler::operator<<(std::streambuf* sb)
    150     {
    151         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    152             std::cout << sb;
    153 
    154         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
    155         {
    156             this->logfile_ << sb;
    157             this->logfile_.flush();
    158         }
    159 
    160         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    161             (*this->outputBuffer_) << sb;
    162 
    163         return *this;
    164     }
    165 
    166     /**
    167         @brief Overloaded << operator, redirects the output to the console, the logfile and the ingame shell.
    168         @param manipulator A function, manipulating the outstream.
    169         @return A reference to the OutputHandler itself
    170     */
    171     OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&))
    172     {
    173         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    174             manipulator(std::cout);
    175 
    176         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
    177         {
    178             manipulator(this->logfile_);
    179             this->logfile_.flush();
    180         }
    181 
    182         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    183             (*this->outputBuffer_) << manipulator;
    184 
    185         return *this;
    186     }
    187 
    188     /**
    189         @brief Overloaded << operator, redirects the output to the console, the logfile and the ingame shell.
    190         @param manipulator A function, manipulating the outstream.
    191         @return A reference to the OutputHandler itself
    192     */
    193     OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&))
    194     {
    195         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    196             manipulator(std::cout);
    197 
    198         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
    199         {
    200             manipulator(this->logfile_);
    201             this->logfile_.flush();
    202         }
    203 
    204         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    205             (*this->outputBuffer_) << manipulator;
    206 
    207         return *this;
    208     }
    209 
    210     /**
    211         @brief Overloaded << operator, redirects the output to the console, the logfile and the ingame shell.
    212         @param manipulator A function, manipulating the outstream.
    213         @return A reference to the OutputHandler itself
    214     */
    215     OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&))
    216     {
    217         if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    218             manipulator(std::cout);
    219 
    220         if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
    221         {
    222             manipulator(this->logfile_);
    223             this->logfile_.flush();
    224         }
    225 
    226         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    227             (*this->outputBuffer_) << manipulator;
    228 
    229         return *this;
     262        this->logFile_->setLogPath(path);
     263    }
     264
     265    void OutputHandler::disableCout()
     266    {
     267        this->unregisterOutputListener(this->consoleWriter_);
     268    }
     269
     270    void OutputHandler::enableCout()
     271    {
     272        this->registerOutputListener(this->consoleWriter_);
     273    }
     274
     275    OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorBegin() const
     276    {
     277        return this->output_->output_.begin();
     278    }
     279
     280    OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorEnd() const
     281    {
     282        return this->output_->output_.end();
     283    }
     284
     285    int OutputHandler::getSoftDebugLevel(const std::string& name) const
     286    {
     287        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     288        {
     289            if ((*it)->name_ == name)
     290                return (*it)->softDebugLevel_;
     291        }
     292        return -1;
     293    }
     294
     295    void OutputHandler::setSoftDebugLevel(const std::string& name, int level)
     296    {
     297        int globalSoftDebugLevel = -1;
     298        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
     299        {
     300            if ((*it)->name_ == name)
     301                (*it)->softDebugLevel_ = level;
     302            if ((*it)->softDebugLevel_ > globalSoftDebugLevel)
     303                globalSoftDebugLevel = (*it)->softDebugLevel_;
     304        }
     305        // Update global soft debug level
     306        OutputHandler::softDebugLevel_s = globalSoftDebugLevel;
    230307    }
    231308}
  • code/branches/pickup2/src/libraries/util/OutputHandler.h

    r5738 r6412  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
    2828
    2929/**
    30     @file
    31     @brief Definition of the OutputHandler class.
    32 
    33     The OutputHandler acts like std::cout, but output isn't only shown in the console,
    34     but also written to the logfile and the ingame shell.
     30@file
     31@brief
     32    Declaration of classes related to output (logging).
    3533*/
    3634
     
    4038#include "UtilPrereqs.h"
    4139
    42 #include <iostream>
    43 #include <fstream>
     40#include <list>
     41#include <ostream>
    4442#include <string>
    45 
    46 #include "OutputBuffer.h"
     43#include <vector>
     44#include <utility>
    4745
    4846namespace orxonox
    4947{
    50     //! The OutputHandler acts like std::cout, but redirects output to the console, the logfile and the ingame shell.
     48    /**
     49    @brief
     50        Denotes different levels of text output (log output)
     51
     52        0, None   : Very important output
     53        1, Error  : Errors
     54        2, Warning: Warnings
     55        3, Info   : Information
     56        4, Debug  : Debug information
     57        5, Verbose: More debug information
     58        6, Ultra  : Crazy debug information
     59    */
     60    namespace OutputLevel
     61    {
     62        enum Value
     63        {
     64            None    = 0,
     65            Error   = 1,
     66            Warning = 2,
     67            Info    = 3,
     68            Debug   = 4,
     69            Verbose = 5,
     70            Ultra   = 6,
     71        };
     72    }
     73
     74    // Forward declarations for classes in the source file
     75    class LogFileWriter;
     76    class ConsoleWriter;
     77    class MemoryLogWriter;
     78
     79    /**
     80    @brief
     81        The OutputHandler acts like std::cout, but output isn't only shown in the console.
     82
     83        You can register your own listener for output by inheriting from OutputListner.
     84        And if you need the output previously processed, iterate over it with
     85        OutputHandler::getOutputVector[Begin/End].
     86        The way to output text is to first set the desired output level with
     87        OutputHandler::getOutStream(level) and then use the "<<" operator like with std::cout.
     88    */
    5189    class _UtilExport OutputHandler
    5290    {
    5391        public:
    54             enum OutputDevice
    55             {
    56                 LD_All = 0,
    57                 LD_Console = 1,
    58                 LD_Logfile = 2,
    59                 LD_Shell = 3
    60             };
    61 
    62             static OutputHandler& getOutStream();
    63 
    64             /** @brief Puts some text on the outstream. @param text The text */
     92            //! Returns a reference to the only existing instance of the OutputHandler class.
     93            static OutputHandler& getInstance();
     94
     95            //! Sets the output level and returns a stream to be used with "<<"
     96            static inline OutputHandler& getOutStream(int level)
     97                { return OutputHandler::getInstance().setOutputLevel(level); }
     98
     99            typedef std::vector<std::pair<int, std::string> >::const_iterator OutputVectorIterator;
     100            //! Returns an iterator to the beginning of the all-output vector
     101            OutputVectorIterator getOutputVectorBegin() const;
     102            //! Returns an iterator to the end of the all-output vector
     103            OutputVectorIterator getOutputVectorEnd() const;
     104
     105            //! Writes to all output devices
    65106            static inline const std::string& log(const std::string& text)
    66                 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; }
    67 
    68             /** @brief Puts an error on the outstream. @param text The text */
     107                { OutputHandler::getOutStream(0).output(text) << std::endl; return text; }
     108
     109            //! Writes an error message to the output
    69110            static inline const std::string& error(const std::string& text)
    70                 { OutputHandler::getOutStream().setOutputLevel(1); OutputHandler::getOutStream().output(text + "\n"); return text; }
    71 
    72             /** @brief Puts a warning on the outstream. @param text The text */
     111                { OutputHandler::getOutStream(1).output(text) << std::endl; return text; }
     112
     113            //! Writes a warning message to the output
    73114            static inline const std::string& warning(const std::string& text)
    74                 { OutputHandler::getOutStream().setOutputLevel(2); OutputHandler::getOutStream().output(text + "\n"); return text; }
    75 
    76             /** @brief Puts an info on the outstream. @param text The text */
     115                { OutputHandler::getOutStream(2).output(text) << std::endl; return text; }
     116
     117            //! Writes an informational message to the output
    77118            static inline const std::string& info(const std::string& text)
    78                 { OutputHandler::getOutStream().setOutputLevel(3); OutputHandler::getOutStream().output(text + "\n"); return text; }
    79 
    80             /** @brief Puts some debug output on the outstream. @param text The text */
     119                { OutputHandler::getOutStream(3).output(text) << std::endl; return text; }
     120
     121            //! Writes a debug message to the output
    81122            static inline const std::string& debug(const std::string& text)
    82                 { OutputHandler::getOutStream().setOutputLevel(4); OutputHandler::getOutStream().output(text + "\n"); return text; }
    83 
    84             /** @brief Returns a reference to the logfile. @return The logfile */
    85             inline std::ofstream& getLogfile()
    86                 { return this->logfile_; }
    87 
    88             /** @brief Returns a pointer to the OutputBuffer. @return The OutputBuffer */
    89             inline OutputBuffer* getOutputBuffer()
    90                 { return this->outputBuffer_; }
    91 
    92             /** @brief Sets the level of the incoming output. @param level The level of the incoming output @return The OutputHandler itself */
     123                { OutputHandler::getOutStream(4).output(text) << std::endl; return text; }
     124
     125            //! Registers an object that receives output via a provided std::ostream
     126            void registerOutputListener(OutputListener* listener);
     127            //! Unregisters an object that receives output via a provided std::ostream
     128            void unregisterOutputListener(OutputListener* listener);
     129
     130            //! Set the log path once the program has been properly initialised
     131            void setLogPath(const std::string& path);
     132            //! Disables the std::cout stream for output
     133            void disableCout();
     134            //! Enables the std::cout stream for output (startup behaviour)
     135            void enableCout();
     136
     137            //! Sets the level of the incoming output and returns the OutputHandler
    93138            inline OutputHandler& setOutputLevel(int level)
    94139                { this->outputLevel_ = level; return *this; }
    95140
    96             /** @brief Returns the level of the incoming output. @return The level */
     141            //! Returns the level of the incoming output
    97142            inline int getOutputLevel() const
    98143                { return this->outputLevel_; }
    99144
    100             static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
    101             static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
    102 
    103             static void setLogPath(const std::string& path);
    104 
    105             void setOutputBuffer(OutputBuffer* buffer);
    106 
     145            //! Returns the maximum debug level over all registered listeners (devices)
     146            static int getSoftDebugLevel() { return softDebugLevel_s; }
     147            //! Returns the soft debug level for a device by its name   @return The level or -1 if the listener was not found
     148            int  getSoftDebugLevel(const std::string& name) const;
     149            //! Sets the soft debug level for a listener by its name   @remarks Only works for registered listeners!
     150            void setSoftDebugLevel(const std::string& name, int level);
     151
     152            /**
     153            @brief
     154                General template that copes with all output.
     155                Required because operator << might be ambiguous.
     156                @a output will be streamed into every listener with an appropriate debug level
     157            @return
     158                Returns a reference to the OutputHandler so you can use it again directly
     159            */
    107160            template <class T>
    108161            OutputHandler& output(const T& output);
    109162
    110             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     163            //! Overloaded << operator, redirects the output to the listeners
    111164            inline OutputHandler& operator<<(unsigned char val)      { return this->output(val); }
    112             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     165            //! Overloaded << operator, redirects the output to the listeners
    113166            inline OutputHandler& operator<<(short val)              { return this->output(val); }
    114             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     167            //! Overloaded << operator, redirects the output to the listeners
    115168            inline OutputHandler& operator<<(unsigned short val)     { return this->output(val); }
    116             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     169            //! Overloaded << operator, redirects the output to the listeners
    117170            inline OutputHandler& operator<<(int val)                { return this->output(val); }
    118             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     171            //! Overloaded << operator, redirects the output to the listeners
    119172            inline OutputHandler& operator<<(unsigned int val)       { return this->output(val); }
    120             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     173            //! Overloaded << operator, redirects the output to the listeners
    121174            inline OutputHandler& operator<<(long val)               { return this->output(val); }
    122             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     175            //! Overloaded << operator, redirects the output to the listeners
    123176            inline OutputHandler& operator<<(unsigned long val)      { return this->output(val); }
    124             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     177            //! Overloaded << operator, redirects the output to the listeners
    125178            inline OutputHandler& operator<<(long long val)          { return this->output(val); }
    126             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     179            //! Overloaded << operator, redirects the output to the listeners
    127180            inline OutputHandler& operator<<(unsigned long long val) { return this->output(val); }
    128             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     181            //! Overloaded << operator, redirects the output to the listeners
    129182            inline OutputHandler& operator<<(float val)              { return this->output(val); }
    130             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     183            //! Overloaded << operator, redirects the output to the listeners
    131184            inline OutputHandler& operator<<(double val)             { return this->output(val); }
    132             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     185            //! Overloaded << operator, redirects the output to the listeners
    133186            inline OutputHandler& operator<<(long double val)        { return this->output(val); }
    134             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     187            //! Overloaded << operator, redirects the output to the listeners
    135188            inline OutputHandler& operator<<(const void* val)        { return this->output(val); }
    136             /** @brief Overloaded << operator, redirects the output to the console and the logfile. @param val The value that should be shown in the console @return A reference to the OutputHandler itself */
     189            //! Overloaded << operator, redirects the output to the listeners
    137190            inline OutputHandler& operator<<(bool val)               { return this->output(val); }
    138191
    139             OutputHandler& operator<<(std::streambuf* sb);
    140 
    141             OutputHandler& operator<<(std::ostream& (*manipulator)(std::ostream&));
    142             OutputHandler& operator<<(std::ios& (*manipulator)(std::ios&));
    143             OutputHandler& operator<<(std::ios_base& (*manipulator)(std::ios_base&));
     192            //! Overloaded << operator, redirects the output to the listeners
     193            inline OutputHandler& operator<<(std::streambuf* sb)     { return this->output(sb); }
     194
     195            //! Overloaded << operator, redirect the output of classes with self defined 'operator <<' to the listeners
     196            template <class T>
     197            inline OutputHandler& operator<<(const T& val)           { return this->output(val); }
     198
     199            //! Overloaded << operator for std manipulators like std::endl, redirects the output to the listeners
     200            inline OutputHandler& operator<<(std::ostream&  (*manip)(std::ostream&))  { return this->output(manip); }
     201            //! Overloaded << operator for std manipulators like std::endl, redirects the output to the listeners
     202            inline OutputHandler& operator<<(std::ios&      (*manip)(std::ios&))      { return this->output(manip); }
     203            //! Overloaded << operator for std manipulators like std::endl, redirects the output to the listeners
     204            inline OutputHandler& operator<<(std::ios_base& (*manip)(std::ios_base&)) { return this->output(manip); }
     205
     206            //! Dummy operator required by Debug.h for the ternary operator
     207            inline operator int() const { return 0; }
     208
     209            //! Name of the OutputListener that writes to the log file
     210            static const std::string logFileOutputListenerName_s;
    144211
    145212        private:
    146             explicit OutputHandler();
    147             OutputHandler(const OutputHandler& oh);
    148             virtual ~OutputHandler();
    149 
    150             std::ofstream logfile_;              //!< The logfile where the output is logged
    151             std::string logfilename_;            //!< The name of the logfile
    152             OutputBuffer fallbackBuffer_;        //!< The OutputBuffer that gets used if there is no other OutputBuffer
    153             OutputBuffer* outputBuffer_;         //!< The OutputBuffer to put output in (usually used by the Shell)
    154             int outputLevel_;                    //!< The level of the incoming output
    155             int softDebugLevel_[4];              //!< The soft debug level for each OutputDevice - the configurable maximal output level
     213            OutputHandler();
     214            ~OutputHandler();
     215            OutputHandler(const OutputHandler& rhs); //! Unused and undefined
     216
     217            std::list<OutputListener*> listeners_;        //!< Array with all registered output listeners
     218            int                        outputLevel_;      //!< The level of the incoming output
     219            LogFileWriter*             logFile_;          //!< Listener that writes to the log file
     220            ConsoleWriter*             consoleWriter_;    //!< Listener for std::cout (just program beginning)
     221            MemoryLogWriter*           output_;           //!< Listener that Stores ALL output below the current soft debug level
     222            static int                 softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
    156223    };
    157224
    158225    /**
    159         @brief Redirects the output to the console and the logfile.
    160         @param output The value that should be shown in the console
    161         @return A reference to the OutputHandler itself
     226    @brief
     227        Interface for listening to output.
     228    @remarks
     229        Remember to register the listener (not done automatically!)
    162230    */
     231    class OutputListener
     232    {
     233        friend class OutputHandler;
     234
     235    public:
     236        OutputListener(const std::string& name)
     237            : outputStream_(NULL)
     238            , name_(name)
     239            , softDebugLevel_(OutputLevel::Info)
     240        {}
     241        virtual ~OutputListener() {}
     242
     243        //! Gets called whenever output is put into the stream
     244        virtual void outputChanged(int level) {}
     245        //! Returns the name of this output listener
     246        const std::string& getOutputListenerName() const { return this->name_; }
     247        //! Returns the soft debug level of the listener
     248        int getSoftDebugLevel() const { return this->softDebugLevel_; }
     249        //! Sets the soft debug level of the listener
     250        void setSoftDebugLevel(int level)
     251        {
     252            this->softDebugLevel_ = level;
     253            OutputHandler::getInstance().setSoftDebugLevel(this->name_, level);
     254        }
     255
     256    protected:
     257        std::ostream*     outputStream_;   //!< Pointer to the associated output stream, can be NULL
     258
     259    private:
     260        const std::string name_;           //!< Name of the listener, constant and unique!
     261        int               softDebugLevel_; //!< Current soft debug level that defines what kind of output is written to the stream
     262    };
     263
    163264    template<class T>
    164     OutputHandler& OutputHandler::output(const T& output)
    165     {
    166         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_)
    167             std::cout << output;
    168 
    169         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_)
     265    inline OutputHandler& OutputHandler::output(const T& output)
     266    {
     267        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
    170268        {
    171             this->logfile_ << output;
    172             this->logfile_.flush();
     269            if (this->outputLevel_ <= (*it)->softDebugLevel_ && (*it)->outputStream_ != NULL)
     270            {
     271                std::ostream& stream = *((*it)->outputStream_);
     272                stream << output;
     273                stream.flush();
     274                (*it)->outputChanged(this->outputLevel_);
     275            }
    173276        }
    174 
    175         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
    176             (*this->outputBuffer_) << output;
    177277
    178278        return *this;
    179279    }
    180 
    181     /**
    182         @brief Overloading of the non-member << operator to redirect the output of classes with self defined '<< to std::ostream' operators to the console and the logfile.
    183         @param out The OutputHandler itself
    184         @param output The class that should be shown in the console
    185         @return The OutputHandler itself
    186     */
    187     template<class T>
    188     OutputHandler& operator<<(OutputHandler& out, const T& output)
    189     {
    190         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel())
    191             std::cout << output;
    192 
    193         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= out.getOutputLevel())
    194         {
    195             out.getLogfile() << output;
    196             out.getLogfile().flush();
    197         }
    198 
    199         if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel())
    200             (*out.getOutputBuffer()) << output;
    201 
    202         return out;
    203     }
    204280}
    205281
  • code/branches/pickup2/src/libraries/util/Serialise.h

    r5738 r6412  
    3737#include <cstring>
    3838#include "util/Math.h"
     39#include "util/mbool.h"
    3940
    4041namespace orxonox{
    41    
    42 // general template declaration
    43    
     42
    4443    /** @brief returns the size of the variable in a datastream */
    45     template <class T> inline uint32_t returnSize( const T& );
     44    template <class T> inline uint32_t returnSize( const T& variable );
    4645    /** @brief loads the value of a variable out of the bytestream and increases the mem pointer */
    47     template <class T> inline void loadAndIncrease( const T&, uint8_t*& );
     46    template <class T> inline void loadAndIncrease( const T& variable, uint8_t*& mem );
    4847    /** @brief saves the value of a variable into the bytestream and increases the mem pointer */
    49     template <class T> inline void saveAndIncrease( const T&, uint8_t*& );
     48    template <class T> inline void saveAndIncrease( const T& variable, uint8_t*& mem );
    5049    /** @brief checks whether the variable of type T is the same as in the bytestream */
    51     template <class T> inline  bool checkEquality( const T&, uint8_t* );
     50    template <class T> inline bool checkEquality( const T& variable, uint8_t* mem );
    5251
    5352// =================== Template specialisation stuff =============
     
    203202        return sizeof(uint32_t);
    204203    }
    205    
     204
    206205    template <> inline void loadAndIncrease( const unsigned int& variable, uint8_t*& mem )
    207206    {
     
    376375        double temp;
    377376        memcpy(&temp, mem, sizeof(uint64_t));
    378         *(long double*)( &variable ) = static_cast<const long double>(temp);
     377        *(long double*)( &variable ) = static_cast<long double>(temp);
    379378        mem += returnSize( variable );
    380379    }
     
    471470        return variable==Degree(*r);
    472471    }
    473    
    474    
     472
     473    // =========== Vector2
     474
     475    template <> inline uint32_t returnSize( const Vector2& variable )
     476    {
     477        return returnSize( variable.x )+returnSize( variable.y );
     478    }
     479
     480    template <> inline void saveAndIncrease( const Vector2& variable, uint8_t*& mem )
     481    {
     482        saveAndIncrease( variable.x, mem );
     483        saveAndIncrease( variable.y, mem );
     484    }
     485
     486    template <> inline void loadAndIncrease( const Vector2& variable, uint8_t*& mem )
     487    {
     488        loadAndIncrease( variable.x, mem );
     489        loadAndIncrease( variable.y, mem );
     490    }
     491
     492    template <> inline bool checkEquality( const Vector2& variable, uint8_t* mem )
     493    {
     494        return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x));
     495    }
     496
     497    // =========== Vector3
     498
     499    template <> inline uint32_t returnSize( const Vector3& variable )
     500    {
     501        return returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z );
     502    }
     503
     504    template <> inline void saveAndIncrease( const Vector3& variable, uint8_t*& mem )
     505    {
     506        saveAndIncrease( variable.x, mem );
     507        saveAndIncrease( variable.y, mem );
     508        saveAndIncrease( variable.z, mem );
     509    }
     510
     511    template <> inline void loadAndIncrease( const Vector3& variable, uint8_t*& mem )
     512    {
     513        loadAndIncrease( variable.x, mem );
     514        loadAndIncrease( variable.y, mem );
     515        loadAndIncrease( variable.z, mem );
     516    }
     517
     518    template <> inline bool checkEquality( const Vector3& variable, uint8_t* mem )
     519    {
     520        return checkEquality(variable.x, mem) && checkEquality(variable.y, mem+returnSize(variable.x)) &&
     521            checkEquality(variable.z, mem+returnSize(variable.x)+returnSize(variable.y));
     522    }
     523
     524    // =========== Vector4
     525
     526    template <> inline uint32_t returnSize( const Vector4& variable )
     527    {
     528        return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z );
     529    }
     530
     531    template <> inline void saveAndIncrease( const Vector4& variable, uint8_t*& mem )
     532    {
     533        saveAndIncrease( variable.w, mem );
     534        saveAndIncrease( variable.x, mem );
     535        saveAndIncrease( variable.y, mem );
     536        saveAndIncrease( variable.z, mem );
     537    }
     538
     539    template <> inline void loadAndIncrease( const Vector4& variable, uint8_t*& mem )
     540    {
     541        loadAndIncrease( variable.w, mem );
     542        loadAndIncrease( variable.x, mem );
     543        loadAndIncrease( variable.y, mem );
     544        loadAndIncrease( variable.z, mem );
     545    }
     546
     547    template <> inline bool checkEquality( const Vector4& variable, uint8_t* mem )
     548    {
     549        return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) &&
     550            checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) &&
     551            checkEquality(variable.z, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y));
     552    }
     553
     554    // =========== Quaternion
     555
     556    template <> inline uint32_t returnSize( const Quaternion& variable )
     557    {
     558        return returnSize( variable.w )+returnSize( variable.x )+returnSize( variable.y )+returnSize( variable.z );
     559    }
     560
     561    template <> inline void saveAndIncrease( const Quaternion& variable, uint8_t*& mem )
     562    {
     563        saveAndIncrease( variable.w, mem );
     564        saveAndIncrease( variable.x, mem );
     565        saveAndIncrease( variable.y, mem );
     566        saveAndIncrease( variable.z, mem );
     567    }
     568
     569    template <> inline void loadAndIncrease( const Quaternion& variable, uint8_t*& mem )
     570    {
     571        loadAndIncrease( variable.w, mem );
     572        loadAndIncrease( variable.x, mem );
     573        loadAndIncrease( variable.y, mem );
     574        loadAndIncrease( variable.z, mem );
     575    }
     576
     577    template <> inline bool checkEquality( const Quaternion& variable, uint8_t* mem )
     578    {
     579        return checkEquality(variable.w, mem) && checkEquality(variable.x, mem+returnSize(variable.w)) &&
     580            checkEquality(variable.y, mem+returnSize(variable.w)+returnSize(variable.x)) &&
     581            checkEquality(variable.z, mem+returnSize(variable.w)+returnSize(variable.x)+returnSize(variable.y));
     582    }
     583
     584    // =========== ColourValue
     585
     586    template <> inline uint32_t returnSize( const ColourValue& variable )
     587    {
     588        return returnSize( variable.r )+returnSize( variable.g )+returnSize( variable.b )+returnSize( variable.a );
     589    }
     590
     591    template <> inline void saveAndIncrease( const ColourValue& variable, uint8_t*& mem )
     592    {
     593        saveAndIncrease( variable.r, mem );
     594        saveAndIncrease( variable.g, mem );
     595        saveAndIncrease( variable.b, mem );
     596        saveAndIncrease( variable.a, mem );
     597    }
     598
     599    template <> inline void loadAndIncrease( const ColourValue& variable, uint8_t*& mem )
     600    {
     601        loadAndIncrease( variable.r, mem );
     602        loadAndIncrease( variable.g, mem );
     603        loadAndIncrease( variable.b, mem );
     604        loadAndIncrease( variable.a, mem );
     605    }
     606
     607    template <> inline bool checkEquality( const ColourValue& variable, uint8_t* mem )
     608    {
     609        return checkEquality(variable.r, mem) && checkEquality(variable.g, mem+returnSize(variable.r)) &&
     610            checkEquality(variable.b, mem+returnSize(variable.r)+returnSize(variable.g)) &&
     611            checkEquality(variable.a, mem+returnSize(variable.r)+returnSize(variable.g)+returnSize(variable.b));
     612    }
     613
     614    // =========== mbool
     615
     616    template <> inline uint32_t returnSize( const mbool& variable )
     617    {
     618        return returnSize( (unsigned char&)((mbool&)variable).getMemory() );
     619    }
     620
     621    template <> inline void saveAndIncrease( const mbool& variable, uint8_t*& mem )
     622    {
     623        saveAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem );
     624    }
     625
     626    template <> inline void loadAndIncrease( const mbool& variable, uint8_t*& mem )
     627    {
     628        loadAndIncrease( (unsigned char&)((mbool&)variable).getMemory(), mem );
     629    }
     630
     631    template <> inline bool checkEquality( const mbool& variable, uint8_t* mem )
     632    {
     633        return checkEquality( (unsigned char&)((mbool&)variable).getMemory(), mem );
     634    }
    475635}
    476636
  • code/branches/pickup2/src/libraries/util/Singleton.h

    r5929 r6412  
    5656
    5757        //! Update method called by ClassSingletonManager (if used)
    58         void updateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->update(time); }
     58        void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }
    5959        //! Empty update method for the static polymorphism
    60         void update(const Clock& time) { }
     60        void preUpdate(const Clock& time) { }
     61        //! Update method called by ClassSingletonManager (if used)
     62        void postUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->postUpdate(time); }
     63        //! Empty update method for the static polymorphism
     64        void postUpdate(const Clock& time) { }
    6165
    6266    protected:
  • code/branches/pickup2/src/libraries/util/StringUtils.cc

    r5738 r6412  
    4040namespace orxonox
    4141{
    42     std::string BLANKSTRING("");
     42    std::string BLANKSTRING;
    4343
    4444    std::string getUniqueNumberString()
     
    5454    {
    5555        size_t pos;
    56         while ((pos = (*str).find(" ")) < (*str).length())
    57             (*str).erase(pos, 1);
    58         while ((pos = (*str).find("\t")) < (*str).length())
    59             (*str).erase(pos, 1);
    60         while ((pos = (*str).find("\n")) < (*str).length())
    61             (*str).erase(pos, 1);
     56        while ((pos = str->find(' ')) < str->length())
     57            str->erase(pos, 1);
     58        while ((pos = str->find('\t')) < str->length())
     59            str->erase(pos, 1);
     60        while ((pos = str->find('\n')) < str->length())
     61            str->erase(pos, 1);
    6262    }
    6363
     
    6969    std::string getStripped(const std::string& str)
    7070    {
    71         std::string output = std::string(str);
     71        std::string output(str);
    7272        strip(&output);
    7373        return output;
     
    9898        size_t quote = start - 1;
    9999
    100         while ((quote = str.find('\"', quote + 1)) != std::string::npos)
     100        while ((quote = str.find('"', quote + 1)) != std::string::npos)
    101101        {
    102102            size_t backslash = quote;
     
    231231    {
    232232        // Strip the line, whitespaces are disturbing
    233         std::string teststring = getStripped(str);
     233        const std::string& teststring = getStripped(str);
    234234
    235235        // There are four possible comment-symbols:
     
    259259    bool isEmpty(const std::string& str)
    260260    {
    261         std::string temp = getStripped(str);
    262         return ((temp == "") || (temp.size() == 0));
     261        return getStripped(str).empty();
    263262    }
    264263
     
    303302        for (size_t pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\f"); }
    304303        for (size_t pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\a"); }
    305         for (size_t pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
     304        for (size_t pos = 0; (pos = output.find('"' , pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\\""); }
    306305        for (size_t pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 1, "\\0"); }
    307306
     
    319318            return str;
    320319
    321         std::string output = "";
     320        std::string output;
    322321        for (size_t pos = 0; pos < str.size() - 1; )
    323322        {
     
    363362    std::string getLowercase(const std::string& str)
    364363    {
    365         std::string output = std::string(str);
     364        std::string output(str);
    366365        lowercase(&output);
    367366        return output;
     
    387386    std::string getUppercase(const std::string& str)
    388387    {
    389         std::string output = std::string(str);
     388        std::string output(str);
    390389        uppercase(&output);
    391390        return output;
  • code/branches/pickup2/src/libraries/util/SubString.cc

    r5738 r6412  
    270270        }
    271271        else
    272         {
    273             static std::string empty;
    274             return empty;
    275         }
     272            return "";
    276273    }
    277274
     
    557554    void SubString::debug() const
    558555    {
    559         printf("Substring-information::count=%d ::", this->strings.size());
     556        printf("Substring-information::count=%zd ::", this->strings.size());
    560557        for (unsigned int i = 0; i < this->strings.size(); i++)
    561558            printf("s%d='%s'::", i, this->strings[i].c_str());
  • code/branches/pickup2/src/libraries/util/UtilPrereqs.h

    r5929 r6412  
    8787    class IntVector3;
    8888    class MultiType;
    89     class OutputBuffer;
    90     class OutputBufferListener;
    9189    class OutputHandler;
     90    class OutputListener;
    9291    template <ScopeID::Value>
    9392    class Scope;
     
    132131}
    133132
     133// Just so you don't have to include StringUtils.h everywhere just for this
     134namespace orxonox
     135{
     136    extern _UtilExport std::string BLANKSTRING;
     137}
     138
     139
    134140#endif /* _UtilPrereqs_H__ */
  • code/branches/pickup2/src/libraries/util/mbool.h

    r5738 r6412  
    6767            inline bool operator!() const
    6868                { return (!this->value_.bool_); }
    69            
     69
    7070            inline unsigned char& getMemory(){ return value_.memory_; }
    7171
Note: See TracChangeset for help on using the changeset viewer.