Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Traits.hh

Go to the documentation of this file.
00001 // $Id: Traits.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Scheduler_Console_Traits_
00027 #define HH_SENF_Scheduler_Console_Traits_ 1
00028 
00029 // Custom includes
00030 #include <iostream>
00031 #include <boost/intrusive_ptr.hpp>
00032 #include <boost/type_traits/is_same.hpp>
00033 #include <senf/Utils/intrusive_refcount.hh>
00034 #include "Parse.hh"
00035 
00036 #include "Traits.ih"
00037 //#include "Traits.mpp"
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 
00040 namespace senf {
00041 namespace console {
00042 
00062     template <class Type>
00063     struct ArgumentTraits
00064     {
00065         typedef Type type;
00066 
00067         static bool const singleToken =
00068             boost::is_same< typeof(senf_console_parse_argument(
00069                                        *static_cast<ParseCommandInfo::TokensRange const *>(0),
00070                                        *static_cast<Type*>(0))),
00071                             bool >::value;
00072 
00073         static void parse(ParseCommandInfo::TokensRange const & tokens, Type & out);
00075 
00083         static std::string description(); 
00084 
00086         static std::string str(Type const & value); 
00087 
00091     };
00092 
00099     template <class Type>
00100     bool senf_console_parse_argument(ParseCommandInfo::TokensRange const & tokens, Type & out);
00101 
00102 
00115     template <class Type>
00116     struct ReturnValueTraits
00117     {
00118         typedef Type type;
00119 
00120         static void format(Type const & value, std::ostream & os);
00122     };
00123 
00130     template <class Type>
00131     void senf_console_format_value(Type const & value, std::ostream & os);
00132 
00133 
00141     template <class Type>
00142     void parse(ParseCommandInfo::TokensRange const & tokens, Type & out);
00143 
00150     template <class Type>
00151     std::string str(Type const & value);
00152 
00160     template <class Type>
00161     void format(Type const & value, std::ostream & os);
00162 
00163 
00190 #   define SENF_CONSOLE_REGISTER_ENUM(Type, Values) \
00191         SENF_CONSOLE_REGISTER_ENUM_(BOOST_PP_EMPTY(), Type, Values)
00192 
00208 #   define SENF_CONSOLE_REGISTER_ENUM_MEMBER(Class, Type, Values) \
00209         SENF_CONSOLE_REGISTER_ENUM_(Class::, Type, Values)
00210 
00211 
00213     void formatTrueFalse(bool value, std::ostream & os);
00214 
00216     void formatYesNo(bool value, std::ostream & os);
00217 
00219     void formatEnabledDisabled(bool value, std::ostream & os);
00220 
00222     void formatOnOff(bool value, std::ostream & os);
00223 
00225     void formatOneZero(bool value, std::ostream & os);
00226 
00227 
00228 #ifndef DOXYGEN
00229 
00230     // Parse bool: true/false, yes/no, enabled/disabled, 0/1
00231     template <>
00232     struct ArgumentTraits<bool>
00233     {
00234         typedef bool type;
00235         static bool const singleToken = true;
00236 
00237         static void parse(ParseCommandInfo::TokensRange const & tokens, bool & out);
00238         static std::string description();
00239         static std::string str(bool value);
00240     };
00241 
00242     template <>
00243     struct ReturnValueTraits<bool>
00244     {
00245         typedef bool type;
00246 
00247         static void format(bool value, std::ostream & os);
00248     };
00249 
00250     template <> struct ArgumentTraits<char> : public detail::CharArgumentTraits<char> {};
00251     template <> struct ReturnValueTraits<char> : public detail::CharReturnValueTraits<char> {};
00252     template <> struct ArgumentTraits<signed char> : public detail::CharArgumentTraits<signed char> {};
00253     template <> struct ReturnValueTraits<signed char> : public detail::CharReturnValueTraits<signed char> {};
00254     template <> struct ArgumentTraits<unsigned char> : public detail::CharArgumentTraits<unsigned char> {};
00255     template <> struct ReturnValueTraits<unsigned char> : public detail::CharReturnValueTraits<unsigned char> {};
00256 
00257 #endif
00258 
00259 }}
00260 
00261 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00262 #include "Traits.cci"
00263 #include "Traits.ct"
00264 #include "Traits.cti"
00265 #endif
00266 
00267 
00268 // Local Variables:
00269 // mode: c++
00270 // fill-column: 100
00271 // comment-column: 40
00272 // c-file-style: "senf"
00273 // indent-tabs-mode: nil
00274 // ispell-local-dictionary: "american"
00275 // compile-command: "scons -u test"
00276 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research