X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FParsedCommand.cti;h=029fa2deddf61db82e7149b733e63075d85db2fe;hb=81a550d520e8531b7f353e1ce0da5b99c249cecb;hp=e37906c81b4a5a91fa8d2e5b7b4d9517defd406e;hpb=63c40810b93b4d8f3d6dad5f987adc5f2bf5b5ed;p=senf.git diff --git a/Console/ParsedCommand.cti b/Console/ParsedCommand.cti index e37906c..029fa2d 100644 --- a/Console/ParsedCommand.cti +++ b/Console/ParsedCommand.cti @@ -28,7 +28,7 @@ // Custom includes #include "../Utils/membind.hh" #include -#include +#include "../Utils/parameter.hh" #define prefix_ inline ///////////////////////////////cti.p/////////////////////////////////////// @@ -99,6 +99,13 @@ prefix_ void senf::console::ParsedCommandAttributorBase::defaultValue(Type const overload().arg(index_).hasDefault = true; } +template +prefix_ void senf::console::ParsedCommandAttributorBase::parser(Fn fn) + const +{ + overload().arg(index_).parser = fn; +} + /////////////////////////////////////////////////////////////////////////// // senf::console::ParsedCommandAttributor @@ -119,9 +126,43 @@ senf::console::ParsedCommandAttributor::ParsedCommandAttributor(Overlo /////////////////////////////////////////////////////////////////////////// // senf::console::ParsedArgumentAttributorBase +template +prefix_ Self +senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) + const +{ + this->ParsedCommandAttributorBase::nodeDoc(doc); + return static_cast(*this); +} + +template +prefix_ Self senf::console::ParsedArgumentAttributorBase:: +overloadDoc(std::string const & doc) + const +{ + this->ParsedCommandAttributorBase::overloadDoc(doc); + return static_cast(*this); +} + +template +prefix_ Self senf::console::ParsedArgumentAttributorBase:: +formatter(typename Overload::Formatter f) + const +{ + this->overload().formatter(f); + return static_cast(*this); +} + +template +prefix_ +senf::console::ParsedArgumentAttributorBase:: +ParsedArgumentAttributorBase(Overload & overload, unsigned index) + : ParsedCommandAttributor (overload, index) +{} + template prefix_ Self -senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) +senf::console::ParsedArgumentAttributorBase::doc(std::string const & doc) const { this->ParsedCommandAttributorBase::nodeDoc(doc); @@ -129,7 +170,7 @@ senf::console::ParsedArgumentAttributorBase::doc(std::string cons } template -prefix_ Self senf::console::ParsedArgumentAttributorBase:: +prefix_ Self senf::console::ParsedArgumentAttributorBase:: overloadDoc(std::string const & doc) const { @@ -139,7 +180,7 @@ overloadDoc(std::string const & doc) template prefix_ -senf::console::ParsedArgumentAttributorBase:: +senf::console::ParsedArgumentAttributorBase:: ParsedArgumentAttributorBase(Overload & overload, unsigned index) : ParsedCommandAttributor (overload, index) {} @@ -162,12 +203,15 @@ senf::console::ParsedArgumentAttributor:: argInfo(ArgumentPack const & args) const { -# define HaveArg(tag) boost::is_same< \ - typename boost::parameter::binding::type, void >() +# define ProcessArg(tag) \ + argInfo( kw:: tag, args, senf::has_parameter< ArgumentPack, kw::type:: tag >() ) - argInfo( kw::name, args, HaveArg(kw::type::name) ); - argInfo( kw::description, args, HaveArg(kw::type::description) ); - argInfo( kw::default_value, args, HaveArg(kw::type::default_value) ); + ProcessArg(name); + ProcessArg(description); + ProcessArg(default_value); + ProcessArg(type_name); + ProcessArg(default_doc); + ProcessArg(parser); return next(); @@ -177,7 +221,7 @@ argInfo(ArgumentPack const & args) template template prefix_ void senf::console::ParsedArgumentAttributor:: -argInfo(Kw const &, ArgumentPack const &, boost::mpl::true_) +argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_) const {} @@ -185,7 +229,7 @@ template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, - boost::mpl::false_) + boost::mpl::true_) const { this->argName(args[kw::name]); @@ -195,7 +239,7 @@ template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, - boost::mpl::false_) + boost::mpl::true_) const { this->argDoc(args[kw::description]); @@ -205,13 +249,44 @@ template template prefix_ void senf::console::ParsedArgumentAttributor:: argInfo(boost::parameter::keyword const &, ArgumentPack const & args, - boost::mpl::false_) + boost::mpl::true_) const { this->defaultValue(args[kw::default_value]); } template +template +prefix_ void senf::console::ParsedArgumentAttributor:: +argInfo(boost::parameter::keyword const &, ArgumentPack const & args, + boost::mpl::true_) + const +{ + this->typeName(args[kw::type_name]); +} + +template +template +prefix_ void senf::console::ParsedArgumentAttributor:: +argInfo(boost::parameter::keyword const &, ArgumentPack const & args, + boost::mpl::true_) + const +{ + 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_) + const +{ + this->parser(args[kw::parser]); +} + +template prefix_ senf::console::ParsedArgumentAttributor:: ParsedArgumentAttributor(Overload & overload) @@ -231,7 +306,15 @@ prefix_ void senf::console::ParsedArgumentAttributor:: defaultValue(value_type const & value) const { - ParsedCommandAttributorBase::defaultValue(value); + ParsedCommandAttributorBase::defaultValue(value); +} + +template +template +prefix_ void senf::console::ParsedArgumentAttributor::parser(Fn fn) + const +{ + ParsedCommandAttributorBase::parser(fn); } /////////////////////////////////////////////////////////////////////////// @@ -330,23 +413,6 @@ senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & n senf::membind(fn,&owner)) ) ); } -/////////////////////////////////////////////////////////////////////////// -// senf::console::detail::CheckVoidReturn - -template -template -prefix_ void senf::console::detail::CheckVoidReturn::call(Fn fn, std::ostream & os) -{ - ReturnValueTraits::format(fn(),os); - os << "\n"; -} - -template -prefix_ void senf::console::detail::CheckVoidReturn::call(Fn fn, std::ostream & os) -{ - fn(); -} - ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_