[Orxonox-commit 4133] r8804 - code/branches/output/src/libraries/util

landauf at orxonox.net landauf at orxonox.net
Sat Jul 30 23:06:37 CEST 2011


Author: landauf
Date: 2011-07-30 23:06:36 +0200 (Sat, 30 Jul 2011)
New Revision: 8804

Modified:
   code/branches/output/src/libraries/util/Clipboard.cc
   code/branches/output/src/libraries/util/Convert.h
   code/branches/output/src/libraries/util/Exception.cc
   code/branches/output/src/libraries/util/Exception.h
   code/branches/output/src/libraries/util/ExprParser.h
   code/branches/output/src/libraries/util/MultiType.h
   code/branches/output/src/libraries/util/OrxAssert.h
   code/branches/output/src/libraries/util/Scope.h
   code/branches/output/src/libraries/util/ScopedSingletonManager.h
   code/branches/output/src/libraries/util/SignalHandler.cc
   code/branches/output/src/libraries/util/Singleton.h
   code/branches/output/src/libraries/util/Sleep.cc
   code/branches/output/src/libraries/util/SubString.cc
   code/branches/output/src/libraries/util/SubString.h
Log:
Replaced COUT in util with orxout.
Used user_error for Exceptions and Assertions because I assume they're only used in very critical situations. Same with Signal Handler.
Clipboard shows user_errors because it's used only with user interaction.
Other output is mostly internal.

Modified: code/branches/output/src/libraries/util/Clipboard.cc
===================================================================
--- code/branches/output/src/libraries/util/Clipboard.cc	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Clipboard.cc	2011-07-30 21:06:36 UTC (rev 8804)
@@ -75,8 +75,8 @@
         }
         catch (...)
         {
-            COUT(1) << "Error: Unable to copy the following text to the clipboard:" << std::endl;
-            COUT(1) << "       \"" << text << '"' << std::endl;
+            orxout(user_error) << "Unable to copy the following text to the clipboard:" << endl;
+            orxout(user_error) << '"' << text << '"' << endl;
         }
         return false;
     }
@@ -103,7 +103,7 @@
         }
         catch (...)
         {
-            COUT(1) << "Error: Unable to retrieve text from the clipboard." << std::endl;
+            orxout(user_error) << "Unable to retrieve text from the clipboard." << endl;
         }
         return "";
     }

Modified: code/branches/output/src/libraries/util/Convert.h
===================================================================
--- code/branches/output/src/libraries/util/Convert.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Convert.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -150,8 +150,8 @@
     {
         ORX_FORCEINLINE static bool convert(ToType* /*output*/, const FromType& /*input*/)
         {
-            COUT(2) << "Could not convert value of type " << typeid(FromType).name()
-                    << " to type " << typeid(ToType).name() << std::endl;
+            orxout(internal_warning) << "Could not convert value of type " << typeid(FromType).name()
+                                     << " to type " << typeid(ToType).name() << endl;
             return false;
         }
     };

Modified: code/branches/output/src/libraries/util/Exception.cc
===================================================================
--- code/branches/output/src/libraries/util/Exception.cc	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Exception.cc	2011-07-30 21:06:36 UTC (rev 8804)
@@ -110,8 +110,8 @@
         }
         catch (...)
         {
-            COUT(0) << "BIG WARNING: Unknown exception type encountered."
-                    << "Rethrowing" << endl;
+            orxout(user_error) << "BIG WARNING: Unknown exception type encountered."
+                               << " Rethrowing" << endl;
             throw;
         }
     }

Modified: code/branches/output/src/libraries/util/Exception.h
===================================================================
--- code/branches/output/src/libraries/util/Exception.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Exception.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -175,8 +175,8 @@
     template <class T>
     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;
+        // let the catcher decide whether to display the message also to the user
+        orxout(internal_error) << exception.getFullDescription() << endl;
         return exception;
     }
 

Modified: code/branches/output/src/libraries/util/ExprParser.h
===================================================================
--- code/branches/output/src/libraries/util/ExprParser.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/ExprParser.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -54,12 +54,12 @@
         {
             if (!expr.getRemains().empty())
             {
-                COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl;
+                orxout(user_warning) << "Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << endl;
             }
             float result = expr.getResult();
         }
         else
-            COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl;
+            orxout(user_error) << "Cannot calculate expression: Parse error." << endl;
         @endcode
         getRemains() returns the expression after what could be parsed. For instance
         \c "2*3 text" will return \c "text" as remains.

