[Orxonox-commit 1273] r5991 - in code/branches/console/src/libraries: core core/input util
rgrieder at orxonox.net
rgrieder at orxonox.net
Sat Oct 24 23:35:31 CEST 2009
Author: rgrieder
Date: 2009-10-24 23:35:31 +0200 (Sat, 24 Oct 2009)
New Revision: 5991
Modified:
code/branches/console/src/libraries/core/OrxonoxClass.h
code/branches/console/src/libraries/core/input/InputManager.cc
code/branches/console/src/libraries/util/Debug.h
code/branches/console/src/libraries/util/OutputHandler.h
Log:
Replaced the load of macros in Debug.h with just two, doing almost exactly the same. The only difference is that the compiler can now completely eliminate COUT with a level higher than the hard debug level.
Modified: code/branches/console/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/branches/console/src/libraries/core/OrxonoxClass.h 2009-10-23 12:14:40 UTC (rev 5990)
+++ code/branches/console/src/libraries/core/OrxonoxClass.h 2009-10-24 21:35:31 UTC (rev 5991)
@@ -42,6 +42,13 @@
#include <set>
#include <vector>
+/**
+ at def CCOUT
+ Acts almost exactly like COUT(x), but prepends "ClassName: "
+*/
+#define CCOUT(level) \
+ COUT(level) << this->getIdentifier()->getName() << ": "
+
namespace orxonox
{
//! The class all objects and interfaces of the game-logic (not the engine) are derived from.
Modified: code/branches/console/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/console/src/libraries/core/input/InputManager.cc 2009-10-23 12:14:40 UTC (rev 5990)
+++ code/branches/console/src/libraries/core/input/InputManager.cc 2009-10-24 21:35:31 UTC (rev 5991)
@@ -189,7 +189,7 @@
oisInputManager_ = OIS::InputManager::createInputSystem(paramList);
// Exception-safety
Loki::ScopeGuard guard = Loki::MakeGuard(OIS::InputManager::destroyInputSystem, oisInputManager_);
- CCOUT(ORX_DEBUG) << "Created OIS input manager." << std::endl;
+ CCOUT(4) << "Created OIS input manager." << std::endl;
if (oisInputManager_->getNumberOfDevices(OIS::OISKeyboard) > 0)
devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard, oisInputManager_);
@@ -231,7 +231,7 @@
}
}
else
- CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
+ CCOUT(2) << "Warning: No mouse found! Proceeding without mouse support." << std::endl;
}
//! Creates as many joy sticks as are available.
Modified: code/branches/console/src/libraries/util/Debug.h
===================================================================
--- code/branches/console/src/libraries/util/Debug.h 2009-10-23 12:14:40 UTC (rev 5990)
+++ code/branches/console/src/libraries/util/Debug.h 2009-10-24 21:35:31 UTC (rev 5991)
@@ -20,23 +20,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Benjamin Grauer
- * Co-authors:
* Fabian 'x3n' Landau
+ * Reto Grieder
+ * Co-authors:
+ * ...
*
*/
/**
- @file
- @brief Handles different output-levels of errors, warnings, infos and debug information.
+ at file
+ at brief
+ Handles different output-levels of errors, warnings, infos and debug information.
The COUT(level) macro acts like std::cout, but the output is only performed if the given
level is <= the soft debug level.
There are two used values in this file:
- - The hard debug level is used during compiletime. It describes the highest allowed output level.
+ - The hard debug level is used during compile time. It describes the highest allowed output level.
- The soft debug level is used during runtime and is the maximum of the three configurable
- output-levels for console, logfile and ingame shell.
+ output-levels for console, log file and in game shell.
The separation between the three devices is done by the OutputHandler.
@@ -49,211 +51,45 @@
5: More debug information
6: Crazy debug information
- @example
+ at example
COUT(0) << "Very important output" << std::endl;
COUT(1) << "Error: Something went wrong!" << std::endl;
COUT(2) << "Warning: There might be a problem." << std::endl;
- COUT(3) << "Info: It's monday" << std::endl;
+ COUT(3) << "Info: It's Monday" << std::endl;
COUT(4) << "Debug: x is 1.23456" << std::endl;
- */
+*/
-#ifndef _Debug_H__
-#define _Debug_H__
+#ifndef _Util_Debug_H__
+#define _Util_Debug_H__
#include "UtilPrereqs.h"
-
#include "OutputHandler.h"
namespace orxonox
{
- /**
- @brief Returns the soft debug level, stored in the only existing instance of the OutputHandler class, configured in the config-file.
- @return The soft debug level
- */
- inline int getSoftDebugLevel()
- {
- return OutputHandler::getSoftDebugLevel();
- }
-
+ // Just for convenience
using std::endl;
+
+ //! Adjust to discard certain output with level > hardDebugLevel at compile time
+ const int hardDebugLevel = OutputLevel::Verbose;
}
-// DEFINE ERROR MODES
-#define ORX_NONE 0
-#define ORX_ERROR 1
-#define ORX_WARNING 2
-#define ORX_INFO 3
-#define ORX_DEBUG 4
-#define ORX_VERBOSE 5
-#define ORX_ULTRA 6
+/**
+ at def COUT
+ Logs text output: use exactly like std::cout, but specify an output
+ level as argument. For example COUT(3) << "Some info" << std::endl;
+ at note
+ The ? : operator requires both possible results to have the type of
+ the first. This is achieved by the int conversion operator dummy
+ in the OutputHandler.
+*/
+#define COUT(level) \
+ /*if*/ (level > orxonox::hardDebugLevel) ? \
+ 0 \
+ /*else*/ : \
+ /*if*/ (level > orxonox::OutputHandler::getSoftDebugLevel()) ? \
+ 0 \
+ /*else*/ : \
+ orxonox::OutputHandler::getOutStream(level)
-//definitions
-#define ORX_PRINT_DEBUG_OUTPUT 1
-#define ORX_HARD_DEBUG_LEVEL ORX_VERBOSE
-
-#define COUT_EXEC(x) orxonox::OutputHandler::getOutStream().setOutputLevel(x)
-
-////////////////////////////////////////////////////////
-/// COUT: just prints output as is with std::cout ///
-////////////////////////////////////////////////////////
-#define COUTORX_NONE COUT0
-#define COUTORX_ERROR COUT1
-#define COUTORX_WARNING COUT2
-#define COUTORX_INFO COUT3
-#define COUTORX_DEBUG COUT4
-#define COUTORX_VERBOSE COUT5
-#define COUTORX_ULTRA COUT6
-
-#ifndef COUT
- #if ORX_PRINT_DEBUG_OUTPUT
- #define COUT(x) \
- COUT ## x
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
- #define COUT0 \
- (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : COUT_EXEC(0)
- #else
- #define COUT0 \
- false ? COUT_EXEC(0) : COUT_EXEC(0)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
- #define COUT1 \
- (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : COUT_EXEC(1)
- #else
- #define COUT1 \
- false ? COUT_EXEC(1) : COUT_EXEC(1)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
- #define COUT2 \
- (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : COUT_EXEC(2)
- #else
- #define COUT2 \
- false ? COUT_EXEC(2) : COUT_EXEC(2)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
- #define COUT3 \
- (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : COUT_EXEC(3)
- #else
- #define COUT3 \
- false ? COUT_EXEC(3) : COUT_EXEC(3)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
- #define COUT4 \
- (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : COUT_EXEC(4)
- #else
- #define COUT4 \
- false ? COUT_EXEC(4) : COUT_EXEC(4)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
- #define COUT5 \
- (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : COUT_EXEC(5)
- #else
- #define COUT5 \
- false ? COUT_EXEC(5) : COUT_EXEC(5)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
- #define COUT6 \
- (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : COUT_EXEC(6)
- #else
- #define COUT6 \
- false ? COUT_EXEC(6) : COUT_EXEC(6)
- #endif
-
- #else /* if ORX_PRINT_DEBUG_OUTPUT */
- #define COUT(x) \
- false ? COUT_EXEC(6) : COUT_EXEC(6)
- #endif /* if ORX_PRINT_DEBUG_OUTPUT */
-
-#endif /* ifndef COUT */
-
-
-/////////////////////////////////////////////////////////////////////
-/// CCOUT: Prints output with std::cout and adds the classname ///
-/////////////////////////////////////////////////////////////////////
-#define CCOUTORX_NONE CCOUT0
-#define CCOUTORX_ERROR CCOUT1
-#define CCOUTORX_WARNING CCOUT2
-#define CCOUTORX_INFO CCOUT3
-#define CCOUTORX_DEBUG CCOUT4
-#define CCOUTORX_VERBOSE CCOUT5
-#define CCOUTORX_ULTRA CCOUT6
-
-#define CCOUT_EXEC(x) \
- orxonox::OutputHandler::getOutStream().setOutputLevel(x) \
- << this->getIdentifier()->getName() << ": "
-
-#ifndef CCOUT
- #if ORX_PRINT_DEBUG_OUTPUT
- #define CCOUT(x) \
- CCOUT ## x
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_NONE
- #define CCOUT0 \
- (orxonox::getSoftDebugLevel() < ORX_NONE) ? COUT_EXEC(0) : CCOUT_EXEC(0)
- #else
- #define CCOUT0 \
- false ? COUT_EXEC(0) : CCOUT_EXEC(0)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
- #define CCOUT1 \
- (orxonox::getSoftDebugLevel() < ORX_ERROR) ? COUT_EXEC(1) : CCOUT_EXEC(1)
- #else
- #define CCOUT1 \
- false ? COUT_EXEC(1) : CCOUT_EXEC(1)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
- #define CCOUT2 \
- (orxonox::getSoftDebugLevel() < ORX_WARNING) ? COUT_EXEC(2) : CCOUT_EXEC(2)
- #else
- #define CCOUT2 \
- false ? COUT_EXEC(2) : CCOUT_EXEC(2)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
- #define CCOUT3 \
- (orxonox::getSoftDebugLevel() < ORX_INFO) ? COUT_EXEC(3) : CCOUT_EXEC(3)
- #else
- #define CCOUT3 \
- false ? COUT_EXEC(3) : CCOUT_EXEC(3)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
- #define CCOUT4 \
- (orxonox::getSoftDebugLevel() < ORX_DEBUG) ? COUT_EXEC(4) : CCOUT_EXEC(4)
- #else
- #define CCOUT4 \
- false ? COUT_EXEC(4) : CCOUT_EXEC(4)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_VERBOSE
- #define CCOUT5 \
- (orxonox::getSoftDebugLevel() < ORX_VERBOSE) ? COUT_EXEC(5) : CCOUT_EXEC(5)
- #else
- #define CCOUT5 \
- false ? COUT_EXEC(5) : CCOUT_EXEC(5)
- #endif
-
- #if ORX_HARD_DEBUG_LEVEL >= ORX_ULTRA
- #define CCOUT6 \
- (orxonox::getSoftDebugLevel() < ORX_ULTRA) ? COUT_EXEC(6) : CCOUT_EXEC(6)
- #else
- #define CCOUT6 \
- false ? COUT_EXEC(6) : CCOUT_EXEC(6)
- #endif
-
- #else /* if ORX_PRINT_DEBUG_OUTPUT */
- #define CCOUT(x) \
- false ? CCOUT_EXEC(6) : CCOUT_EXEC(6)
- #endif /* if ORX_PRINT_DEBUG_OUTPUT */
-
-#endif /* ifndef CCOUT */
-
-#endif /* _Debug_H__ */
+#endif /* _Util_Debug_H__ */
Modified: code/branches/console/src/libraries/util/OutputHandler.h
===================================================================
--- code/branches/console/src/libraries/util/OutputHandler.h 2009-10-23 12:14:40 UTC (rev 5990)
+++ code/branches/console/src/libraries/util/OutputHandler.h 2009-10-24 21:35:31 UTC (rev 5991)
@@ -47,6 +47,20 @@
namespace orxonox
{
+ namespace OutputLevel
+ {
+ enum Value
+ {
+ None = 0,
+ Error = 1,
+ Warning = 2,
+ Info = 3,
+ Debug = 4,
+ Verbose = 5,
+ Ultra = 6,
+ };
+ }
+
//! The OutputHandler acts like std::cout, but redirects output to the console, the logfile and the ingame shell.
class _UtilExport OutputHandler
{
@@ -60,6 +74,8 @@
};
static OutputHandler& getOutStream();
+ static inline OutputHandler& getOutStream(int level)
+ { return OutputHandler::getOutStream().setOutputLevel(level); }
/** @brief Puts some text on the outstream. @param text The text */
static inline const std::string& log(const std::string& text)
@@ -142,6 +158,9 @@
OutputHandler& operator<<(std::ios& (*manipulator)(std::ios&));
OutputHandler& operator<<(std::ios_base& (*manipulator)(std::ios_base&));
+ /** @brief Dummy operator required by Debug.h for the ternary operator */
+ inline operator int() { return 0; }
+
private:
explicit OutputHandler();
OutputHandler(const OutputHandler& oh);
More information about the Orxonox-commit
mailing list