Console: More simple argument parsing (argument iterator wrapper)
[senf.git] / Console / Traits.cti
index e96392f..4ffa5a7 100644 (file)
 /** \file
     \brief Traits inline template implementation */
 
-//#include "Traits.ih"
+#include "Traits.ih"
 
 // Custom includes
+#include <sstream>
+#include <boost/lexical_cast.hpp>
 #include "../Utils/TypeInfo.hh"
 
 #define prefix_ inline
@@ -38,6 +40,12 @@ template <class Type>
 prefix_ void senf::console::ReturnValueTraits<Type>::format(Type const & value,
                                                             std::ostream & os)
 {
+    senf_console_format_value(value, os);
+}
+
+template <class Type>
+prefix_ void senf::console::senf_console_format_value(Type const & value, std::ostream & os)
+{
     os << value;
 }
 
@@ -48,15 +56,13 @@ template <class Type>
 prefix_ void senf::console::ArgumentTraits<Type>::
 parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
 {
-    if (tokens.size() != 1)
-        throw SyntaxErrorException("parameter syntax error");
+    senf_console_parse_argument(tokens,out);
+}
 
-    try {
-        out = boost::lexical_cast<Type>(tokens.begin()[0].value());
-    }
-    catch (std::bad_cast & ex) {
-        throw SyntaxErrorException("parameter syntax error");
-    }
+template <class Type>
+prefix_ void senf::console::parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
+{
+    ArgumentTraits<Type>::parse(tokens, out);
 }
 
 template <class Type>
@@ -70,7 +76,9 @@ prefix_ std::string senf::console::ArgumentTraits<Type>::description()
 template <class Type>
 prefix_ std::string senf::console::ArgumentTraits<Type>::str(Type const & value)
 {
-    return boost::lexical_cast<std::string>(value);
+    std::stringstream ss;
+    senf::console::ReturnValueTraits<Type>::format(value, ss);
+    return ss.str();
 }
 
 ///////////////////////////////cti.e///////////////////////////////////////