Skip to content
Snippets Groups Projects
Commit 0b029965 authored by Nicolas Mansard's avatar Nicolas Mansard
Browse files

Added a function to access directly a given command, with protection.

parent 59d7efc3
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,7 @@ namespace dynamicgraph
{
public:
typedef std::map< std::string,SignalBase<int>* > SignalMap;
typedef std::map<const std::string, command::Command*> CommandMap_t;
static const std::string CLASS_NAME;
......@@ -87,10 +88,8 @@ namespace dynamicgraph
}
virtual const std::string& getCommandList () const;
/// Return the list of command objects
virtual std::map<const std::string, command::Command*>
getNewStyleCommandMap();
virtual CommandMap_t getNewStyleCommandMap();
command::Command* getNewStyleCommand( const std::string& cmdName );
virtual SignalMap getSignalMap() const;
protected:
......@@ -107,7 +106,7 @@ namespace dynamicgraph
std::string name;
SignalMap signalMap;
std::map<const std::string, command::Command*> commandMap;
CommandMap_t commandMap;
};
DYNAMIC_GRAPH_DLLAPI std::ostream&
......
......@@ -284,15 +284,29 @@ addCommand(const std::string& inName, Command* command)
{
if (commandMap.count(inName) != 0) {
DG_THROW ExceptionFactory(ExceptionFactory::OBJECT_CONFLICT,
"Command " + inName +
"Command " + inName +
" already registered in Entity.");
}
std::pair<const std::string, Command*> item(inName, command);
commandMap.insert(item);
}
/// Return the list of command objects
std::map<const std::string, Command*> Entity::
getNewStyleCommandMap()
{
return commandMap;
}
Command* Entity::
getNewStyleCommand( const std::string& commandName )
{
if (commandMap.count(commandName) != 1)
{
DG_THROW ExceptionFactory(ExceptionFactory::UNREFERED_FUNCTION,
"Command <" + commandName +
"> is not registered in Entity.");
}
return commandMap[commandName];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment