#include <string>
+#include <cassert>
+
namespace SGCONF
{
virtual std::string ParamDescription() const { return ""; }
virtual std::string DefaultDescription() const { return ""; }
virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
- virtual PARSER_STATE Parse(int argc, char ** argv)
+ virtual PARSER_STATE Parse(int argc, char ** argv, void * /*data*/)
{
m_func();
return PARSER_STATE(true, argc, argv);
virtual std::string ParamDescription() const { return m_description; }
virtual std::string DefaultDescription() const;
virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
- virtual PARSER_STATE Parse(int argc, char ** argv);
+ virtual PARSER_STATE Parse(int argc, char ** argv, void * /*data*/);
virtual void ParseValue(const std::string & value);
private:
template <typename T>
inline
-PARSER_STATE PARAM_ACTION<T>::Parse(int argc, char ** argv)
+PARSER_STATE PARAM_ACTION<T>::Parse(int argc, char ** argv, void * /*data*/)
{
if (argc == 0 ||
argv == NULL ||
template <>
inline
-PARSER_STATE PARAM_ACTION<std::string>::Parse(int argc, char ** argv)
+PARSER_STATE PARAM_ACTION<std::string>::Parse(int argc, char ** argv, void * /*data*/)
{
if (argc == 0 ||
argv == NULL ||
{
public:
KV_ACTION(const std::string & name,
- std::map<std::string, std::string> & kvs,
const std::string & paramDescription)
: m_name(name),
- m_kvs(kvs),
m_description(paramDescription)
{}
virtual std::string ParamDescription() const { return m_description; }
virtual std::string DefaultDescription() const { return ""; }
virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
- virtual PARSER_STATE Parse(int argc, char ** argv);
+ virtual PARSER_STATE Parse(int argc, char ** argv, void * data);
private:
std::string m_name;
- std::map<std::string, std::string> & m_kvs;
std::string m_description;
OPTION_BLOCK m_suboptions;
};
inline
-PARSER_STATE KV_ACTION::Parse(int argc, char ** argv)
+PARSER_STATE KV_ACTION::Parse(int argc, char ** argv, void * data)
{
if (argc == 0 ||
argv == NULL ||
*argv == NULL)
throw ERROR("Missing argument.");
-m_kvs[m_name] = *argv;
+assert(data != NULL && "Expecting container pointer.");
+std::map<std::string, std::string> & kvs = *static_cast<std::map<std::string, std::string>*>(data);
+kvs[m_name] = *argv;
return PARSER_STATE(false, --argc, ++argv);
}
inline
KV_ACTION * MakeKVAction(const std::string & name,
- std::map<std::string, std::string> & kvs,
const std::string & paramDescription)
{
-return new KV_ACTION(name, kvs, paramDescription);
+return new KV_ACTION(name, paramDescription);
}
} // namespace SGCONF