Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ParsedCommand.hh

Go to the documentation of this file.
00001 // $Id: ParsedCommand.hh 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Scheduler_Console_ParsedCommand_
00027 #define HH_SENF_Scheduler_Console_ParsedCommand_ 1
00028 
00029 // Custom includes
00030 
00031 #define BOOST_PARAMETER_MAX_ARITY 6
00032 
00033 #include <vector>
00034 #include <boost/type_traits/function_traits.hpp>
00035 #include <boost/type_traits/is_member_function_pointer.hpp>
00036 #include <boost/mpl/if.hpp>
00037 #include <boost/utility.hpp>
00038 #include <boost/parameter/keyword.hpp>
00039 #include <boost/parameter/parameters.hpp>
00040 #include <senf/config.hh>
00041 #include "OverloadedCommand.hh"
00042 #include "Traits.hh"
00043 #include <senf/Utils/type_traits.hh>
00044 
00045 #include "ParsedCommand.ih"
00046 #include "ParsedCommand.mpp"
00047 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00048 
00049 namespace senf {
00050 namespace console {
00051 
00052     namespace detail { class ArgumentInfoBase; }
00053 
00136     class ParsedCommandOverloadBase
00137         : public CommandOverload
00138     {
00139     public:
00140         typedef boost::intrusive_ptr<ParsedCommandOverloadBase> ptr;
00141 
00142         detail::ArgumentInfoBase & arg(unsigned n) const;
00143 
00144         void doc(std::string const & d);
00145 
00146     protected:
00147         ParsedCommandOverloadBase();
00148 
00149         template <class Type> void addParameter();
00150 
00151     private:
00152         virtual unsigned v_numArguments() const;
00153         virtual void v_argumentDoc(unsigned index, ArgumentDoc & doc) const;
00154         virtual std::string v_doc() const;
00155 
00156         typedef std::vector<detail::ArgumentInfoBase::ptr> Parameters;
00157         Parameters parameters_;
00158         std::string doc_;
00159     };
00160 
00175     template <class FunctionTraits, class ReturnType, unsigned arity>
00176     class ParsedCommandOverload : public ParsedCommandOverloadBase
00177     {
00178     public:
00179         typedef boost::intrusive_ptr<ParsedCommandOverload> ptr;
00180     };
00181 
00182 #ifndef DOXYGEN
00183 
00184 #   define BOOST_PP_ITERATION_PARAMS_1                                  \
00185         (4, (0, SENF_CONSOLE_MAX_COMMAND_ARITY,                         \
00186              SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp), \
00187              1))
00188 #   include BOOST_PP_ITERATE()
00189 
00190 #endif
00191 
00202     class ParsedCommandAttributorBase
00203         : public detail::NodeFactory
00204     {
00205     public:
00206         typedef OverloadedCommandNode node_type;
00207         typedef OverloadedCommandNode & result_type;
00208 
00209     protected:
00210         ParsedCommandAttributorBase(ParsedCommandOverloadBase::ptr overload, unsigned index);
00211         ParsedCommandAttributorBase(ParsedCommandAttributorBase const & other, unsigned index);
00212 
00213         void argName(std::string const & name);
00214         void argDoc(std::string const & doc);
00215         void typeName(std::string const & doc);
00216         void defaultDoc(std::string const & doc);
00217 
00218         ParsedCommandOverloadBase & overload() const;
00219         void overloadDoc(std::string const & doc);
00220         void nodeDoc(std::string const & doc);
00221         void shortDoc(std::string const & doc);
00222 
00223     private:
00224         OverloadedCommandNode & create(DirectoryNode & dir, std::string const & name) const;
00225 
00226         ParsedCommandOverloadBase::ptr overload_;
00227         unsigned index_;
00228         boost::optional<std::string> doc_;
00229         boost::optional<std::string> shortdoc_;
00230 
00231         friend class senf::console::DirectoryNode;
00232     };
00233 
00244     template <class Overload>
00245     class ParsedCommandAttributor
00246         : public ParsedCommandAttributorBase
00247     {
00248     public:
00249         Overload & overload() const;    
00250 
00251     protected:
00252         ParsedCommandAttributor(typename Overload::ptr overload, unsigned index);
00253         ParsedCommandAttributor(ParsedCommandAttributorBase const & other, unsigned index);
00254 
00255     private:
00256     };
00257 
00317     namespace kw {
00318         BOOST_PARAMETER_KEYWORD(type, name) 
00319 
00320         BOOST_PARAMETER_KEYWORD(type, description) 
00321 
00326         BOOST_PARAMETER_KEYWORD(type, default_value) 
00327 
00367         BOOST_PARAMETER_KEYWORD(type, type_name) 
00368 
00372         BOOST_PARAMETER_KEYWORD(type, default_doc) 
00373 
00379         BOOST_PARAMETER_KEYWORD(type, parser) 
00380 
00397     }
00398 
00409     template <class Overload, class Self, class ReturnType=typename Overload::traits::result_type>
00410     class ParsedArgumentAttributorBase
00411         : public ParsedCommandAttributor<Overload>
00412     {
00413     public:
00414         Self doc(std::string const & doc); 
00415         Self shortdoc(std::string const & doc); 
00416         Self overloadDoc(std::string const & doc); 
00417         Self formatter(typename Overload::Formatter formatter);
00419 
00430     protected:
00431         ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index);
00432         ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index);
00433 
00434     private:
00435     };
00436 
00437 #ifndef DOXYGEN
00438 
00439     template <class Overload, class Self>
00440     class ParsedArgumentAttributorBase<Overload, Self, void>
00441         : public ParsedCommandAttributor<Overload>
00442     {
00443     public:
00444         Self doc(std::string const & doc); 
00445         Self shortdoc(std::string const & doc); 
00446         Self overloadDoc(std::string const & doc); 
00447 
00448     protected:
00449         ParsedArgumentAttributorBase(typename Overload::ptr overload, unsigned index);
00450         ParsedArgumentAttributorBase(ParsedCommandAttributorBase const & other, unsigned index);
00451 
00452     private:
00453     };
00454 
00455 #endif
00456 
00467     template <class Overload, unsigned index, bool flag>
00468     class ParsedArgumentAttributor
00469         : public ParsedArgumentAttributorBase< Overload,
00470                                                 ParsedArgumentAttributor<Overload, index, flag> >
00471     {
00472         typedef boost::parameter::parameters<
00473             kw::type::name,
00474             kw::type::description,
00475             kw::type::default_value,
00476             kw::type::type_name,
00477             kw::type::default_doc,
00478             kw::type::parser> arg_params;
00479 
00480     public:
00481         typedef typename senf::function_traits_arg_type<
00482             typename Overload::traits, int(index) >::type arg_type;
00483         typedef typename senf::remove_cvref< arg_type >::type value_type;
00484         typedef ParsedArgumentAttributor<Overload, index+1> next_type;
00485 
00486         next_type arg() const;          
00487 
00506 #ifndef DOXYGEN
00507 #       define BOOST_PP_ITERATION_PARAMS_1                                                        \
00508             (4, (1, BOOST_PARAMETER_MAX_ARITY,                                                    \
00509                  SENF_ABSOLUTE_INCLUDE_PATH(Utils/Console/ParsedCommand.mpp),                     \
00510                  5))
00511 #       include BOOST_PP_ITERATE()
00512 #endif
00513 
00514     private:
00515         explicit ParsedArgumentAttributor(typename Overload::ptr overload);
00516         explicit ParsedArgumentAttributor(ParsedCommandAttributorBase const & other);
00517 
00518         template <class ArgumentPack>
00519         next_type argInfo(ArgumentPack const & args);
00520         template <class Kw, class ArgumentPack>
00521         void argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_);
00522 
00523         template <class ArgumentPack>
00524         void argInfo(boost::parameter::keyword<kw::type::name> const &,
00525                      ArgumentPack const & args, boost::mpl::true_);
00526         template <class ArgumentPack>
00527         void argInfo(boost::parameter::keyword<kw::type::description> const &,
00528                      ArgumentPack const & args, boost::mpl::true_);
00529         template <class ArgumentPack>
00530         void argInfo(boost::parameter::keyword<kw::type::default_value> const &,
00531                      ArgumentPack const & args, boost::mpl::true_);
00532         template <class ArgumentPack>
00533         void argInfo(boost::parameter::keyword<kw::type::type_name> const &,
00534                      ArgumentPack const & args, boost::mpl::true_);
00535         template <class ArgumentPack>
00536         void argInfo(boost::parameter::keyword<kw::type::default_doc> const &,
00537                      ArgumentPack const & args, boost::mpl::true_);
00538         template <class ArgumentPack>
00539         void argInfo(boost::parameter::keyword<kw::type::parser> const &,
00540                      ArgumentPack const & args, boost::mpl::true_);
00541 
00542         next_type next() const;
00543 
00544         void defaultValue(value_type const & value);
00545         template <class Fn> void parser(Fn fn);
00546 
00547         template <class O, unsigned i, bool f>
00548         friend class ParsedArgumentAttributor;
00549 
00550         friend class detail::ParsedCommandAddNodeAccess;
00551     };
00552 
00553 #ifndef DOXYGEN
00554 
00555     template <class Overload, unsigned index>
00556     class ParsedArgumentAttributor<Overload, index, false>
00557         : public ParsedArgumentAttributorBase< Overload,
00558                                                 ParsedArgumentAttributor<Overload, index, false> >
00559     {
00560     public:
00561         typedef OverloadedCommandNode node_type;
00562         typedef ParsedArgumentAttributor return_type;
00563 
00564     private:
00565         explicit ParsedArgumentAttributor(typename Overload::ptr overload);
00566         explicit ParsedArgumentAttributor(ParsedCommandAttributorBase const & other);
00567 
00568         template <class O, unsigned i, bool f>
00569         friend class ParsedArgumentAttributor;
00570 
00571         friend class detail::ParsedCommandAddNodeAccess;
00572     };
00573 
00574 #endif
00575 
00576 namespace factory {
00577 
00578 #ifdef DOXYGEN
00579 
00614     class Command : public ParsedArgumentAttributor
00615     {
00616     public:
00617         typedef OverloadedCommandNode node_type;
00618         typedef unspecified result_type;
00619 
00620         Command(unspecified fn);        
00621         template <class Signature>
00622         Command(unspecified fn);        
00623 
00626         Command(member_function_pointer fn, Owner const * owner);
00628         template <class Signature>
00629         Command(member_function_pointer fn, Owner const * owner);
00632 
00635     };
00636 
00637 #else
00638 
00639     template <class Signature>
00640     SimpleOverloadAttributor
00641     Command(boost::function<Signature> fn,
00642             typename boost::enable_if_c<detail::ParsedCommandTraits<Signature>::is_simple>::type * = 0);
00643 
00644     template <class Function>
00645     SimpleOverloadAttributor
00646     Command(Function fn,
00647             typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_simple>::type * = 0);
00648 
00649     template <class Owner, class Member>
00650     SimpleOverloadAttributor
00651     Command(Member memfn, Owner * owner,
00652             typename boost::enable_if<boost::is_member_function_pointer<Member> >::type * = 0,
00653             typename boost::enable_if_c<detail::ParsedCommandTraits<Member>::is_simple>::type * = 0);
00654 
00655     template <class Owner, class Member>
00656     SimpleOverloadAttributor
00657     Command(Member memfn, Owner const * owner,
00658             typename boost::enable_if<boost::is_member_function_pointer<Member> >::type * = 0,
00659             typename boost::enable_if_c<detail::ParsedCommandTraits<Member>::is_simple>::type * = 0);
00660 
00661     template <class CastTo, class Signature>
00662     typename senf::console::detail::ParsedCommandTraits<CastTo>::Attributor
00663     Command(boost::function<Signature> fn);
00664 
00665     template <class CastTo, class Function>
00666     typename senf::console::detail::ParsedCommandTraits<CastTo>::Attributor
00667     Command(Function fn,
00668             typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_callable>::type * = 0,
00669             typename boost::disable_if<boost::is_member_function_pointer<Function> >::type * = 0);
00670 
00671     template <class Signature>
00672     typename senf::console::detail::ParsedCommandTraits<Signature>::Attributor
00673     Command(boost::function<Signature> fn);
00674 
00675     template <class Function>
00676     typename senf::console::detail::ParsedCommandTraits<Function>::Attributor
00677     Command(Function fn,
00678             typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_callable>::type * = 0,
00679             typename boost::disable_if<boost::is_member_function_pointer<Function> >::type * = 0);
00680 
00681     template <class Owner, class Member>
00682     typename senf::console::detail::ParsedCommandTraits<Member>::Attributor
00683     Command(Member memfn, Owner * owner,
00684             typename boost::enable_if<boost::is_member_function_pointer<Member> >::type * = 0);
00685 
00686     template <class Owner, class Member>
00687     typename senf::console::detail::ParsedCommandTraits<Member>::Attributor
00688     Command(Member memfn, Owner const * owner,
00689             typename boost::enable_if<boost::is_member_function_pointer<Member> >::type * = 0);
00690 
00691     template <class CastTo, class Owner, class Member>
00692     typename senf::console::detail::ParsedCommandTraits<CastTo>::Attributor
00693     Command(Member memfn, Owner * owner,
00694             typename boost::enable_if<boost::is_member_function_pointer<Member> >::type * = 0);
00695 
00696     template <class CastTo, class Owner, class Member>
00697     typename senf::console::detail::ParsedCommandTraits<CastTo>::Attributor
00698     Command(Member memfn, Owner const * owner,
00699             typename boost::enable_if<boost::is_member_function_pointer<Member> >::type * = 0);
00700 
00701 #endif
00702 
00703 }}}
00704 
00705 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00706 #include "ParsedCommand.cci"
00707 #include "ParsedCommand.ct"
00708 #include "ParsedCommand.cti"
00709 #endif
00710 
00711 
00712 // Local Variables:
00713 // mode: c++
00714 // fill-column: 100
00715 // comment-column: 40
00716 // c-file-style: "senf"
00717 // indent-tabs-mode: nil
00718 // ispell-local-dictionary: "american"
00719 // compile-command: "scons -u test"
00720 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research