Utils/Console: Add control char escaping to string formatter
[senf.git] / senf / Utils / Console / Traits.cti
index db9163f..f6dd892 100644 (file)
@@ -28,7 +28,7 @@
 // Custom includes
 #include <sstream>
 #include <boost/lexical_cast.hpp>
-#include "../../Utils/TypeInfo.hh"
+#include <senf/Utils/TypeInfo.hh>
 
 #define prefix_ inline
 ///////////////////////////////cti.p///////////////////////////////////////
@@ -66,6 +66,12 @@ prefix_ void senf::console::parse(ParseCommandInfo::TokensRange const & tokens,
 }
 
 template <class Type>
+prefix_ std::string senf::console::str(Type const & value)
+{
+    return ArgumentTraits<Type>::str(value);
+}
+
+template <class Type>
 prefix_ void senf::console::format(Type const & value, std::ostream & os)
 {
     ReturnValueTraits<Type>::format(value, os);
@@ -74,9 +80,7 @@ prefix_ void senf::console::format(Type const & value, std::ostream & os)
 template <class Type>
 prefix_ std::string senf::console::ArgumentTraits<Type>::description()
 {
-    std::string type (prettyName(typeid(Type)));
-    std::string::size_type i (type.rfind(':'));
-    return i == std::string::npos ? type : type.substr(i+1);
+    return prettyBaseName(typeid(Type));
 }
 
 template <class Type>
@@ -87,6 +91,24 @@ prefix_ std::string senf::console::ArgumentTraits<Type>::str(Type const & value)
     return ss.str();
 }
 
+///////////////////////////////////////////////////////////////////////////
+// senf::console::detail::CharArgumentTraits<CharT>
+
+template <class CharT>
+prefix_ void senf::console::detail::CharArgumentTraits<CharT>::
+parse(ParseCommandInfo::TokensRange const & tokens, CharT & out)
+{
+    typename base::type v;
+    base::parse(tokens,v);
+    out = v;
+}
+
+template <class CharT>
+prefix_ std::string senf::console::detail::CharArgumentTraits<CharT>::description()
+{
+    return std::numeric_limits<CharT>::is_signed ? "byte" : "unsigned byte";
+}
+
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_