// $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 ParsedCommand inline template implementation */ #include "ParsedCommand.ih" // Custom includes #include #include #include #define prefix_ inline //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::ArgumentInfo template prefix_ typename senf::console::detail::ArgumentInfo::ptr senf::console::detail::ArgumentInfo::create() { return ptr(new ArgumentInfo()); } template prefix_ senf::console::detail::ArgumentInfo::ArgumentInfo() : ArgumentInfoBase ( ArgumentTraits::description(), ArgumentTraits::singleToken ), defaultValue () {} template prefix_ std::string senf::console::detail::ArgumentInfo::defaultValueStr() const { return hasDefault ? ArgumentTraits::str(defaultValue) : ""; } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandOverloadBase template prefix_ void senf::console::ParsedCommandOverloadBase::addParameter() { parameters_.push_back(detail::ArgumentInfo::create()); } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandOverload #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp), \ 2)) #include BOOST_PP_ITERATE() //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandAttributor template prefix_ Overload & senf::console::ParsedCommandAttributor::overload() const { return static_cast(ParsedCommandAttributorBase::overload()); } template prefix_ senf::console::ParsedCommandAttributor:: ParsedCommandAttributor(typename Overload::ptr overload, unsigned index) : ParsedCommandAttributorBase (overload, index) {} template prefix_ senf::console::ParsedCommandAttributor:: ParsedCommandAttributor(ParsedCommandAttributorBase const & other, unsigned index) : ParsedCommandAttributorBase (other, index) {} //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributorBase template prefix_ Self senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) { this->ParsedCommandAttributorBase::nodeDoc(doc); return static_cast(*this); } template prefix_ Self senf::console::ParsedArgumentAttributorBase:: shortdoc(std::string const & doc) { this->ParsedCommandAttributorBase::shortDoc(doc); return static_cast(*this); } template prefix_ Self senf::console::ParsedArgumentAttributorBase:: overloadDoc(std::string const & doc) { this->ParsedCommandAttributorBase::overloadDoc(doc); return static_cast(*this); } template prefix_ Self senf::console::ParsedArgumentAttributorBase:: formatter(typename Overload::Formatter f) { this->overload().formatter(f); return static_cast(*this); } template prefix_ senf::console::ParsedArgumentAttributorBase:: ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index) : ParsedCommandAttributor (overload, index) {} template prefix_ senf::console::ParsedArgumentAttributorBase:: ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index) : ParsedCommandAttributor (other, index) {} template prefix_ Self senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) { this->ParsedCommandAttributorBase::nodeDoc(doc); return static_cast(*this); } template prefix_ Self senf::console::ParsedArgumentAttributorBase:: shortdoc(std::string const & doc) { this->ParsedCommandAttributorBase::shortDoc(doc); return static_cast(*this); } template prefix_ Self senf::console::ParsedArgumentAttributorBase:: overloadDoc(std::string const & doc) { this->ParsedCommandAttributorBase::overloadDoc(doc); return static_cast(*this); } template prefix_ senf::console::ParsedArgumentAttributorBase:: ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index) : ParsedCommandAttributor (overload, index) {} template prefix_ senf::console::ParsedArgumentAttributorBase:: ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index) : ParsedCommandAttributor (other, index) {} //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributor template prefix_ typename senf::console::ParsedArgumentAttributor::next_type senf::console::ParsedArgumentAttributor::arg() const { return next(); } template template prefix_ typename senf::console::ParsedArgumentAttributor::next_type senf::console::ParsedArgumentAttributor:: argInfo(ArgumentPack const & args) { # define ProcessArg(tag) \ argInfo( kw:: tag, args, senf::has_parameter< ArgumentPack, kw::type:: tag >() ) ProcessArg(name); ProcessArg(description); ProcessArg(default_value); ProcessArg(type_name); ProcessArg(default_doc); ProcessArg(parser); return next(); # undef ProcessArg } template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_) {} template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) { this->argName(args[kw::name]); } template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) { this->argDoc(args[kw::description]); } template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) { this->defaultValue(args[kw::default_value]); } template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) { this->typeName(args[kw::type_name]); } template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) { BOOST_STATIC_ASSERT(( senf::has_parameter::value )); this->defaultDoc(args[kw::default_doc]); } template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, boost::mpl::true_) { this->parser(args[kw::parser]); } template prefix_ senf::console::ParsedArgumentAttributor:: ParsedArgumentAttributor(typename Overload::ptr overload) : ParsedArgumentAttributorBase (overload, index) {} template prefix_ senf::console::ParsedArgumentAttributor:: ParsedArgumentAttributor(ParsedCommandAttributorBase const & other) : ParsedArgumentAttributorBase (other, index) {} template prefix_ typename senf::console::ParsedArgumentAttributor::next_type senf::console::ParsedArgumentAttributor::next() const { return ParsedArgumentAttributor(*this); } template prefix_ void senf::console::ParsedArgumentAttributor:: defaultValue(value_type const & value) { this->overload().arg().defaultValue = value; this->overload().arg(index).hasDefault = true; } template template prefix_ void senf::console::ParsedArgumentAttributor::parser(Fn fn) { this->overload().arg().parser = fn; } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributor template prefix_ senf::console::ParsedArgumentAttributor:: ParsedArgumentAttributor(typename Overload::ptr overload) : ParsedArgumentAttributorBase< Overload, ParsedArgumentAttributor > (overload, index) {} template prefix_ senf::console::ParsedArgumentAttributor:: ParsedArgumentAttributor(ParsedCommandAttributorBase const & other) : ParsedArgumentAttributorBase (other, index) {} //-///////////////////////////////////////////////////////////////////////////////////////////////// // namespace members namespace senf { namespace console { namespace detail { #ifndef DOXYGEN struct ParsedCommandAddNodeAccess { template static Attributor attributor(NodePtr ptr) { return Attributor(ptr); } }; template typename senf::console::detail::ParsedCommandTraits::Attributor addOverloadedCommandNode(Fn fn) { typedef senf::console::detail::ParsedCommandTraits CmdTraits; typedef senf::console::ParsedCommandOverload Overload; typedef senf::console::ParsedArgumentAttributor Attributor; return detail::ParsedCommandAddNodeAccess::attributor( CreateParsedCommandOverload::create(fn)); } #endif }}} //-///////////////////////////////////////////////////////////////////////////////////////////////// template prefix_ senf::console::SimpleOverloadAttributor senf::console::factory:: Command(boost::function fn, typename boost::enable_if_c::is_simple>::type *) { return SimpleOverloadAttributor(fn); } template prefix_ senf::console::SimpleOverloadAttributor senf::console::factory:: Command(Function fn, typename boost::enable_if_c::is_simple>::type *) { return SimpleOverloadAttributor(fn); } template prefix_ senf::console::SimpleOverloadAttributor senf::console::factory:: Command(Member memfn, Owner * owner, typename boost::enable_if >::type *, typename boost::enable_if_c::is_simple>::type *) { return SimpleOverloadAttributor(senf::membind(memfn,owner)); } template prefix_ senf::console::SimpleOverloadAttributor senf::console::factory:: Command(Member memfn, Owner const * owner, typename boost::enable_if >::type *, typename boost::enable_if_c::is_simple>::type *) { return SimpleOverloadAttributor(senf::membind(memfn,owner)); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(boost::function fn) { return detail::addOverloadedCommandNode(fn); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(Function fn, typename boost::enable_if_c::is_callable>::type *, typename boost::disable_if >::type *) { return detail::addOverloadedCommandNode(fn); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(boost::function fn) { return detail::addOverloadedCommandNode(fn); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(Function fn, typename boost::enable_if_c::is_callable>::type *, typename boost::disable_if >::type *) { return detail::addOverloadedCommandNode(fn); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(Member memfn, Owner * owner, typename boost::enable_if >::type *) { return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(Member memfn, Owner const * owner, typename boost::enable_if >::type *) { return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(Member memfn, Owner * owner, typename boost::enable_if >::type *) { return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); } template prefix_ typename senf::console::detail::ParsedCommandTraits::Attributor senf::console::factory:: Command(Member memfn, Owner const * owner, typename boost::enable_if >::type *) { return detail::addOverloadedCommandNode(senf::membind(memfn,owner)); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #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: