[Orxonox-commit 634] r3166 - in branches/pch/src: core util
rgrieder at orxonox.net
rgrieder at orxonox.net
Sun Jun 14 12:43:53 CEST 2009
Author: rgrieder
Date: 2009-06-14 12:43:52 +0200 (Sun, 14 Jun 2009)
New Revision: 3166
Modified:
branches/pch/src/core/Core.cc
branches/pch/src/core/Core.h
branches/pch/src/util/Exception.cc
branches/pch/src/util/Exception.h
branches/pch/src/util/Sleep.cc
branches/pch/src/util/Sleep.h
Log:
Merged some code work from the Gruppenarbeit.
Modified: branches/pch/src/core/Core.cc
===================================================================
--- branches/pch/src/core/Core.cc 2009-06-14 09:52:50 UTC (rev 3165)
+++ branches/pch/src/core/Core.cc 2009-06-14 10:43:52 UTC (rev 3166)
@@ -28,8 +28,9 @@
*/
/**
- @file
- @brief Implementation of the Core class.
+ at file
+ at brief
+ Implementation of the Core singleton with its global variables (avoids boost include)
*/
#include "Core.h"
@@ -80,6 +81,7 @@
static boost::filesystem::path configPath_g; //!< Path to the config file folder
static boost::filesystem::path logPath_g; //!< Path to the log file folder
+ //! Static pointer to the singleton
Core* Core::singletonRef_s = 0;
SetCommandLineArgument(mediaPath, "").information("PATH");
@@ -471,6 +473,8 @@
Checks for "orxonox_dev_build.keep_me" in the executable diretory.
If found it means that this is not an installed run, hence we
don't write the logs and config files to ~/.orxonox
+ @throws
+ GeneralException
*/
void Core::checkDevBuild()
{
@@ -531,14 +535,14 @@
@brief
Checks for the log and the config directory and creates them
if necessary. Otherwise me might have problems opening those files.
+ @throws
+ orxonox::GeneralException if the directory to be created is a file.
*/
void Core::createDirectories()
{
std::vector<std::pair<boost::filesystem::path, std::string> > directories;
- directories.push_back(std::pair<boost::filesystem::path, std::string>
- (boost::filesystem::path(configPath_g), "config"));
- directories.push_back(std::pair<boost::filesystem::path, std::string>
- (boost::filesystem::path(logPath_g), "log"));
+ directories.push_back(std::make_pair(boost::filesystem::path(configPath_g), "config"));
+ directories.push_back(std::make_pair(boost::filesystem::path(logPath_g), "log"));
for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();
it != directories.end(); ++it)
Modified: branches/pch/src/core/Core.h
===================================================================
--- branches/pch/src/core/Core.h 2009-06-14 09:52:50 UTC (rev 3165)
+++ branches/pch/src/core/Core.h 2009-06-14 10:43:52 UTC (rev 3166)
@@ -28,9 +28,10 @@
*/
/**
- @file
- @brief Declaration of the Core class.
-
+ at file
+ at brief
+ Declaration of the Core class.
+ at details
The Core class is a singleton, only used to configure some variables
in the core through the config-file.
*/
@@ -46,10 +47,23 @@
namespace orxonox
{
- //! The Core class is a singleton, only used to configure some config-values.
+ /**
+ @brief
+ The Core class is a singleton used to configure the program basics.
+ @details
+ The class provides information about the media, config and log path.
+ It determines those by the use of platform specific functions.
+ */
class _CoreExport Core : public OrxonoxClass
{
public:
+ /**
+ @brief
+ Determines the executable path, checks for build directory runs, creates
+ the output directories and sets up the other core library singletons.
+ @throws
+ GeneralException
+ */
Core();
~Core();
@@ -67,15 +81,21 @@
static void tsetMediaPath(const std::string& path)
{ assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); }
+ //! Returns the path to the config files as boost::filesystem::path
static const boost::filesystem::path& getMediaPath();
+ //! Returns the path to the config files as boost::filesystem::path
static const boost::filesystem::path& getConfigPath();
+ //! Returns the path to the log files as boost::filesystem::path
static const boost::filesystem::path& getLogPath();
+ //! Returns the path to the data files as std::string
static std::string getMediaPathString();
+ //! Returns the path to the config files as std::string
static std::string getConfigPathString();
+ //! Returns the path to the log files as std::string
static std::string getLogPathString();
private:
- Core(const Core&);
+ Core(const Core&); //!< Don't use (undefined symbol)
void checkDevBuild();
void setExecutablePath();
Modified: branches/pch/src/util/Exception.cc
===================================================================
--- branches/pch/src/util/Exception.cc 2009-06-14 09:52:50 UTC (rev 3165)
+++ branches/pch/src/util/Exception.cc 2009-06-14 10:43:52 UTC (rev 3166)
@@ -36,7 +36,7 @@
namespace orxonox
{
- Exception::Exception(const std::string& description, int lineNumber,
+ Exception::Exception(const std::string& description, unsigned int lineNumber,
const char* filename, const char* functionName)
: description_(description)
, lineNumber_(lineNumber)
@@ -51,6 +51,12 @@
, filename_("")
{ }
+ /**
+ @remarks
+ The composed full description gets stored to fullDescription_. But for compliance
+ with std::exception, this method has to be const. Hence fullDescription_ is declared
+ as mutable.
+ */
const std::string& Exception::getFullDescription() const
{
if (fullDescription_ == "")
Modified: branches/pch/src/util/Exception.h
===================================================================
--- branches/pch/src/util/Exception.h 2009-06-14 09:52:50 UTC (rev 3165)
+++ branches/pch/src/util/Exception.h 2009-06-14 10:43:52 UTC (rev 3166)
@@ -29,7 +29,7 @@
/**
@file
@brief
- Declaration of the Exception class.
+ Declaration of facilities to handle exceptions.
*/
#ifndef _Exception_H__
@@ -44,56 +44,78 @@
namespace orxonox
{
+ /**
+ @brief
+ Base class for all exceptions (derived from std::exception).
+ @details
+ This class provides support for information about the file, the line
+ and the function the error occured.
+ */
class _UtilExport Exception : public std::exception
{
public:
-
- Exception(const std::string& description, int lineNumber,
+ /**
+ @brief
+ Creates the exception but doesn't yet compose the full descrption (because of the virtual functions)
+ @param description
+ Exception description as string. This message is supposed to help developers!
+ */
+ Exception(const std::string& description, unsigned int lineNumber,
const char* filename, const char* functionName);
+ //! Simplified constructor with just a description. If you need more, use the other one.
Exception(const std::string& description);
- /// Needed for compatibility with std::exception (from Ogre::Exception)
+ //! Needed for compatibility with std::exception
virtual ~Exception() throw() { }
+ //! Returns a full description with type, line, file and function
virtual const std::string& getFullDescription() const;
+ //! Returns the string name of the exception type
virtual std::string getTypeName() const = 0;
+ //! Returns the short developer written exception
virtual const std::string& getDescription() const { return this->description_; }
- virtual const int getLineNumber() const { return this->lineNumber_; }
+ //! Returns the line number on which the exception occurred.
+ virtual const unsigned int getLineNumber() const { return this->lineNumber_; }
+ //! Returns the function in which the exception occurred.
virtual const std::string& getFunctionName() const { return this->functionName_; }
+ //! Returns the filename in which the exception occurred.
+ virtual const std::string& getFilename() const { return this->filename_; }
- /// Override std::exception::what (from Ogre::Exception)
+ //! Returns a full description of the error.
const char* what() const throw() { return getFullDescription().c_str(); }
protected:
- std::string description_;
- int lineNumber_;
- std::string functionName_;
- std::string filename_;
+ std::string description_; //!< User typed text about why the exception occurred
+ unsigned int lineNumber_; //!< Line on which the exception occurred
+ std::string functionName_; //!< Function (including namespace and class) where the exception occurred
+ std::string filename_; //!< File where the exception occurred
// mutable because "what()" is a const method
- mutable std::string fullDescription_;
+ mutable std::string fullDescription_; //!< Full description with line, file and function
};
-
+//! Creates a new type of exception that inherits from tracker::Exception
#define CREATE_ORXONOX_EXCEPTION(ExceptionName) \
class ExceptionName##Exception : public Exception \
{ \
public: \
- ExceptionName##Exception(const std::string& description, int lineNumber, \
- const char* filename, const char* functionName) \
- : Exception(description, lineNumber, filename, functionName) \
+ ExceptionName##Exception(const std::string& description, \
+ unsigned int lineNumber, const char* filename, \
+ const char* functionName) \
+ : Exception(description, lineNumber, filename, functionName) \
{ } \
\
ExceptionName##Exception(const std::string& description) \
- : Exception(description) \
+ : Exception(description) \
{ } \
\
~ExceptionName##Exception() throw() { } \
\
std::string getTypeName() const { return #ExceptionName; } \
- };
+ }
// Creates all possible exception types.
// If you want to add a new type, simply copy and adjust a new line here.
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
CREATE_ORXONOX_EXCEPTION(General);
CREATE_ORXONOX_EXCEPTION(FileNotFound);
CREATE_ORXONOX_EXCEPTION(Argument);
@@ -105,21 +127,33 @@
CREATE_ORXONOX_EXCEPTION(GameState);
CREATE_ORXONOX_EXCEPTION(NoGraphics);
CREATE_ORXONOX_EXCEPTION(AbortLoading);
-}
+#endif
/**
@brief
- Helper function that creates an exception, displays the message, but doesn't throw it.
+ Helper function that forwards an exception and displays the message.
+ @details
+ This is necessary because only when using 'throw' the objects storage is managed.
*/
template <class T>
- inline const T& InternalHandleException(const T& exception)
+ inline const T& exceptionThrowerHelper(const T& exception)
{
// let the catcher decide whether to display the message below level 4
COUT(4) << exception.getFullDescription() << std::endl;
return exception;
}
-#define ThrowException(type, description) \
- throw InternalHandleException(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__))
+/**
+ at brief
+ Throws an exception and logs a message beforehand.
+ at param type
+ Type of the exception as literal (General, Initialisation, etc.)
+ at param description
+ Exception description as string
+*/
+#define ThrowException(type, description, ...) \
+ throw orxonox::exceptionThrowerHelper(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__))
+} /* namespace orxonox */
+
#endif /* _Exception_H__ */
Modified: branches/pch/src/util/Sleep.cc
===================================================================
--- branches/pch/src/util/Sleep.cc 2009-06-14 09:52:50 UTC (rev 3165)
+++ branches/pch/src/util/Sleep.cc 2009-06-14 10:43:52 UTC (rev 3166)
@@ -27,8 +27,9 @@
*/
/**
- @file
- @brief Implementation of three sleep functions.
+ at file
+ at brief
+ Implementation of three sleep functions. Avoids including windows.h
*/
#include "Sleep.h"
Modified: branches/pch/src/util/Sleep.h
===================================================================
--- branches/pch/src/util/Sleep.h 2009-06-14 09:52:50 UTC (rev 3165)
+++ branches/pch/src/util/Sleep.h 2009-06-14 10:43:52 UTC (rev 3166)
@@ -27,9 +27,9 @@
*/
/**
- @file
- @brief
- Functions for using sleep() and usleep() on windows.
+ at file
+ at brief
+ Functions declarations to make the current thread sleep.
*/
#ifndef _Sleep_H__
@@ -39,8 +39,11 @@
namespace orxonox
{
+ //! Makes the thread sleep for a few @a microseconds
_UtilExport void usleep(unsigned long microseconds);
+ //! Makes the thread sleep for a few @a milliseconds
_UtilExport void msleep(unsigned long milliseconds);
+ //! Makes the thread sleep for a few @a seconds
_UtilExport void sleep (unsigned long seconds);
}
More information about the Orxonox-commit
mailing list