* Author : Maxim Mamontov <faust@stargazer.dp.ua>
*/
-#ifndef __STG_SGCONF_ACTIONS_H__
-#define __STG_SGCONF_ACTIONS_H__
+#pragma once
#include "action.h"
#include "options.h"
#include "parser_state.h"
#include "stg/common.h"
-#include "stg/resetable.h"
+#include "stg/optional.h"
#include <string>
class PARAM_ACTION : public ACTION
{
public:
- PARAM_ACTION(RESETABLE<T> & param,
+ PARAM_ACTION(STG::Optional<T> & param,
const T & defaultValue,
const std::string & paramDescription)
: m_param(param),
m_description(paramDescription),
m_hasDefault(true)
{}
- PARAM_ACTION(RESETABLE<T> & param,
+ PARAM_ACTION(STG::Optional<T> & param)
+ : m_param(param),
+ m_hasDefault(false)
+ {}
+ PARAM_ACTION(STG::Optional<T> & param,
const std::string & paramDescription)
: m_param(param),
m_description(paramDescription),
virtual void ParseValue(const std::string & value);
private:
- RESETABLE<T> & m_param;
+ STG::Optional<T> & m_param;
T m_defaltValue;
std::string m_description;
bool m_hasDefault;
inline
std::string PARAM_ACTION<T>::DefaultDescription() const
{
-return m_hasDefault ? " (default: '" + x2str(m_defaltValue) + "')"
+return m_hasDefault ? " (default: '" + std::to_string(m_defaltValue) + "')"
: "";
}
return PARSER_STATE(false, --argc, ++argv);
}
+template <>
+inline
+PARSER_STATE PARAM_ACTION<bool>::Parse(int argc, char ** argv, void * /*data*/)
+{
+m_param = true;
+return PARSER_STATE(false, argc, argv);
+}
+
template <typename T>
inline
void PARAM_ACTION<T>::ParseValue(const std::string & stringValue)
template <typename T>
inline
-PARAM_ACTION<T> * MakeParamAction(RESETABLE<T> & param,
+PARAM_ACTION<T> * MakeParamAction(STG::Optional<T> & param,
const T & defaultValue,
const std::string & paramDescription)
{
template <typename T>
inline
-PARAM_ACTION<T> * MakeParamAction(RESETABLE<T> & param,
+PARAM_ACTION<T> * MakeParamAction(STG::Optional<T> & param)
+{
+return new PARAM_ACTION<T>(param);
+}
+
+template <typename T>
+inline
+PARAM_ACTION<T> * MakeParamAction(STG::Optional<T> & param,
const std::string & paramDescription)
{
return new PARAM_ACTION<T>(param, paramDescription);
}
} // namespace SGCONF
-
-#endif