// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // 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 Traits inline non-template implementation */ #include "Traits.ih" // Custom includes #include #define prefix_ inline //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ArgumentTraits prefix_ void senf::console::ArgumentTraits::parse(ParseCommandInfo::TokensRange const & tokens, bool & out) { if (tokens.size() != 1) throw SyntaxErrorException("argument syntax error"); if ( boost::istarts_with(std::string("true"), tokens.begin()->value()) || boost::istarts_with(std::string("enabled"), tokens.begin()->value()) || boost::istarts_with(std::string("yes"), tokens.begin()->value()) || boost::iequals(std::string("on"), tokens.begin()->value()) ) out = true; else if (boost::istarts_with(std::string("false"), tokens.begin()->value()) || boost::istarts_with(std::string("disabled"), tokens.begin()->value()) || boost::istarts_with(std::string("no"), tokens.begin()->value()) || (boost::istarts_with(std::string("off"), tokens.begin()->value()) && tokens.begin()->value().size() >= 2) ) out = false; else { int v (0); senf::console::parse(tokens, v); out = v; } } prefix_ std::string senf::console::ArgumentTraits::description() { return "bool"; } prefix_ std::string senf::console::ArgumentTraits::str(bool value) { return value ? "true" : "false"; } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ReturnValueTraits prefix_ void senf::console::ReturnValueTraits::format(bool value, std::ostream & os) { formatTrueFalse(value, os); } //-///////////////////////////////////////////////////////////////////////////////////////////////// prefix_ void senf::console::formatTrueFalse(bool value, std::ostream & os) { os << (value ? "true" : "false"); } prefix_ void senf::console::formatYesNo(bool value, std::ostream & os) { os << (value ? "yes" : "no"); } prefix_ void senf::console::formatEnabledDisabled(bool value, std::ostream & os) { os << (value ? "enabled" : "disabled"); } prefix_ void senf::console::formatOnOff(bool value, std::ostream & os) { os << (value ? "on" : "off"); } prefix_ void senf::console::formatOneZero(bool value, std::ostream & os) { os << (value ? "0" : "1"); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ // 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: