Changeset 699 for code/branches/FICN/src/orxonox/core
- Timestamp:
- Dec 27, 2007, 4:58:52 PM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/core/Debug.h
r684 r699 68 68 69 69 #define PRINT_EXEC printf 70 //#define COUT_EXEC std::cout 71 #define COUT_EXEC orxonox::OutputHandler::getOutStream()70 #define COUT_EXEC(x) \ 71 orxonox::OutputHandler::getOutStream().setOutputLevel(x) 72 72 73 73 #ifndef PRINTF … … 207 207 #define COUT1 \ 208 208 if (getSoftDebugLevel() >= ORX_ERROR) \ 209 COUT_EXEC 209 COUT_EXEC(1) 210 210 #else 211 211 #define COUT1 if (ORX_NONE)\ 212 COUT_EXEC 212 COUT_EXEC(1) 213 213 #endif 214 214 … … 216 216 #define COUT2 \ 217 217 if (getSoftDebugLevel() >= ORX_WARNING) \ 218 COUT_EXEC 218 COUT_EXEC(2) 219 219 #else 220 220 #define COUT2 if (ORX_NONE) \ 221 COUT_EXEC 221 COUT_EXEC(2) 222 222 #endif 223 223 … … 225 225 #define COUT3 \ 226 226 if (getSoftDebugLevel() >= ORX_INFO) \ 227 COUT_EXEC 227 COUT_EXEC(3) 228 228 #else 229 229 #define COUT3 if (ORX_NONE) \ 230 COUT_EXEC 230 COUT_EXEC(3) 231 231 #endif 232 232 … … 234 234 #define COUT4 \ 235 235 if (getSoftDebugLevel() >= ORX_DEBUG) \ 236 COUT_EXEC 236 COUT_EXEC(4) 237 237 #else 238 238 #define COUT4 if (ORX_NONE) \ 239 COUT_EXEC 239 COUT_EXEC(4) 240 240 #endif 241 241 … … 243 243 #define COUT5 \ 244 244 if (getSoftDebugLevel() >= ORX_vDEBUG) \ 245 COUT_EXEC 245 COUT_EXEC(5) 246 246 #else 247 247 #define COUT5 if (ORX_NONE) \ 248 COUT_EXEC 248 COUT_EXEC(5) 249 249 #endif 250 250 251 251 #else /* if ORX_PRINT_DEBUG_OUTPUT */ 252 252 #define COUT(x) if (ORX_NONE) \ 253 COUT_EXEC 253 COUT_EXEC(5) 254 254 #endif /* if ORX_PRINT_DEBUG_OUTPUT */ 255 255 256 256 #define COUT0 \ 257 COUT_EXEC 257 COUT_EXEC(0) 258 258 #endif /* ifndef COUT */ 259 259 -
code/branches/FICN/src/orxonox/core/DebugLevel.cc
r696 r699 32 32 33 33 #include "CoreIncludes.h" 34 #include "Debug.h"35 34 #include "DebugLevel.h" 36 35 … … 53 52 void DebugLevel::setConfigValues() 54 53 { 55 SetConfigValue(softDebugLevel_, 2); 54 SetConfigValue(softDebugLevelConsole_, 3); 55 SetConfigValue(softDebugLevelLogfile_, 3); 56 SetConfigValue(softDebugLevelShell_, 1); 57 58 // softDebugLevel_ is the maximum of the 3 variables 59 this->softDebugLevel_ = this->softDebugLevelConsole_; 60 if (this->softDebugLevelLogfile_ > this->softDebugLevel_) 61 this->softDebugLevel_ = this->softDebugLevelLogfile_; 62 if (this->softDebugLevelShell_ > this->softDebugLevel_) 63 this->softDebugLevel_ = this->softDebugLevelShell_; 56 64 } 57 65 … … 59 67 @brief Static function that holds the singleton. 60 68 */ 61 int DebugLevel::getSoftDebugLevel( )69 int DebugLevel::getSoftDebugLevel(OutputHandler::OutputDevice device) 62 70 { 63 71 static bool bCreatingSoftDebugLevelObject = true; // Static variable - used to enhance the performance … … 67 75 // If bReturnSoftDebugLevel is true, the instance of DebugLevel was created (it's set to true at the end of the constructor, call by reference) 68 76 if (bReturnSoftDebugLevel) 69 return theOnlyDebugLevelObject->softDebugLevel_; 77 { 78 if (device == OutputHandler::LD_All) 79 return theOnlyDebugLevelObject->softDebugLevel_; 80 else if (device == OutputHandler::LD_Console) 81 return theOnlyDebugLevelObject->softDebugLevelConsole_; 82 else if (device == OutputHandler::LD_Logfile) 83 return theOnlyDebugLevelObject->softDebugLevelLogfile_; 84 else if (device == OutputHandler::LD_Shell) 85 return theOnlyDebugLevelObject->softDebugLevelShell_; 86 } 70 87 71 88 // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class … … 74 91 bCreatingSoftDebugLevelObject = false; 75 92 theOnlyDebugLevelObject = new DebugLevel(bReturnSoftDebugLevel); 76 return theOnlyDebugLevelObject->softDebugLevel_;93 return getSoftDebugLevel(device); 77 94 } 78 95 -
code/branches/FICN/src/orxonox/core/DebugLevel.h
r695 r699 31 31 32 32 The DebugLevel class is a singleton, only used to configure the amount of debug 33 output (see Debug.h) into the console and the log -file (see OutputHandler.h).33 output (see Debug.h) into the console and the logfile (see OutputHandler.h). 34 34 */ 35 35 … … 39 39 #include "CorePrereqs.h" 40 40 #include "OrxonoxClass.h" 41 #include "OutputHandler.h" 41 42 42 43 namespace orxonox … … 46 47 { 47 48 public: 48 static int getSoftDebugLevel( );49 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 49 50 void setConfigValues(); 50 51 … … 55 56 56 57 int softDebugLevel_; //!< The debug level 58 int softDebugLevelConsole_; //!< The debug level for the console 59 int softDebugLevelLogfile_; //!< The debug level for the logfile 60 int softDebugLevelShell_; //!< The debug level for the ingame shell 57 61 ConfigValueContainer* softDebugLevelContainer_; //!< The config value container for the debug level 58 62 }; -
code/branches/FICN/src/orxonox/core/OutputHandler.cc
r685 r699 27 27 28 28 #include "OutputHandler.h" 29 #include "DebugLevel.h" 29 30 30 31 namespace orxonox … … 61 62 62 63 /** 64 @brief Returns the soft debug level for a given output device. 65 @param device The output device 66 @return The debug level 67 */ 68 int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device) 69 { 70 return DebugLevel::getSoftDebugLevel(device); 71 } 72 73 /** 63 74 @brief Overloaded << operator, redirects the output to the console and the logfile. 64 75 @param sb The streambuffer that should be shown in the console … … 67 78 OutputHandler& OutputHandler::operator<<(std::streambuf* sb) 68 79 { 69 std::cout << sb; 70 this->logfile_ << sb; 71 this->logfile_.flush(); 80 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 81 std::cout << sb; 82 83 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) 84 { 85 this->logfile_ << sb; 86 this->logfile_.flush(); 87 } 88 72 89 return *this; 73 90 } … … 80 97 OutputHandler& OutputHandler::operator<<(std::ostream& (*manipulator)(std::ostream&)) 81 98 { 82 manipulator(std::cout); 83 manipulator(this->logfile_); 84 this->logfile_.flush(); 99 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 100 manipulator(std::cout); 101 102 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) 103 { 104 manipulator(this->logfile_); 105 this->logfile_.flush(); 106 } 107 85 108 return *this; 86 109 } … … 93 116 OutputHandler& OutputHandler::operator<<(std::ios& (*manipulator)(std::ios&)) 94 117 { 95 manipulator(std::cout); 96 manipulator(this->logfile_); 97 this->logfile_.flush(); 118 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 119 manipulator(std::cout); 120 121 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) 122 { 123 manipulator(this->logfile_); 124 this->logfile_.flush(); 125 } 126 98 127 return *this; 99 128 } … … 106 135 OutputHandler& OutputHandler::operator<<(std::ios_base& (*manipulator)(std::ios_base&)) 107 136 { 108 manipulator(std::cout); 109 manipulator(this->logfile_); 110 this->logfile_.flush(); 137 if (getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 138 manipulator(std::cout); 139 140 if (getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) 141 { 142 manipulator(this->logfile_); 143 this->logfile_.flush(); 144 } 145 111 146 return *this; 112 147 } 113 114 /** 115 @brief Overloaded non-member << operator, redirects the output to the console and the logfile. 116 @param output The value that should be shown in the console 117 @return A reference to the OutputHandler itself 118 *//* 119 OutputHandler& operator<<(OutputHandler& out, char c) 120 { 121 std::cout << c; 122 out.getLogfile() << c; 123 out.getLogfile().flush(); 124 return out; 125 }*/ 126 127 /** 128 @brief Overloaded non-member << operator, redirects the output to the console and the logfile. 129 @param output The value that should be shown in the console 130 @return A reference to the OutputHandler itself 131 *//* 132 OutputHandler& operator<<(OutputHandler& out, signed char c) 133 { 134 std::cout << c; 135 out.getLogfile() << c; 136 out.getLogfile().flush(); 137 return out; 138 }*/ 139 140 /** 141 @brief Overloaded non-member << operator, redirects the output to the console and the logfile. 142 @param output The value that should be shown in the console 143 @return A reference to the OutputHandler itself 144 *//* 145 OutputHandler& operator<<(OutputHandler& out, unsigned char c) 146 { 147 std::cout << c; 148 out.getLogfile() << c; 149 out.getLogfile().flush(); 150 return out; 151 }*/ 152 153 /** 154 @brief Overloaded non-member << operator, redirects the output to the console and the logfile. 155 @param output The value that should be shown in the console 156 @return A reference to the OutputHandler itself 157 *//* 158 OutputHandler& operator<<(OutputHandler& out, const char* s) 159 { 160 std::cout << s; 161 out.getLogfile() << s; 162 out.getLogfile().flush(); 163 return out; 164 }*/ 165 166 /** 167 @brief Overloaded non-member << operator, redirects the output to the console and the logfile. 168 @param output The value that should be shown in the console 169 @return A reference to the OutputHandler itself 170 *//* 171 OutputHandler& operator<<(OutputHandler& out, const signed char* s) 172 { 173 std::cout << s; 174 out.getLogfile() << s; 175 out.getLogfile().flush(); 176 return out; 177 }*/ 178 179 /** 180 @brief Overloaded non-member << operator, redirects the output to the console and the logfile. 181 @param output The value that should be shown in the console 182 @return A reference to the OutputHandler itself 183 *//* 184 OutputHandler& operator<<(OutputHandler& out, const unsigned char* s) 185 { 186 std::cout << s; 187 out.getLogfile() << s; 188 out.getLogfile().flush(); 189 return out; 190 }*/ 191 } 148 } -
code/branches/FICN/src/orxonox/core/OutputHandler.h
r685 r699 49 49 { 50 50 public: 51 enum OutputDevice 52 { 53 LD_All, 54 LD_Console, 55 LD_Logfile, 56 LD_Shell 57 }; 58 51 59 static OutputHandler& getOutStream(); 52 60 53 61 /** @returns a reference to the logfile. */ 54 inline std::ofstream& getLogfile() { return this->logfile_; } 62 inline std::ofstream& getLogfile() 63 { return this->logfile_; } 64 65 /** @brief Sets the level of the incoming output. @param level The level of the incoming output @return The OutputHandler itself */ 66 inline OutputHandler& setOutputLevel(int level) 67 { this->outputLevel_ = level; return *this; } 68 69 /** @returns the level of the incoming output. */ 70 inline int getOutputLevel() const 71 { return this->outputLevel_; } 72 73 static int getSoftDebugLevel(OutputHandler::OutputDevice device); 55 74 56 75 template <class T> … … 94 113 std::ofstream logfile_; //!< The logfile where the output is logged 95 114 std::string logfilename_; //!< The name of the logfile 115 int outputLevel_; //!< The level of the incoming output 96 116 }; 97 117 … … 104 124 OutputHandler& OutputHandler::output(const T& output) 105 125 { 106 std::cout << output; 107 this->logfile_ << output; 108 this->logfile_.flush(); 126 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= this->outputLevel_) 127 std::cout << output; 128 129 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= this->outputLevel_) 130 { 131 this->logfile_ << output; 132 this->logfile_.flush(); 133 } 134 109 135 return *this; 110 136 } 111 /*112 _CoreExport OutputHandler& operator<<(OutputHandler& out, char c);113 _CoreExport OutputHandler& operator<<(OutputHandler& out, signed char c);114 _CoreExport OutputHandler& operator<<(OutputHandler& out, unsigned char c);115 137 116 _CoreExport OutputHandler& operator<<(OutputHandler& out, const char* s);117 _CoreExport OutputHandler& operator<<(OutputHandler& out, const signed char* s);118 _CoreExport OutputHandler& operator<<(OutputHandler& out, const unsigned char* s);119 */120 138 /** 121 139 @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. … … 127 145 OutputHandler& operator<<(OutputHandler& out, const T& output) 128 146 { 129 std::cout << output; 130 out.getLogfile() << output; 131 out.getLogfile().flush(); 147 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Console) >= out.getOutputLevel()) 148 std::cout << output; 149 150 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Logfile) >= out.getOutputLevel()) 151 { 152 out.getLogfile() << output; 153 out.getLogfile().flush(); 154 } 155 132 156 return out; 133 157 }
Note: See TracChangeset
for help on using the changeset viewer.