Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 23, 2011, 12:45:53 AM (13 years ago)
Author:
landauf
Message:

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/command/CommandExecutor.cc

    r7401 r8858  
    6969        @return Returns the error-code (see @ref CommandExecutorErrorCodes "error codes")
    7070    */
    71     /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl)
     71    /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl, bool printErrors)
    7272    {
    7373        int error;
    7474        CommandExecutor::queryMT(command, &error, useTcl);
     75        if (error && printErrors)
     76            orxout(user_error) << "Can't execute \"" << command << "\", " << CommandExecutor::getErrorDescription(error) << ". (execute)" << endl;
    7577        return error;
    7678    }
     
    8587    /* static */ MultiType CommandExecutor::queryMT(const std::string& command, int* error, bool useTcl)
    8688    {
     89        MultiType result;
     90        int error_internal;
     91
    8792        if (useTcl)
    8893        {
    8994            // pass the command to tcl
    90             return TclBind::eval(command, error);
     95            result = TclBind::eval(command, &error_internal);
    9196        }
    9297        else
     
    108113
    109114            // query the command and return its return-value
    110             return evaluation.query(error);
    111         }
     115            result = evaluation.query(&error_internal);
     116        }
     117
     118        if (error)
     119            *error = error_internal;
     120        else if (error_internal)
     121            orxout(user_error) << "Can't execute \"" << command << "\", " << CommandExecutor::getErrorDescription(error_internal) << ". (query)" << endl;
     122
     123        return result;
    112124    }
    113125
     
    172184
    173185    /**
     186        @brief Returns a description of the error code.
     187        @param error The error code
     188    */
     189    /* static */ std::string CommandExecutor::getErrorDescription(int error)
     190    {
     191        switch (error)
     192        {
     193            case CommandExecutor::Inexistent:  return "command doesn't exist";
     194            case CommandExecutor::Incomplete:  return "not enough arguments given";
     195            case CommandExecutor::Deactivated: return "command is not active";
     196            case CommandExecutor::Denied:      return "access denied";
     197            case CommandExecutor::Error:       return "an error occurred";
     198            default: return "";
     199        }
     200    }
     201
     202    /**
    174203        @brief Gets an evaluated command from the cache.
    175204        @param command The command that should be looked up in the cache
     
    261290            if ((tokens.size() == 1 && ConsoleCommand::getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommand::getCommand(tokens[0], tokens[1])))
    262291            {
    263                 COUT(1) << "Error: A command with name \"" << alias << "\" already exists." << std::endl;
     292                orxout(user_error) << "A command with name \"" << alias << "\" already exists." << endl;
    264293                return;
    265294            }
     
    271300                createConsoleCommand(tokens[0], tokens[1], executor);
    272301            else
    273                 COUT(1) << "Error: \"" << alias << "\" is not a valid alias name (must have one or two words)." << std::endl;
     302                orxout(user_error) << "\"" << alias << "\" is not a valid alias name (must have one or two words)." << endl;
    274303        }
    275304        else
    276             COUT(1) << "Error: \"" << command << "\" is not a valid command (did you mean \"" << evaluation.getCommandSuggestion() << "\"?)." << std::endl;
     305            orxout(user_error) << "\"" << command << "\" is not a valid command (did you mean \"" << evaluation.getCommandSuggestion() << "\"?)." << endl;
    277306    }
    278307}
Note: See TracChangeset for help on using the changeset viewer.