X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FParsedCommand.ih;h=391c7dba6fd621af758346bbd9260cfbe7bef033;hb=5b2e9a63a43027c71ac470ac9bdecb72e8974951;hp=0dbe33be296344602a924a35676ac716e58831f5;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/ParsedCommand.ih b/senf/Utils/Console/ParsedCommand.ih index 0dbe33b..391c7db 100644 --- a/senf/Utils/Console/ParsedCommand.ih +++ b/senf/Utils/Console/ParsedCommand.ih @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -31,26 +31,26 @@ #include #include "Parse.hh" -///////////////////////////////ih.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace console { - template < class FunctionTraits, - class ReturnType=typename FunctionTraits::result_type, + template < class FunctionTraits, + class ReturnType=typename FunctionTraits::result_type, unsigned arity=FunctionTraits::arity > class ParsedCommandOverload; - template < class Overload, - unsigned index=0, + template < class Overload, + unsigned index=0, bool flag=(index < unsigned(Overload::traits::arity)) > class ParsedArgumentAttributor; namespace detail { /** \brief Internal: Argument information structure - - This class is used to hold argument information for automatically parsed commands. + + This class is used to hold argument information for automatically parsed commands. \see ParsedCommandOverloadBase */ @@ -58,32 +58,32 @@ namespace detail { : public intrusive_refcount { typedef boost::intrusive_ptr ptr; - + std::string type; std::string name; std::string defaultDoc; bool hasDefault; std::string doc; bool singleToken; - + explicit ArgumentInfoBase(std::string const & type, bool singleToken=false); virtual ~ArgumentInfoBase(); virtual std::string defaultValueStr() const = 0; }; - + /** \brief Internal: Argument information structure - - This class is used to hold argument information for automatically parsed commands. + + This class is used to hold argument information for automatically parsed commands. \see ParsedCommandOverloadBase */ template - struct ArgumentInfo + struct ArgumentInfo : public ArgumentInfoBase { typedef boost::intrusive_ptr ptr; - typedef boost::function Parser; static ptr create(); @@ -94,7 +94,7 @@ namespace detail { virtual std::string defaultValueStr() const; }; - + #ifndef DOXYGEN // FirstArgType returns void, if the function has no arguments, otherwise it returns arg1_type @@ -116,6 +116,7 @@ namespace detail { { static const bool is_callable = false; static const bool is_member = false; + static const bool is_simple = false; }; template @@ -129,8 +130,8 @@ namespace detail { static const bool has_ostream_arg = boost::is_same::value; typedef typename boost::mpl::if_c< - has_ostream_arg, - typename function_traits_remove_arg::type, + has_ostream_arg, + typename function_traits_remove_arg::type, base_traits> ::type traits; @@ -138,7 +139,8 @@ namespace detail { static const bool is_callable = true; static const bool is_member = boost::is_member_pointer::value; - + static const bool is_simple = false; + typedef typename senf::member_class::type class_type; typedef ParsedCommandOverload Overload; @@ -148,21 +150,58 @@ namespace detail { // Disable auto-parsing for ParseCommandInfo arg -> register manually parsed command template struct ParsedCommandTraits_i - {}; + { + static const bool is_simple = true; + }; template struct ParsedCommandTraits - : public ParsedCommandTraits_i< FunctionP, + : public ParsedCommandTraits_i< FunctionP, typename senf::remove_any_pointer::type > {}; struct ParsedCommandAddNodeAccess; + // What is THIS about ?? + + // Ok, here's the dope: parsed commands may optionally have an std::ostream & first argument. If + // this argument is given, then the function will be called with the console output stream as + // it's first argument. + // + // This is implemented in the following way: ParsedCommandOverload (the class responsible for + // calling the callback) will ALWAYS pass the stream as first argument. If the user callback + // expects os as it's first argument, 'ignoreOneArg' will be false and the user supplied + // function will be directly passed to ParsedCommandOverload. + // + // If however, it does NOT take an std::ostream first argument, 'ignoreOneArg' will be true and + // the create member will use boost::bind to DROP the first argument. + + template + struct CreateParsedCommandOverload + {}; + + template + struct CreateParsedCommandOverload + { + typedef typename Traits::traits traits; + + template + static typename senf::console::ParsedCommandOverload::ptr create(Function fn) + { return senf::console::ParsedCommandOverload::create(fn); }; + }; + +# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY, \ + SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp), \ + 4)) +# include BOOST_PP_ITERATE() + #endif }}} -///////////////////////////////ih.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #endif