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.cci

Go to the documentation of this file.
00001 // $Id: Traits.cci 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 #include "Traits.ih"
00027 
00028 // Custom includes
00029 #include <boost/algorithm/string/predicate.hpp>
00030 
00031 #define prefix_ inline
00032 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00033 
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 // senf::console::ArgumentTraits<bool>
00036 
00037 prefix_ void
00038 senf::console::ArgumentTraits<bool>::parse(ParseCommandInfo::TokensRange const & tokens,
00039                                            bool & out)
00040 {
00041     if (tokens.size() != 1)
00042         throw SyntaxErrorException("argument syntax error");
00043 
00044     if ( boost::istarts_with(std::string("true"), tokens.begin()->value())
00045          || boost::istarts_with(std::string("enabled"), tokens.begin()->value())
00046          || boost::istarts_with(std::string("yes"), tokens.begin()->value())
00047          || boost::iequals(std::string("on"), tokens.begin()->value()) )
00048         out = true;
00049     else if (boost::istarts_with(std::string("false"), tokens.begin()->value())
00050              || boost::istarts_with(std::string("disabled"), tokens.begin()->value())
00051              || boost::istarts_with(std::string("no"), tokens.begin()->value())
00052              || (boost::istarts_with(std::string("off"), tokens.begin()->value())
00053                  && tokens.begin()->value().size() >= 2) )
00054         out = false;
00055     else {
00056         int v (0);
00057         senf::console::parse(tokens, v);
00058         out = v;
00059     }
00060 }
00061 
00062 prefix_ std::string senf::console::ArgumentTraits<bool>::description()
00063 {
00064     return "bool";
00065 }
00066 
00067 prefix_ std::string senf::console::ArgumentTraits<bool>::str(bool value)
00068 {
00069     return value ? "true" : "false";
00070 }
00071 
00072 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00073 // senf::console::ReturnValueTraits<bool>
00074 
00075 prefix_ void senf::console::ReturnValueTraits<bool>::format(bool value, std::ostream & os)
00076 {
00077     formatTrueFalse(value, os);
00078 }
00079 
00080 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00081 
00082 prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os)
00083 {
00084     os << (value ? "true" : "false");
00085 }
00086 
00087 prefix_ void senf::console::formatYesNo(bool value, std::ostream & os)
00088 {
00089     os << (value ? "yes" : "no");
00090 }
00091 
00092 prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os)
00093 {
00094     os << (value ? "enabled" : "disabled");
00095 }
00096 
00097 prefix_ void senf::console::formatOnOff(bool value, std::ostream & os)
00098 {
00099     os << (value ? "on" : "off");
00100 }
00101 
00102 prefix_ void senf::console::formatOneZero(bool value, std::ostream & os)
00103 {
00104     os << (value ? "0" : "1");
00105 }
00106 
00107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00108 #undef prefix_
00109 
00110 
00111 // Local Variables:
00112 // mode: c++
00113 // fill-column: 100
00114 // comment-column: 40
00115 // c-file-style: "senf"
00116 // indent-tabs-mode: nil
00117 // ispell-local-dictionary: "american"
00118 // compile-command: "scons -u test"
00119 // End:

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