1 #ifndef __STG_SGCONF_API_ACTION_H__
2 #define __STG_SGCONF_API_ACTION_H__
15 typedef bool (* API_FUNCTION) (const CONFIG &,
17 const std::map<std::string, std::string> &);
22 COMMAND(API_FUNCTION funPtr,
23 const std::string & arg,
24 const std::map<std::string, std::string> & options)
29 bool Execute(const SGCONF::CONFIG & config) const
31 return m_funPtr(config, m_arg, m_options);
35 API_FUNCTION m_funPtr;
37 std::map<std::string, std::string> m_options;
43 void Add(API_FUNCTION funPtr,
44 const std::string & arg,
45 const std::map<std::string, std::string> & options) { m_commands.push_back(COMMAND(funPtr, arg, options)); }
46 bool Execute(const SGCONF::CONFIG & config) const
48 std::vector<COMMAND>::const_iterator it(m_commands.begin());
50 while (it != m_commands.end() && res)
52 res = res && it->Execute(config);
58 std::vector<COMMAND> m_commands;
61 class API_ACTION : public ACTION
64 API_ACTION(COMMANDS & commands,
65 const std::string & paramDescription,
67 const OPTION_BLOCK& suboptions,
69 : m_commands(commands),
70 m_description(paramDescription),
71 m_argument(needArgument ? "1" : ""), // Hack
72 m_suboptions(suboptions),
75 API_ACTION(COMMANDS & commands,
76 const std::string & paramDescription,
79 : m_commands(commands),
80 m_description(paramDescription),
81 m_argument(needArgument ? "1" : ""), // Hack
85 virtual ACTION * Clone() const { return new API_ACTION(*this); }
87 virtual std::string ParamDescription() const { return m_description; }
88 virtual std::string DefaultDescription() const { return ""; }
89 virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
90 virtual PARSER_STATE Parse(int argc, char ** argv);
93 COMMANDS & m_commands;
94 std::string m_description;
95 std::string m_argument;
96 OPTION_BLOCK m_suboptions;
97 std::map<std::string, std::string> m_params;
98 API_FUNCTION m_funPtr;
102 ACTION * MakeAPIAction(COMMANDS & commands,
103 const std::string & paramDescription,
107 return new API_ACTION(commands, paramDescription, needArgument, funPtr);
111 ACTION * MakeAPIAction(COMMANDS & commands,
114 return new API_ACTION(commands, "", false, funPtr);