Modified: code/branches/output/src/libraries/util/MultiType.h
===================================================================
--- code/branches/output/src/libraries/util/MultiType.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/MultiType.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -77,7 +77,7 @@
     @code
     void myfunction(int value)
     {
-        COUT(0) << "doubled value is " << (2 * value) << std::endl;
+        orxout() << "doubled value is " << (2 * value) << endl;
     }
 
     MultiType a = "50";        // Note: We assigned a string

Modified: code/branches/output/src/libraries/util/OrxAssert.h
===================================================================
--- code/branches/output/src/libraries/util/OrxAssert.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/OrxAssert.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -45,7 +45,7 @@
 
 /** Run time assertion like assert(), but with an embedded message.
 @details
-    The message will be printed as error with COUT(1). <br>
+    The message will be printed as error with orxout(user_error). <br>
     You can use the same magic here as you can with \ref ThrowException
     @code
         OrxAssert(condition, "Text: " << number << " more text");
@@ -56,10 +56,10 @@
     { \
         if (!(condition)) \
         { \
-            COUT(1) << __FILE__ << "(" << __LINE__ << "): "; \
-            COUT(1) << "Assertion failed in " << __FUNCTIONNAME__ << std::endl; \
-            COUT(1) << "Expression: " << #condition << std::endl; \
-            COUT(1) << "Message   : " << errorMessage << std::endl; \
+            orxout(user_error) << __FILE__ << "(" << __LINE__ << "): "; \
+            orxout(user_error) << "Assertion failed in " << __FUNCTIONNAME__ << endl; \
+            orxout(user_error) << "Expression: " << #condition << endl; \
+            orxout(user_error) << "Message   : " << errorMessage << endl; \
             /* Don't use the condition again to avoid double evaluation */ \
             /* Instead, stringify the expression and negate it */ \
             assert(!#condition); \
@@ -69,7 +69,7 @@
 /** Works like OrxAssert in debug mode, but also checks the condition in release
     mode (no abort() triggered then).
 @details
-    The message will be printed as error with COUT(1). <br>
+    The message will be printed as error with orxout(user_error). <br>
     You can use the same magic here as you can with \ref ThrowException
     @code
         OrxVerify(condition, "Text: " << number << " more text");
@@ -80,10 +80,10 @@
     { \
         if (!(condition)) \
         { \
-            COUT(1) << __FILE__ << "(" << __LINE__ << "): "; \
-            COUT(1) << "Verification failed in " << __FUNCTIONNAME__ << std::endl; \
-            COUT(1) << "Expression: " << #condition << std::endl; \
-            COUT(1) << "Message   : " << errorMessage << std::endl; \
+            orxout(user_error) << __FILE__ << "(" << __LINE__ << "): "; \
+            orxout(user_error) << "Verification failed in " << __FUNCTIONNAME__ << endl; \
+            orxout(user_error) << "Expression: " << #condition << endl; \
+            orxout(user_error) << "Message   : " << errorMessage << endl; \
             /* Don't use the condition again to avoid double evaluation */ \
             /* Instead, stringify the expression and negate it */ \
             assert(!#condition); \
@@ -99,10 +99,10 @@
     { \
         if (!(condition)) \
         { \
-            COUT(1) << __FILE__ << "(" << __LINE__ << "): "; \
-            COUT(1) << "Verification failed in " << __FUNCTIONNAME__ << std::endl; \
-            COUT(1) << "Expression: " << #condition << std::endl; \
-            COUT(1) << "Message   : " << errorMessage << std::endl; \
+            orxout(user_error) << __FILE__ << "(" << __LINE__ << "): "; \
+            orxout(user_error) << "Verification failed in " << __FUNCTIONNAME__ << endl; \
+            orxout(user_error) << "Expression: " << #condition << endl; \
+            orxout(user_error) << "Message   : " << errorMessage << endl; \
             /* No assert() in release configuration */ \
         } \
     } while (false)

Modified: code/branches/output/src/libraries/util/Scope.h
===================================================================
--- code/branches/output/src/libraries/util/Scope.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Scope.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -173,7 +173,7 @@
                         try
                             { (*it)->deactivated(); }
                         catch (...)
-                            { COUT(0) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << std::endl; }
+                            { orxout(internal_warning) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << endl; }
                         (*(it++))->bActivated_ = false;
                     }
                     else

Modified: code/branches/output/src/libraries/util/ScopedSingletonManager.h
===================================================================
--- code/branches/output/src/libraries/util/ScopedSingletonManager.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/ScopedSingletonManager.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -230,9 +230,9 @@
             try
                 { singletonPtr_ = new T(); }
             catch (const InitialisationAbortedException& ex)
-                { COUT(3) << ex.getDescription() << std::endl; }
+                { orxout(internal_error) << ex.getDescription() << endl; }
             catch (...)
-                { COUT(1) << "Singleton creation failed: " << Exception::handleMessage() << std::endl; }
+                { orxout(internal_error) << "Singleton creation failed: " << Exception::handleMessage() << endl; }
         }
 
         //! Called if the Scope of this Singleton gets deactivated (destroys the instance)

