Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 14, 2009, 12:43:52 PM (15 years ago)
Author:
rgrieder
Message:

Merged some code work from the Gruppenarbeit.

Location:
code/branches/pch/src/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pch/src/util/Exception.cc

    r3068 r3166  
    3737namespace orxonox
    3838{
    39     Exception::Exception(const std::string& description, int lineNumber,
     39    Exception::Exception(const std::string& description, unsigned int lineNumber,
    4040                         const char* filename, const char* functionName)
    4141        : description_(description)
     
    5252    { }
    5353
     54    /**
     55    @remarks
     56        The composed full description gets stored to fullDescription_. But for compliance
     57        with std::exception, this method has to be const. Hence fullDescription_ is declared
     58        as mutable.
     59    */
    5460    const std::string& Exception::getFullDescription() const
    5561    {
  • code/branches/pch/src/util/Exception.h

    r3162 r3166  
    3030@file
    3131@brief
    32     Declaration of the Exception class.
     32    Declaration of facilities to handle exceptions.
    3333*/
    3434
     
    4545namespace orxonox
    4646{
     47    /**
     48    @brief
     49        Base class for all exceptions (derived from std::exception).
     50    @details
     51        This class provides support for information about the file, the line
     52        and the function the error occured.
     53    */
    4754    class _UtilExport Exception : public std::exception
    4855    {
    4956    public:
    50 
    51         Exception(const std::string& description, int lineNumber,
     57        /**
     58        @brief
     59            Creates the exception but doesn't yet compose the full descrption (because of the virtual functions)
     60        @param description
     61            Exception description as string. This message is supposed to help developers!
     62        */
     63        Exception(const std::string& description, unsigned int lineNumber,
    5264                  const char* filename, const char* functionName);
     65        //! Simplified constructor with just a description. If you need more, use the other one.
    5366        Exception(const std::string& description);
    5467
    55         /// Needed for  compatibility with std::exception (from Ogre::Exception)
     68        //! Needed for compatibility with std::exception
    5669        virtual ~Exception() throw() { }
    5770
     71        //! Returns a full description with type, line, file and function
    5872        virtual const std::string& getFullDescription() const;
     73        //! Returns the string name of the exception type
    5974        virtual std::string        getTypeName()        const = 0;
     75        //! Returns the short developer written exception
    6076        virtual const std::string& getDescription()     const { return this->description_; }
    61         virtual const int          getLineNumber()      const { return this->lineNumber_; }
     77        //! Returns the line number on which the exception occurred.
     78        virtual const unsigned int getLineNumber()      const { return this->lineNumber_; }
     79        //! Returns the function in which the exception occurred.
    6280        virtual const std::string& getFunctionName()    const { return this->functionName_; }
     81        //! Returns the filename in which the exception occurred.
     82        virtual const std::string& getFilename()        const { return this->filename_; }
    6383
    64         /// Override std::exception::what (from Ogre::Exception)
     84        //! Returns a full description of the error.
    6585        const char* what() const throw() { return getFullDescription().c_str(); }
    6686
    6787    protected:
    68         std::string description_;
    69         int lineNumber_;
    70         std::string functionName_;
    71         std::string filename_;
     88        std::string description_;             //!< User typed text about why the exception occurred
     89        unsigned int lineNumber_;             //!< Line on which the exception occurred
     90        std::string functionName_;            //!< Function (including namespace and class) where the exception occurred
     91        std::string filename_;                //!< File where the exception occurred
    7292        // mutable because "what()" is a const method
    73         mutable std::string fullDescription_;
     93        mutable std::string fullDescription_; //!< Full description with line, file and function
    7494    };
    7595
    76 
     96//! Creates a new type of exception that inherits from tracker::Exception
    7797#define CREATE_ORXONOX_EXCEPTION(ExceptionName)                                     \
    7898    class ExceptionName##Exception : public Exception                               \
    7999    {                                                                               \
    80100    public:                                                                         \
    81         ExceptionName##Exception(const std::string& description, int lineNumber,    \
    82                   const char* filename, const char* functionName)                   \
    83                   : Exception(description, lineNumber, filename, functionName)      \
     101        ExceptionName##Exception(const std::string& description,                    \
     102                unsigned int lineNumber, const char* filename,                      \
     103                const char* functionName)                                           \
     104            : Exception(description, lineNumber, filename, functionName)            \
    84105        { }                                                                         \
    85106                                                                                    \
    86107        ExceptionName##Exception(const std::string& description)                    \
    87                   : Exception(description)                                          \
     108            : Exception(description)                                                \
    88109        { }                                                                         \
    89110                                                                                    \
     
    91112                                                                                    \
    92113        std::string getTypeName() const { return #ExceptionName; }                  \
    93     };
     114    }
    94115
    95116    // Creates all possible exception types.
    96117    // If you want to add a new type, simply copy and adjust a new line here.
     118#ifndef DOXYGEN_SHOULD_SKIP_THIS
    97119    CREATE_ORXONOX_EXCEPTION(General);
    98120    CREATE_ORXONOX_EXCEPTION(FileNotFound);
     
    106128    CREATE_ORXONOX_EXCEPTION(NoGraphics);
    107129    CREATE_ORXONOX_EXCEPTION(AbortLoading);
    108 }
     130#endif
    109131
    110132    /**
    111133    @brief
    112         Helper function that creates an exception, displays the message, but doesn't throw it.
     134        Helper function that forwards an exception and displays the message.
     135    @details
     136        This is necessary because only when using 'throw' the objects storage is managed.
    113137    */
    114138    template <class T>
    115     inline const T& InternalHandleException(const T& exception)
     139    inline const T& exceptionThrowerHelper(const T& exception)
    116140    {
    117141        // let the catcher decide whether to display the message below level 4
     
    120144    }
    121145
    122 #define ThrowException(type, description) \
    123     throw InternalHandleException(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__))
     146/**
     147@brief
     148    Throws an exception and logs a message beforehand.
     149@param type
     150    Type of the exception as literal (General, Initialisation, etc.)
     151@param description
     152    Exception description as string
     153*/
     154#define ThrowException(type, description, ...) \
     155    throw orxonox::exceptionThrowerHelper(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__))
     156
     157} /* namespace orxonox */
    124158
    125159#endif /* _Exception_H__ */
  • code/branches/pch/src/util/Sleep.cc

    r3146 r3166  
    2828
    2929/**
    30     @file
    31     @brief Implementation of three sleep functions.
     30@file
     31@brief
     32    Implementation of three sleep functions. Avoids including windows.h
    3233*/
    3334
  • code/branches/pch/src/util/Sleep.h

    r2773 r3166  
    2828
    2929/**
    30  @file
    31  @brief
    32     Functions for using sleep() and usleep() on windows.
     30@file
     31@brief
     32    Functions declarations to make the current thread sleep.
    3333 */
    3434
     
    4040namespace orxonox
    4141{
     42    //! Makes the thread sleep for a few @a microseconds
    4243    _UtilExport void usleep(unsigned long microseconds);
     44    //! Makes the thread sleep for a few @a milliseconds
    4345    _UtilExport void msleep(unsigned long milliseconds);
     46    //! Makes the thread sleep for a few @a seconds
    4447    _UtilExport void sleep (unsigned long seconds);
    4548}
Note: See TracChangeset for help on using the changeset viewer.