template <class CharT>
prefix_ std::string senf::console::detail::CharArgumentTraits<CharT>::description()
{
- return std::numeric_limits<CharT>::is_signed ? "byte" : "unsigned byte";
+ return std::numeric_limits<CharT>::is_signed ? "byte" : "ubyte";
}
///////////////////////////////cti.e///////////////////////////////////////
// Custom includes
#include <sstream>
+#include <limits>
#include <boost/format.hpp>
+#include "Traits.hh"
#define prefix_
///////////////////////////////ct.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
+// senf::console::ArgumentTraits< CharAsString<CharT> >
+
+template <class CharT>
+prefix_ void senf::console::ArgumentTraits< senf::console::CharAsString<CharT> >::
+parse(ParseCommandInfo::TokensRange const & tokens, CharAsString<CharT> & out)
+{
+ std::string v;
+ senf::console::parse(tokens,v);
+ if (v.size() != 1)
+ throw SyntaxErrorException("Invalid size of character constant");
+ out.value = static_cast<CharT>(v[0]);
+}
+
+template <class CharT>
+prefix_ std::string
+senf::console::ArgumentTraits< senf::console::CharAsString<CharT> >::description()
+{
+ return std::numeric_limits<CharT>::is_signed ? "char" : "uchar";
+}
+
+template <class CharT>
+prefix_ std::string senf::console::ArgumentTraits< senf::console::CharAsString<CharT> >::
+str(CharAsString<CharT> value)
+{
+ return senf::console::str(std::string(1,value.value));
+}
+
+template <class CharT>
+prefix_ void senf::console::ReturnValueTraits< senf::console::CharAsString<CharT> >::
+format(CharAsString<CharT> value, std::ostream & os)
+{
+ return senf::console::format(std::string(1,value.value),os);
+}
+
+///////////////////////////////////////////////////////////////////////////
// senf::console::ArgumentTraits< senf::console::ValueRange<T> >
template <class T>
--- /dev/null
+// $Id$
+//
+// Copyright (C) 2009
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/** \file
+ \brief Utility inline template implementation */
+
+//#include "Utility.ih"
+
+// Custom includes
+
+#define prefix_ inline
+///////////////////////////////cti.p///////////////////////////////////////
+
+template <class CharT>
+prefix_ senf::console::CharAsString<CharT>::CharAsString()
+ : value ()
+{}
+
+template <class CharT>
+prefix_ senf::console::CharAsString<CharT>::CharAsString(CharT value_)
+ : value (value_)
+{}
+
+template <class CharT>
+prefix_ senf::console::CharAsString<CharT>::operator CharT ()
+ const
+{
+ return value;
+}
+
+///////////////////////////////cti.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// comment-column: 40
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// End:
namespace senf {
namespace console {
+ template <class CharT>
+ struct CharAsString
+ {
+ CharAsString();
+ CharAsString(CharT value_);
+ operator CharT () const;
+ CharT value;
+ };
+
+#ifndef DOXYGEN
+
+ template <class CharT>
+ struct ArgumentTraits< CharAsString<CharT> >
+ {
+ typedef CharAsString<CharT> type;
+ static bool const singleToken = true;
+
+ static void parse(ParseCommandInfo::TokensRange const & tokens, CharAsString<CharT> & out);
+ static std::string description();
+ static std::string str(CharAsString<CharT> value);
+ };
+
+ template <class CharT>
+ struct ReturnValueTraits< CharAsString<CharT> >
+ {
+ typedef CharAsString<CharT> type;
+
+ static void format(CharAsString<CharT> value, std::ostream & os);
+ };
+
+#endif
+
/** \brief Value range
A value range may be represented in the console either by a single value (setting both \a
///////////////////////////////hh.e////////////////////////////////////////
//#include "Utility.cci"
#include "Utility.ct"
-//#include "Utility.cti"
+#include "Utility.cti"
#endif
\f
namespace {
+ char charTest(char value) { return value; }
+
enum TestEnum { Foo=1, Bar=2, FooBar=4 };
SENF_CONSOLE_REGISTER_ENUM( TestEnum, (Foo)(Bar)(FooBar) );
}
+BOOST_AUTO_UNIT_TEST(charAsString)
+{
+ senf::console::Executor executor;
+ senf::console::CommandParser parser;
+ senf::console::ScopedDirectory<> dir;
+ senf::console::root().add("test", dir);
+ std::stringstream ss;
+
+ dir.add("test", boost::function<
+ senf::console::CharAsString<char> (senf::console::CharAsString<char>)>(&charTest));
+
+ ss.str("");
+ SENF_CHECK_NO_THROW(
+ parser.parse("test/test \"\\x01\"",
+ boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
+ BOOST_CHECK_EQUAL( ss.str(), "\x01\n" );
+}
+
BOOST_AUTO_UNIT_TEST(flagCollection)
{
senf::console::Executor executor;