4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Traits inline template implementation */
35 #include <boost/format.hpp>
36 #include <senf/Utils/TypeInfo.hh>
38 #define prefix_ inline
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // senf::console::detail::ReturnValueTraits<Type>
45 prefix_ void senf::console::ReturnValueTraits<Type>::format(Type const & value,
48 senf_console_format_value(value, os);
52 prefix_ void senf::console::senf_console_format_value(Type const & value, std::ostream & os)
57 //-/////////////////////////////////////////////////////////////////////////////////////////////////
58 // senf::console::ArgumentTraits<Type>
61 prefix_ void senf::console::ArgumentTraits<Type>::
62 parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
64 senf_console_parse_argument(tokens,out);
68 prefix_ void senf::console::parse(ParseCommandInfo::TokensRange const & tokens, Type & out)
70 ArgumentTraits<Type>::parse(tokens, out);
74 prefix_ std::string senf::console::str(Type const & value)
76 return ArgumentTraits<Type>::str(value);
80 prefix_ void senf::console::format(Type const & value, std::ostream & os)
82 ReturnValueTraits<Type>::format(value, os);
86 prefix_ std::string senf::console::ArgumentTraits<Type>::description()
88 return prettyBaseName(typeid(Type));
92 prefix_ std::string senf::console::ArgumentTraits<Type>::str(Type const & value)
95 senf::console::format(value, ss);
96 std::string rv (ss.str());
98 if (rv.empty() || ! boost::algorithm::all(rv, CommandParser::isWordChar)) {
99 for (std::string::size_type i (0); i < rv.size(); ++i)
100 if (rv[i] == '"' || rv[i] == '\\')
102 else if (rv[i] < ' ' || rv[i] > 126) {
103 rv.insert(i+1, (boost::format("x%02x")
104 % unsigned(static_cast<unsigned char>(rv[i]))).str().c_str());
117 //-/////////////////////////////////////////////////////////////////////////////////////////////////
118 // senf::console::detail::CharArgumentTraits<CharT>
120 template <class CharT>
121 prefix_ void senf::console::detail::CharArgumentTraits<CharT>::
122 parse(ParseCommandInfo::TokensRange const & tokens, CharT & out)
124 typename base::type v;
125 base::parse(tokens,v);
129 template <class CharT>
130 prefix_ std::string senf::console::detail::CharArgumentTraits<CharT>::description()
132 return std::numeric_limits<CharT>::is_signed ? "byte" : "ubyte";
135 //-/////////////////////////////////////////////////////////////////////////////////////////////////
142 // comment-column: 40
143 // c-file-style: "senf"
144 // indent-tabs-mode: nil
145 // ispell-local-dictionary: "american"
146 // compile-command: "scons -u test"