From 0b0299657dc7bce1a46fa538f1bad52ff14795c2 Mon Sep 17 00:00:00 2001 From: Mansard <nmansard@laas.fr> Date: Tue, 25 Jan 2011 11:49:18 +0100 Subject: [PATCH] Added a function to access directly a given command, with protection. --- include/dynamic-graph/entity.h | 9 ++++----- src/dgraph/entity.cpp | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/dynamic-graph/entity.h b/include/dynamic-graph/entity.h index 2cd095c..17c814f 100644 --- a/include/dynamic-graph/entity.h +++ b/include/dynamic-graph/entity.h @@ -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& diff --git a/src/dgraph/entity.cpp b/src/dgraph/entity.cpp index 83a920a..3ea8900 100644 --- a/src/dgraph/entity.cpp +++ b/src/dgraph/entity.cpp @@ -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]; +} + -- GitLab