*
* @return The string name of the command for this binding.
*/
- const string &getCommandName () const { return _command_name; }
+ const std::string &getCommandName () const { return _command_name; }
/**
#include "commands.hxx"
#include <simgear/math/SGMath.hxx>
-
+#include <simgear/structure/exception.hxx>
+#include <simgear/debug/logstream.hxx>
\f
////////////////////////////////////////////////////////////////////////
}
void
-SGCommandMgr::addCommand (const string &name, command_t command)
+SGCommandMgr::addCommand (const std::string &name, command_t command)
{
_commands[name] = command;
}
SGCommandMgr::command_t
-SGCommandMgr::getCommand (const string &name) const
+SGCommandMgr::getCommand (const std::string &name) const
{
const command_map::const_iterator it = _commands.find(name);
return (it != _commands.end() ? it->second : 0);
}
-vector<string>
+string_list
SGCommandMgr::getCommandNames () const
{
- vector<string> names;
+ string_list names;
command_map::const_iterator it = _commands.begin();
command_map::const_iterator last = _commands.end();
while (it != last) {
}
bool
-SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
+SGCommandMgr::execute (const std::string &name, const SGPropertyNode * arg) const
{
command_t command = getCommand(name);
if (command == 0)
return false;
- else
+
+
+ try {
return (*command)(arg);
+ } catch (sg_exception& e) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "command '" << name << "' failed with exception\n"
+ << "\tmessage:" << e.getMessage() << " (from " << e.getOrigin() << ")");
+ return false;
+ }
}
// end of commands.cxx
#include <OpenThreads/Mutex>
+#include <simgear/math/sg_types.hxx>
#include <simgear/props/props.hxx>
-using std::string;
-using std::map;
-using std::vector;
-
-
/**
* Manage commands.
*
* a bool result. The argument is always a const pointer to
* an SGPropertyNode (which may contain multiple values).
*/
- virtual void addCommand (const string &name, command_t command);
+ virtual void addCommand (const std::string &name, command_t command);
/**
* @return A pointer to the command, or 0 if there is no registered
* command with the name specified.
*/
- virtual command_t getCommand (const string &name) const;
+ virtual command_t getCommand (const std::string &name) const;
/**
* @return A (possibly empty) vector of the names of all registered
* commands.
*/
- virtual vector<string> getCommandNames () const;
+ virtual string_list getCommandNames () const;
/**
* @return true if the command is present and executes successfully,
* false otherwise.
*/
- virtual bool execute (const string &name, const SGPropertyNode * arg) const;
+ virtual bool execute (const std::string &name, const SGPropertyNode * arg) const;
protected:
/**
private:
- typedef map<string,command_t> command_map;
+ typedef std::map<std::string,command_t> command_map;
command_map _commands;
static OpenThreads::Mutex _instanceMutex;