#include "parser_state.h"
#include "stg/common.h"
-#include "stg/optional.h"
#include <string>
+#include <optional>
#include <cassert>
class FUNC0_ACTION : public ACTION
{
public:
- FUNC0_ACTION(const F & func) : m_func(func) {}
+ explicit FUNC0_ACTION(const F & func) : m_func(func) {}
- virtual ACTION * Clone() const { return new FUNC0_ACTION<F>(*this); }
-
- 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, void * /*data*/)
+ std::string ParamDescription() const override { return ""; }
+ std::string DefaultDescription() const override { return ""; }
+ OPTION_BLOCK & Suboptions() override { return m_suboptions; }
+ PARSER_STATE Parse(int argc, char ** argv, void * /*data*/) override
{
- m_func();
- return PARSER_STATE(true, argc, argv);
+ m_func();
+ return PARSER_STATE(true, argc, argv);
}
private:
template <typename F>
inline
-FUNC0_ACTION<F> * MakeFunc0Action(F func)
+std::unique_ptr<ACTION> MakeFunc0Action(F func)
{
-return new FUNC0_ACTION<F>(func);
+return std::make_unique<FUNC0_ACTION<F>>(func);
}
template <typename T>
class PARAM_ACTION : public ACTION
{
public:
- PARAM_ACTION(STG::Optional<T> & param,
+ PARAM_ACTION(std::optional<T> & param,
const T & defaultValue,
const std::string & paramDescription)
: m_param(param),
m_description(paramDescription),
m_hasDefault(true)
{}
- PARAM_ACTION(STG::Optional<T> & param)
+ explicit PARAM_ACTION(std::optional<T> & param)
: m_param(param),
m_hasDefault(false)
{}
- PARAM_ACTION(STG::Optional<T> & param,
+ PARAM_ACTION(std::optional<T> & param,
const std::string & paramDescription)
: m_param(param),
m_description(paramDescription),
m_hasDefault(false)
{}
- virtual ACTION * Clone() const { return new PARAM_ACTION<T>(*this); }
-
- 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, void * /*data*/);
- virtual void ParseValue(const std::string & value);
+ std::string ParamDescription() const override { return m_description; }
+ std::string DefaultDescription() const override;
+ OPTION_BLOCK & Suboptions() override { return m_suboptions; }
+ PARSER_STATE Parse(int argc, char ** argv, void * /*data*/) override;
+ void ParseValue(const std::string & value) override;
private:
- STG::Optional<T> & m_param;
+ std::optional<T> & m_param;
T m_defaltValue;
std::string m_description;
bool m_hasDefault;
template <typename T>
inline
-PARAM_ACTION<T> * MakeParamAction(STG::Optional<T> & param,
- const T & defaultValue,
- const std::string & paramDescription)
+std::unique_ptr<ACTION> MakeParamAction(std::optional<T> & param,
+ const T & defaultValue,
+ const std::string & paramDescription)
{
-return new PARAM_ACTION<T>(param, defaultValue, paramDescription);
+return std::make_unique<PARAM_ACTION<T>>(param, defaultValue, paramDescription);
}
template <typename T>
inline
-PARAM_ACTION<T> * MakeParamAction(STG::Optional<T> & param)
+std::unique_ptr<ACTION> MakeParamAction(std::optional<T> & param)
{
-return new PARAM_ACTION<T>(param);
+return std::make_unique<PARAM_ACTION<T>>(param);
}
template <typename T>
inline
-PARAM_ACTION<T> * MakeParamAction(STG::Optional<T> & param,
- const std::string & paramDescription)
+std::unique_ptr<ACTION> MakeParamAction(std::optional<T> & param,
+ const std::string & paramDescription)
{
-return new PARAM_ACTION<T>(param, paramDescription);
+return std::make_unique<PARAM_ACTION<T>>(param, paramDescription);
}
class KV_ACTION : public ACTION
m_description(paramDescription)
{}
- virtual ACTION * Clone() const { return new KV_ACTION(*this); }
-
- 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, void * data);
+ std::string ParamDescription() const override { return m_description; }
+ std::string DefaultDescription() const override { return ""; }
+ OPTION_BLOCK & Suboptions() override { return m_suboptions; }
+ PARSER_STATE Parse(int argc, char ** argv, void * data) override;
private:
std::string m_name;
}
inline
-KV_ACTION * MakeKVAction(const std::string & name,
- const std::string & paramDescription)
+std::unique_ptr<ACTION> MakeKVAction(const std::string & name,
+ const std::string & paramDescription)
{
-return new KV_ACTION(name, paramDescription);
+return std::make_unique<KV_ACTION>(name, paramDescription);
}
} // namespace SGCONF