- Timestamp:
- Aug 23, 2011, 12:45:53 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:ignore
-
old new 1 1 build 2 2 codeblocks 3 vs 3 4 dependencies
-
- Property svn:mergeinfo changed
/code/branches/output (added) merged: 8739-8740,8765,8771-8772,8774-8780,8787-8789,8794-8799,8801,8803-8812,8814,8816-8817,8820,8822,8825-8837,8840,8844,8846,8848-8850,8853-8854
- Property svn:ignore
-
code/trunk/src/libraries/core/command/ConsoleCommandCompilation.cc
r8079 r8858 38 38 #include <string> 39 39 40 #include "util/ Debug.h"40 #include "util/Output.h" 41 41 #include "util/ExprParser.h" 42 42 #include "util/StringUtils.h" … … 46 46 namespace orxonox 47 47 { 48 SetConsoleCommand("echo", echo); 49 50 SetConsoleCommand("orxout", orxout_level); 51 SetConsoleCommand("orxout_context", orxout_level_context); 52 53 SetConsoleCommand("log" , log ); 54 SetConsoleCommand("error" , error ).hide(); 55 SetConsoleCommand("warning", warning).hide(); 56 SetConsoleCommand("status" , status ).hide(); 57 SetConsoleCommand("info" , info ).hide(); 58 SetConsoleCommand("debug" , debug ).hide(); 59 48 60 // SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl 49 SetConsoleCommand("echo", echo);50 // SetConsoleCommand("puts", puts); // disabled because we use the implementation in Tcl51 52 61 // SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl 53 62 // SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files()); // disabled because we use the implementation in Tcl … … 57 66 58 67 /** 68 @brief Simply returns the arguments. 69 */ 70 std::string echo(const std::string& text) 71 { 72 return text; 73 } 74 75 /** 76 @brief Builds a map that maps the levels of all output levels to their ID. 77 */ 78 std::map<std::string, OutputLevel> getOutputLevelsMap() 79 { 80 std::map<std::string, OutputLevel> levels; 81 82 levels["message"] = level::message; 83 levels["debug_output"] = level::debug_output; 84 levels["user_error"] = level::user_error; 85 levels["user_warning"] = level::user_warning; 86 levels["user_status"] = level::user_status; 87 levels["user_info"] = level::user_info; 88 levels["internal_error"] = level::internal_error; 89 levels["internal_warning"] = level::internal_warning; 90 levels["internal_status"] = level::internal_status; 91 levels["internal_info"] = level::internal_info; 92 levels["verbose"] = level::verbose; 93 levels["verbose_more"] = level::verbose_more; 94 levels["verbose_ultra"] = level::verbose_ultra; 95 96 return levels; 97 } 98 99 /** 100 @brief Prints text to the console. 101 @param level_name The name of the output level 102 */ 103 void orxout_level(const std::string& level_name, const std::string& text) 104 { 105 static std::map<std::string, OutputLevel> levels = getOutputLevelsMap(); 106 107 OutputLevel level = level::debug_output; 108 std::map<std::string, OutputLevel>::iterator it = levels.find(level_name); 109 if (it != levels.end()) 110 level = it->second; 111 else 112 orxout(internal_warning) << "'" << level_name << "' is not a valid output level" << endl; 113 114 orxout(level) << text << endl; 115 } 116 117 /** 118 @brief Prints text to the console. 119 @param level_name The name of the output level 120 @param context_name The name of the output context 121 */ 122 void orxout_level_context(const std::string& level_name, const std::string& context_name, const std::string& text) 123 { 124 static std::map<std::string, OutputLevel> levels = getOutputLevelsMap(); 125 126 OutputLevel level = level::debug_output; 127 std::map<std::string, OutputLevel>::iterator it = levels.find(level_name); 128 if (it != levels.end()) 129 level = it->second; 130 else 131 orxout(internal_warning) << "'" << level_name << "' is not a valid output level" << endl; 132 133 OutputContextContainer context = registerContext(context_name); 134 135 orxout(level, context) << text << endl; 136 } 137 138 /// @brief Prints text to the console and the logfile. 139 void log(const std::string& text) 140 { orxout() << text << endl; } 141 142 /// @brief Prints output with error level. 143 void error(const std::string& text) 144 { orxout(user_error) << text << endl; } 145 146 /// @brief Prints output with warning level. 147 void warning(const std::string& text) 148 { orxout(user_warning) << text << endl; } 149 150 /// @brief Prints output with status level. 151 void status(const std::string& text) 152 { orxout(user_status) << text << endl; } 153 154 /// @brief Prints output with info level. 155 void info(const std::string& text) 156 { orxout(user_info) << text << endl; } 157 158 /// @brief Prints debug output with verbose level. 159 void debug(const std::string& text) 160 { orxout(verbose, context::tcl) << text << endl; } 161 162 /** 59 163 @brief Reads the content of a file and executes the commands in it line by line. 60 164 */ … … 66 170 if (it != executingFiles.end()) 67 171 { 68 COUT(1) << "Error: Recurring source command in \"" << filename << "\". Stopped execution." << std::endl;172 orxout(user_error) << "Recurring source command in \"" << filename << "\". Stopped execution." << endl; 69 173 return; 70 174 } … … 76 180 if (!file.is_open()) 77 181 { 78 COUT(1) << "Error: Couldn't open file \"" << filename << "\"." << std::endl;182 orxout(user_error) << "Couldn't open file \"" << filename << "\"." << endl; 79 183 return; 80 184 } … … 95 199 96 200 /** 97 @brief Simply returns the arguments.98 */99 std::string echo(const std::string& text)100 {101 return text;102 }103 104 /**105 @brief Writes text to the console, depending on the first argument with or without a line-break after it.106 */107 void puts(bool newline, const std::string& text)108 {109 if (newline)110 {111 COUT(0) << stripEnclosingBraces(text) << std::endl;112 }113 else114 {115 COUT(0) << stripEnclosingBraces(text);116 }117 }118 119 /**120 201 @brief Writes text to a file. 121 202 */ … … 127 208 if (!file.is_open()) 128 209 { 129 COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl;130 return; 131 } 132 133 file << text << std::endl;210 orxout(user_error) << "Couldn't write to file \"" << filename << "\"." << endl; 211 return; 212 } 213 214 file << text << endl; 134 215 file.close(); 135 216 } … … 145 226 if (!file.is_open()) 146 227 { 147 COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl;148 return; 149 } 150 151 file << text << std::endl;228 orxout(user_error) << "Couldn't append to file \"" << filename << "\"." << endl; 229 return; 230 } 231 232 file << text << endl; 152 233 file.close(); 153 234 } … … 163 244 if (!file.is_open()) 164 245 { 165 COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl;246 orxout(user_error) << "Couldn't read from file \"" << filename << "\"." << endl; 166 247 return ""; 167 248 } … … 192 273 if (expr.getResult() == 42.0) 193 274 { 194 COUT(3) << "Greetings from the restaurant at the end of the universe." << std::endl;275 orxout(user_info) << "Greetings from the restaurant at the end of the universe." << endl; 195 276 } 196 277 if (!expr.getRemains().empty()) 197 278 { 198 COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl;279 orxout(user_warning) << "Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << endl; 199 280 } 200 281 return static_cast<float>(expr.getResult()); … … 202 283 else 203 284 { 204 COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl;285 orxout(user_error) << "Cannot calculate expression: Parse error." << endl; 205 286 return 0; 206 287 }
Note: See TracChangeset
for help on using the changeset viewer.