]> git.stg.codes - stg.git/blobdiff - projects/sgconf/actions.h
Implemented XDG-compliant config file reading.
[stg.git] / projects / sgconf / actions.h
index c88de14dc7f5f306e5b0ee0421485a5945f5724f..33a11347a27fb7a3143380f5dda1a8f3d08435c5 100644 (file)
@@ -89,6 +89,7 @@ class PARAM_ACTION : public ACTION
         virtual std::string DefaultDescription() const;
         virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
         virtual PARSER_STATE Parse(int argc, char ** argv);
+        virtual void ParseValue(const std::string & value);
 
     private:
         RESETABLE<T> & m_param;
@@ -129,6 +130,25 @@ m_param = value;
 return PARSER_STATE(false, --argc, ++argv);
 }
 
+template <typename T>
+inline
+void PARAM_ACTION<T>::ParseValue(const std::string & stringValue)
+{
+if (stringValue.empty())
+    throw ERROR("Missing value.");
+T value;
+if (str2x(stringValue, value))
+    throw ERROR(std::string("Bad value: '") + stringValue + "'");
+m_param = value;
+}
+
+template <>
+inline
+void PARAM_ACTION<std::string>::ParseValue(const std::string & stringValue)
+{
+m_param = stringValue;
+}
+
 template <>
 inline
 PARSER_STATE PARAM_ACTION<std::string>::Parse(int argc, char ** argv)