// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \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: