[Orxonox-commit 4166] r8837 - in code/branches/output: data/tcl src/libraries/core/command

landauf at orxonox.net landauf at orxonox.net
Sat Aug 13 21:41:38 CEST 2011


Author: landauf
Date: 2011-08-13 21:41:38 +0200 (Sat, 13 Aug 2011)
New Revision: 8837

Modified:
   code/branches/output/data/tcl/init.tcl
   code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.cc
   code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.h
   code/branches/output/src/libraries/core/command/Shell.cc
Log:
added console command "orxout" (and also "orxout_context")
re-added the shortcut commands log, error, warning, status, info, and debug
adjusted init.tcl

Modified: code/branches/output/data/tcl/init.tcl
===================================================================
--- code/branches/output/data/tcl/init.tcl	2011-08-13 17:30:04 UTC (rev 8836)
+++ code/branches/output/data/tcl/init.tcl	2011-08-13 19:41:38 UTC (rev 8837)
@@ -168,8 +168,10 @@
 
     foreach {channel s} $input break
 
-    if {$channel == "stdout" || $channel == "stderr"} {
-        execute puts $newline $s
+    if {$channel == "stdout"} {
+        execute log $s
+    } elseif {$channel == "stderr"} {
+        execute error $s
     } else {
         eval [concat ::tcl::puts $args]
     }

Modified: code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.cc
===================================================================
--- code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.cc	2011-08-13 17:30:04 UTC (rev 8836)
+++ code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.cc	2011-08-13 19:41:38 UTC (rev 8837)
@@ -45,9 +45,19 @@
 
 namespace orxonox
 {
-//    SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
     SetConsoleCommand("echo", echo);
 
+    SetConsoleCommand("orxout", orxout_level);
+    SetConsoleCommand("orxout_context", orxout_level_context);
+
+    SetConsoleCommand("log"    , log    );
+    SetConsoleCommand("error"  , error  ).hide();
+    SetConsoleCommand("warning", warning).hide();
+    SetConsoleCommand("status" , status ).hide();
+    SetConsoleCommand("info"   , info   ).hide();
+    SetConsoleCommand("debug"  , debug  ).hide();
+
+//    SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
 //    SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());      // disabled because we use the implementation in Tcl
 //    SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
 //    SetConsoleCommand("write", write).argumentCompleter(0, autocompletion::files());    // disabled because we use the implementation in Tcl
@@ -55,6 +65,101 @@
     SetConsoleCommand("calculate", calculate);
 
     /**
+        @brief Simply returns the arguments.
+    */
+    std::string echo(const std::string& text)
+    {
+        return text;
+    }
+
+    /**
+        @brief Builds a map that maps the levels of all output levels to their ID.
+    */
+    std::map<std::string, OutputLevel> getOutputLevelsMap()
+    {
+        std::map<std::string, OutputLevel> levels;
+
+        levels["message"]          = level::message;
+        levels["debug_output"]     = level::debug_output;
+        levels["user_error"]       = level::user_error;
+        levels["user_warning"]     = level::user_warning;
+        levels["user_status"]      = level::user_status;
+        levels["user_info"]        = level::user_info;
+        levels["internal_error"]   = level::internal_error;
+        levels["internal_warning"] = level::internal_warning;
+        levels["internal_status"]  = level::internal_status;
+        levels["internal_info"]    = level::internal_info;
+        levels["verbose"]          = level::verbose;
+        levels["verbose_more"]     = level::verbose_more;
+        levels["verbose_ultra"]    = level::verbose_ultra;
+
+        return levels;
+    }
+
+    /**
+        @brief Prints text to the console.
+        @param level_name The name of the output level
+    */
+    void orxout_level(const std::string& level_name, const std::string& text)
+    {
+        static std::map<std::string, OutputLevel> levels = getOutputLevelsMap();
+
+        OutputLevel level = level::debug_output;
+        std::map<std::string, OutputLevel>::iterator it = levels.find(level_name);
+        if (it != levels.end())
+            level = it->second;
+        else
+            orxout(internal_warning) << "'" << level_name << "' is not a valid output level" << endl;
+
+        orxout(level) << text << endl;
+    }
+
+    /**
+        @brief Prints text to the console.
+        @param level_name The name of the output level
+        @param context_name The name of the output context
+    */
+    void orxout_level_context(const std::string& level_name, const std::string& context_name, const std::string& text)
+    {
+        static std::map<std::string, OutputLevel> levels = getOutputLevelsMap();
+
+        OutputLevel level = level::debug_output;
+        std::map<std::string, OutputLevel>::iterator it = levels.find(level_name);
+        if (it != levels.end())
+            level = it->second;
+        else
+            orxout(internal_warning) << "'" << level_name << "' is not a valid output level" << endl;
+
+        OutputContextContainer context = registerContext(context_name);
+
+        orxout(level, context) << text << endl;
+    }
+
+    /// @brief Prints text to the console and the logfile.
+    void log(const std::string& text)
+    { orxout() << text << endl; }
+
+    /// @brief Prints output with error level.
+    void error(const std::string& text)
+    { orxout(user_error) << text << endl; }
+
+    /// @brief Prints output with warning level.
+    void warning(const std::string& text)
+    { orxout(user_warning) << text << endl; }
+
+    /// @brief Prints output with status level.
+    void status(const std::string& text)
+    { orxout(user_status) << text << endl; }
+
+    /// @brief Prints output with info level.
+    void info(const std::string& text)
+    { orxout(user_info) << text << endl; }
+
+    /// @brief Prints debug output with verbose level.
+    void debug(const std::string& text)
+    { orxout(verbose, context::tcl) << text << endl; }
+
+    /**
         @brief Reads the content of a file and executes the commands in it line by line.
     */
     void source(const std::string& filename)
@@ -93,14 +198,6 @@
     }
 
     /**
-        @brief Simply returns the arguments.
-    */
-    std::string echo(const std::string& text)
-    {
-        return text;
-    }
-
-    /**
         @brief Writes text to a file.
     */
     void write(const std::string& filename, const std::string& text)

Modified: code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.h
===================================================================
--- code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.h	2011-08-13 17:30:04 UTC (rev 8836)
+++ code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.h	2011-08-13 19:41:38 UTC (rev 8837)
@@ -42,6 +42,16 @@
     _CoreExport void source(const std::string& filename);
     _CoreExport std::string echo(const std::string& text);
 
+    _CoreExport void orxout_level(const std::string& level_name, const std::string& text);
+    _CoreExport void orxout_level_context(const std::string& level_name, const std::string& context_name, const std::string& text);
+
+    _CoreExport void log(const std::string& text);
+    _CoreExport void error(const std::string& text);
+    _CoreExport void warning(const std::string& text);
+    _CoreExport void status(const std::string& text);
+    _CoreExport void info(const std::string& text);
+    _CoreExport void debug(const std::string& text);
+
     _CoreExport void write(const std::string& filename, const std::string& text);
     _CoreExport void append(const std::string& filename, const std::string& text);
     _CoreExport std::string read(const std::string& filename);

Modified: code/branches/output/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/output/src/libraries/core/command/Shell.cc	2011-08-13 17:30:04 UTC (rev 8836)
+++ code/branches/output/src/libraries/core/command/Shell.cc	2011-08-13 19:41:38 UTC (rev 8837)
@@ -46,17 +46,9 @@
 #include "core/PathConfig.h"
 #include "core/input/InputBuffer.h"
 #include "CommandExecutor.h"
-#include "ConsoleCommand.h"
 
 namespace orxonox
 {
-#pragma message(__FILE__ "("BOOST_PP_STRINGIZE(__LINE__)") : Warning: TODO: add commands again, inspect tcl support (and remove boost include)")
-//    SetConsoleCommand("log",     OutputHandler::log    );
-//    SetConsoleCommand("error",   OutputHandler::error  ).hide();
-//    SetConsoleCommand("warning", OutputHandler::warning).hide();
-//    SetConsoleCommand("info",    OutputHandler::info   ).hide();
-//    SetConsoleCommand("debug",   OutputHandler::debug  ).hide();
-
     unsigned int Shell::cacheSize_s;
 
     namespace DefaultLogLevel




More information about the Orxonox-commit mailing list