+ virtual bool operator()(const SGCONF::CONFIG & config,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options) = 0;
+ virtual COMMAND_FUNCTOR * Clone() = 0;
+};
+
+class COMMAND
+{
+ public:
+ COMMAND(COMMAND_FUNCTOR * funPtr,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options)
+ : m_funPtr(funPtr->Clone()),
+ m_arg(arg),
+ m_options(options)
+ {}
+ COMMAND(const COMMAND & rhs)
+ : m_funPtr(rhs.m_funPtr->Clone()),
+ m_arg(rhs.m_arg),
+ m_options(rhs.m_options)
+ {}
+ ~COMMAND()
+ {
+ delete m_funPtr;
+ }
+ bool Execute(const SGCONF::CONFIG & config) const
+ {
+ return (*m_funPtr)(config, m_arg, m_options);
+ }
+
+ private:
+ COMMAND_FUNCTOR * m_funPtr;
+ std::string m_arg;
+ std::map<std::string, std::string> m_options;
+};
+
+class COMMANDS
+{
+ public:
+ void Add(COMMAND_FUNCTOR * funPtr,
+ const std::string & arg,
+ const std::map<std::string, std::string> & options) { m_commands.push_back(COMMAND(funPtr, arg, options)); }
+ bool Execute(const SGCONF::CONFIG & config) const
+ {
+ std::list<COMMAND>::const_iterator it(m_commands.begin());
+ bool res = true;
+ while (it != m_commands.end() && res)
+ {
+ res = res && it->Execute(config);
+ ++it;
+ }
+ return res;
+ }
+ private:
+ std::list<COMMAND> m_commands;