Modified: code/branches/output/src/libraries/util/SignalHandler.cc
===================================================================
--- code/branches/output/src/libraries/util/SignalHandler.cc	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/SignalHandler.cc	2011-07-30 21:06:36 UTC (rev 8804)
@@ -126,7 +126,7 @@
       // if the signalhandler has already been destroyed then don't do anything
       if( SignalHandler::singletonPtr_s == 0 )
       {
-        COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Can't write backtrace because SignalHandler is already destroyed" << std::endl;
+        orxout(user_error) << "Received signal " << sigName.c_str() << endl << "Can't write backtrace because SignalHandler is already destroyed" << endl;
         exit(EXIT_FAILURE);
       }
 
@@ -136,7 +136,7 @@
       }
 
 
-      COUT(0) << "Received signal " << sigName.c_str() << std::endl << "Try to write backtrace to file orxonox_crash.log" << std::endl;
+      orxout(user_error) << "Received signal " << sigName.c_str() << endl << "Try to write backtrace to file orxonox_crash.log" << endl;
 
       
       // First start GDB which will be attached to this process later on
@@ -205,18 +205,18 @@
         // make sure gdb is allowed to attach to our PID even if there are some system restrictions
 #ifdef PR_SET_PTRACER
         if( prctl(PR_SET_PTRACER, gdbPid, 0, 0, 0) == -1 )
-          COUT(0) << "could not set proper permissions for GDB to attach to process..." << endl;
+          orxout(user_error) << "could not set proper permissions for GDB to attach to process..." << endl;
 #endif
         
         // wait for message from parent when it has attached gdb
         int someData;
 
         if( read( sigPipe[0], &someData, sizeof(someData) ) != sizeof(someData) )
-          COUT(0) << "something went wrong :(" << std::endl;
+          orxout(user_error) << "something went wrong :(" << endl;
 
         if ( someData != 0x12345678 )
         {
-          COUT(0) << "something went wrong :(" << std::endl;
+          orxout(user_error) << "something went wrong :(" << endl;
         }
 
         return;
@@ -327,7 +327,7 @@
 
       if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
       {
-        COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl;
+        orxout(user_error) << "could not write " << bt.length() << " byte to " << getInstance().filename << endl;
         exit(EXIT_FAILURE);
       }
 
@@ -363,8 +363,9 @@
 /// Overwrite the original abort() function in MinGW to enable a break point.
 _UtilExport void __cdecl abort()
 {
-    COUT(1) << "This application has requested the Runtime to terminate it in an unusual way." << std::endl;
-    COUT(1) << "Please contact the application's support team for more information." << std::endl;
+    using namespace orxonox;
+    orxout(user_error) << "This application has requested the Runtime to terminate it in an unusual way." << endl;
+    orxout(user_error) << "Please contact the application's support team for more information." << endl;
     DebugBreak();
     exit(0x3);
 }
@@ -372,8 +373,9 @@
 /// Overwrite the original _abort() function in MinGW to enable a break point.
 _UtilExport void __cdecl _assert(const char* expression, const char* file, int line)
 {
-    COUT(1) << "Assertion failed: " << expression << ", file " << file << ", line " << line << std::endl;
-    COUT(1) << std::endl;
+    using namespace orxonox;
+    orxout(user_error) << "Assertion failed: " << expression << ", file " << file << ", line " << line << endl;
+    orxout(user_error) << endl;
     abort();
 }
 #endif
@@ -422,51 +424,51 @@
         {
             bExecuting = true;
 
-            COUT(1) << std::endl;
+            orxout(user_error) << endl;
 
             // if the signalhandler has already been destroyed then don't do anything
             if (SignalHandler::singletonPtr_s == 0)
             {
-                COUT(1) << "Caught an unhandled exception" << std::endl << "Can't write backtrace because SignalHandler is already destroyed" << std::endl;
+                orxout(user_error) << "Caught an unhandled exception" << endl << "Can't write backtrace because SignalHandler is already destroyed" << endl;
                 exit(EXIT_FAILURE);
             }
 
-            COUT(1) << "Caught an unhandled exception" << std::endl << "Try to write backtrace to orxonox_crash.log..." << std::endl;
+            orxout(user_error) << "Caught an unhandled exception" << endl << "Try to write backtrace to orxonox_crash.log..." << endl;
 
             // write the crash log
             std::ofstream crashlog(SignalHandler::getInstance().filename_.c_str());
 
             time_t now = time(NULL);
 
-            crashlog << "=======================================================" << std::endl;
+            crashlog << "=======================================================" << endl;
             crashlog << "= Time: " << std::string(ctime(&now));
-            crashlog << "=======================================================" << std::endl;
-            crashlog << std::endl;
+            crashlog << "=======================================================" << endl;
+            crashlog << endl;
 
             const std::string& error = SignalHandler::getExceptionType(pExceptionInfo);
 
-            crashlog << error << std::endl;
-            crashlog << std::endl;
+            crashlog << error << endl;
+            crashlog << endl;
 
             const std::string& callstack = SignalHandler::getStackTrace(pExceptionInfo);
 
-            crashlog << "Call stack:" << std::endl;
-            crashlog << callstack << std::endl;
+            crashlog << "Call stack:" << endl;
+            crashlog << callstack << endl;
 
             crashlog.close();
 
             // print the same information also to the console
-            COUT(1) << std::endl;
-            COUT(1) << error << std::endl;
-            COUT(1) << std::endl;
-            COUT(1) << "Call stack:" << std::endl;
-            COUT(1) << callstack << std::endl;
+            orxout(user_error) << endl;
+            orxout(user_error) << error << endl;
+            orxout(user_error) << endl;
+            orxout(user_error) << "Call stack:" << endl;
+            orxout(user_error) << callstack << endl;
 
             bExecuting = false;
         }
         else
         {
-            COUT(1) << "An error occurred while writing the backtrace" << std::endl;
+            orxout(user_error) << "An error occurred while writing the backtrace" << endl;
         }
 
         if (SignalHandler::getInstance().prevExceptionFilter_)

Modified: code/branches/output/src/libraries/util/Singleton.h
===================================================================
--- code/branches/output/src/libraries/util/Singleton.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Singleton.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -99,7 +99,7 @@
 
     void TestSingleton::testFunction()                      // implement testFunction
     {
-        COUT(0) << "My value is " << this->testValue_ << std::endl;
+        orxout() << "My value is " << this->testValue_ << endl;
     }
 
     TestSingleton::getInstance().testFunction();            // prints "My value is 15"

Modified: code/branches/output/src/libraries/util/Sleep.cc
===================================================================
--- code/branches/output/src/libraries/util/Sleep.cc	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/Sleep.cc	2011-07-30 21:06:36 UTC (rev 8804)
@@ -48,7 +48,7 @@
     void usleep(unsigned long microseconds)
     {
         //if (microseconds < 1000)
-        //    COUT(2) << "Warning: Windows cannot sleep less than 1ms, ignoring" << std::endl;
+        //    orxout(internal_warning) << "Warning: Windows cannot sleep less than 1ms, ignoring" << endl;
         Sleep(microseconds / 1000);
     }
 

Modified: code/branches/output/src/libraries/util/SubString.cc
===================================================================
--- code/branches/output/src/libraries/util/SubString.cc	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/SubString.cc	2011-07-30 21:06:36 UTC (rev 8804)
@@ -512,9 +512,9 @@
     */
     void SubString::debug() const
     {
-        COUT(0) << "Substring-information::count=" << this->tokens_.size() << " ::";
+        orxout() << "Substring-information::count=" << this->tokens_.size() << " ::";
         for (unsigned int i = 0; i < this->tokens_.size(); ++i)
-            COUT(0) << "s" << i << "='" << this->tokens_[i].c_str() << "'::";
-        COUT(0) << std::endl;
+            orxout() << "s" << i << "='" << this->tokens_[i].c_str() << "'::";
+        orxout() << endl;
     }
 }

Modified: code/branches/output/src/libraries/util/SubString.h
===================================================================
--- code/branches/output/src/libraries/util/SubString.h	2011-07-30 20:05:49 UTC (rev 8803)
+++ code/branches/output/src/libraries/util/SubString.h	2011-07-30 21:06:36 UTC (rev 8804)
@@ -58,7 +58,7 @@
     SubString tokens(text, SubString::WhiteSpaces, "", false, '\\', true, '"', true, '{', '}', true, '\0');
 
     for (unsigned int i = 0; i < tokens.size(); ++i)
-        COUT(0) << i << ": " << tokens[i] << std::endl;
+        orxout() << i << ": " << tokens[i] << endl;
     @endcode
 
     The output of this code is:




More information about the Orxonox-commit mailing list