Console: Remove senf_console_add_node() overloads from documentation
[senf.git] / Console / ParsedCommand.cti
index e37906c..61b447f 100644 (file)
@@ -28,7 +28,7 @@
 // Custom includes
 #include "../Utils/membind.hh"
 #include <boost/format.hpp>
-#include <boost/parameter/binding.hpp>
+#include "../Utils/parameter.hh"
 
 #define prefix_ inline
 ///////////////////////////////cti.p///////////////////////////////////////
@@ -67,14 +67,6 @@ prefix_ std::string senf::console::detail::ArgumentInfo<ParameterType>::defaultV
 // senf::console::ParsedCommandOverloadBase
 
 template <class Type>
-prefix_ senf::console::detail::ArgumentInfo<Type> &
-senf::console::ParsedCommandOverloadBase::arg(unsigned n)
-    const
-{
-    return dynamic_cast<detail::ArgumentInfo<Type> &>(arg(n));
-}
-
-template <class Type>
 prefix_ void senf::console::ParsedCommandOverloadBase::addParameter()
 {
     parameters_.push_back(detail::ArgumentInfo<Type>::create());
@@ -89,17 +81,6 @@ prefix_ void senf::console::ParsedCommandOverloadBase::addParameter()
 #include BOOST_PP_ITERATE()
 
 ///////////////////////////////////////////////////////////////////////////
-// senf::console::ParsedCommandAttributorBase
-
-template <class Type>
-prefix_ void senf::console::ParsedCommandAttributorBase::defaultValue(Type const & value)
-    const
-{
-    overload().arg<Type>(index_).defaultValue = value;
-    overload().arg(index_).hasDefault = true;
-}
-
-///////////////////////////////////////////////////////////////////////////
 // senf::console::ParsedCommandAttributor<Overload>
 
 template <class Overload>
@@ -119,9 +100,43 @@ senf::console::ParsedCommandAttributor<Overload>::ParsedCommandAttributor(Overlo
 ///////////////////////////////////////////////////////////////////////////
 // senf::console::ParsedArgumentAttributorBase<Overload,Self>
 
+template <class Overload, class Self, class ReturnType>
+prefix_ Self
+senf::console::ParsedArgumentAttributorBase<Overload,Self,ReturnType>::doc(std::string const & doc)
+    const
+{
+    this->ParsedCommandAttributorBase::nodeDoc(doc);
+    return static_cast<Self const &>(*this);
+}
+
+template <class Overload, class Self, class ReturnType>
+prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self,ReturnType>::
+overloadDoc(std::string const & doc)
+    const
+{
+    this->ParsedCommandAttributorBase::overloadDoc(doc);
+    return static_cast<Self const &>(*this);
+}
+
+template <class Overload, class Self, class ReturnType>
+prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self,ReturnType>::
+formatter(typename Overload::Formatter f)
+    const
+{
+    this->overload().formatter(f);
+    return static_cast<Self const &>(*this);
+}
+
+template <class Overload, class Self, class ReturnType>
+prefix_
+senf::console::ParsedArgumentAttributorBase<Overload,Self,ReturnType>::
+ParsedArgumentAttributorBase(Overload & overload, unsigned index)
+    : ParsedCommandAttributor<Overload> (overload, index)
+{}
+
 template <class Overload, class Self>
 prefix_ Self
-senf::console::ParsedArgumentAttributorBase<Overload,Self>::doc(std::string const & doc)
+senf::console::ParsedArgumentAttributorBase<Overload,Self,void>::doc(std::string const & doc)
     const
 {
     this->ParsedCommandAttributorBase::nodeDoc(doc);
@@ -129,7 +144,7 @@ senf::console::ParsedArgumentAttributorBase<Overload,Self>::doc(std::string cons
 }
 
 template <class Overload, class Self>
-prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self>::
+prefix_ Self senf::console::ParsedArgumentAttributorBase<Overload,Self,void>::
 overloadDoc(std::string const & doc)
     const
 {
@@ -139,7 +154,7 @@ overloadDoc(std::string const & doc)
 
 template <class Overload, class Self>
 prefix_
-senf::console::ParsedArgumentAttributorBase<Overload,Self>::
+senf::console::ParsedArgumentAttributorBase<Overload,Self,void>::
 ParsedArgumentAttributorBase(Overload & overload, unsigned index)
     : ParsedCommandAttributor<Overload> (overload, index)
 {}
@@ -162,12 +177,15 @@ senf::console::ParsedArgumentAttributor<Overload,index,flag>::
 argInfo(ArgumentPack const & args)
     const
 {
-#   define HaveArg(tag) boost::is_same< \
-        typename boost::parameter::binding<ArgumentPack, tag>::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 +195,7 @@ argInfo(ArgumentPack const & args)
 template <class Overload, unsigned index, bool flag>
 template <class Kw, class ArgumentPack>
 prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
-argInfo(Kw const &, ArgumentPack const &, boost::mpl::true_)
+argInfo(Kw const &, ArgumentPack const &, boost::mpl::false_)
     const
 {}
 
@@ -185,7 +203,7 @@ template <class Overload, unsigned index, bool flag>
 template <class ArgumentPack>
 prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
 argInfo(boost::parameter::keyword<kw::type::name> const &, ArgumentPack const & args,
-        boost::mpl::false_)
+        boost::mpl::true_)
     const
 {
     this->argName(args[kw::name]);
@@ -195,7 +213,7 @@ template <class Overload, unsigned index, bool flag>
 template <class ArgumentPack>
 prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
 argInfo(boost::parameter::keyword<kw::type::description> const &, ArgumentPack const & args,
-        boost::mpl::false_)
+        boost::mpl::true_)
     const
 {
     this->argDoc(args[kw::description]);
@@ -205,13 +223,44 @@ template <class Overload, unsigned index, bool flag>
 template <class ArgumentPack>
 prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
 argInfo(boost::parameter::keyword<kw::type::default_value> const &, ArgumentPack const & args,
-        boost::mpl::false_)
+        boost::mpl::true_)
     const
 {
     this->defaultValue(args[kw::default_value]);
 }
 
 template <class Overload, unsigned index, bool flag>
+template <class ArgumentPack>
+prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
+argInfo(boost::parameter::keyword<kw::type::type_name> const &, ArgumentPack const & args,
+        boost::mpl::true_)
+    const
+{
+    this->typeName(args[kw::type_name]);
+}
+
+template <class Overload, unsigned index, bool flag>
+template <class ArgumentPack>
+prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
+argInfo(boost::parameter::keyword<kw::type::default_doc> const &, ArgumentPack const & args,
+        boost::mpl::true_)
+    const
+{
+    BOOST_STATIC_ASSERT(( senf::has_parameter<ArgumentPack, kw::type::default_value>::value ));
+    this->defaultDoc(args[kw::default_doc]);
+}
+
+template <class Overload, unsigned index, bool flag>
+template <class ArgumentPack>
+prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
+argInfo(boost::parameter::keyword<kw::type::parser> const &, ArgumentPack const & args,
+        boost::mpl::true_)
+    const
+{
+    this->parser(args[kw::parser]);
+}
+
+template <class Overload, unsigned index, bool flag>
 prefix_
 senf::console::ParsedArgumentAttributor<Overload,index,flag>::
 ParsedArgumentAttributor(Overload & overload)
@@ -231,7 +280,16 @@ prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::
 defaultValue(value_type const & value)
     const
 {
-    ParsedCommandAttributorBase::defaultValue<arg_type>(value);
+    this->overload().arg<index>().defaultValue = value;
+    this->overload().arg(index).hasDefault = true;
+}
+
+template <class Overload, unsigned index, bool flag>
+template <class Fn>
+prefix_ void senf::console::ParsedArgumentAttributor<Overload,index,flag>::parser(Fn fn)
+    const
+{
+    this->overload().arg<index>().parser = fn;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -241,14 +299,25 @@ template <class Overload, unsigned index>
 prefix_
 senf::console::ParsedArgumentAttributor<Overload, index, false>::
 ParsedArgumentAttributor(Overload & overload)
-    : ParsedArgumentAttributorBase< Overload, 
-                                     ParsedArgumentAttributor<Overload, index, false> > (overload, index)
+    : ParsedArgumentAttributorBase< 
+          Overload, ParsedArgumentAttributor<Overload, index, false> > (overload, index)
 {}
 
 ///////////////////////////////////////////////////////////////////////////
 // namespace members
 
-namespace {
+namespace senf {
+namespace console {
+namespace detail {
+
+#ifndef DOXYGEN
+
+    struct ParsedCommandAddNodeAccess
+    {
+        template <class Attributor, class Node>
+        static Attributor attributor(Node & node)
+            { return Attributor(node); }
+    };
 
     // What is THIS about ??
 
@@ -264,14 +333,16 @@ namespace {
     // 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 <class Traits, bool ignoreOneArg, unsigned arity=Traits::arity>
+    template <class Traits, 
+              bool ignoreOneArg=! Traits::has_ostream_arg, 
+              unsigned arity=Traits::traits::arity>
     struct CreateParsedCommandOverload
     {};
 
     template <class Traits, unsigned arity>
     struct CreateParsedCommandOverload<Traits, false, arity>
     {
-        typedef Traits traits;
+        typedef typename Traits::traits traits;
         
         template <class Function>
         static typename senf::console::ParsedCommandOverload<traits>::ptr create(Function fn) 
@@ -283,69 +354,56 @@ namespace {
                                             4))
 #   include BOOST_PP_ITERATE()
 
-}
+    template <class Signature, class Fn>
+    typename senf::console::detail::ParsedCommandTraits<Signature>::Attributor
+    addOverloadedCommandNode(senf::console::DirectoryNode & node,  std::string const & name, Fn fn)
+    {
+        senf::console::OverloadedCommandNode & cmdNode (
+            node.hasChild(name) 
+            ? dynamic_cast<senf::console::OverloadedCommandNode &>(node(name))
+            : node.add(name, senf::console::OverloadedCommandNode::create()) );
+
+        typedef senf::console::detail::ParsedCommandTraits<Signature> CmdTraits;
+        typedef senf::console::ParsedCommandOverload<typename CmdTraits::traits> Overload;
+        typedef senf::console::ParsedArgumentAttributor<Overload> Attributor;
+
+        return senf::console::detail::ParsedCommandAddNodeAccess::attributor<Attributor>(
+            cmdNode.add( CreateParsedCommandOverload<CmdTraits>::create(fn) ) );
+    }
+
+#endif
+
+}}}
+
+#ifndef DOXYGEN
 
 template <class Function>
-prefix_ senf::console::ParsedArgumentAttributor<
-    senf::console::ParsedCommandOverload<
-        typename senf::console::detail::ParsedCommandTraits<Function>::traits> >
+typename senf::console::detail::ParsedCommandTraits<Function>::Attributor
 senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
                                      Function fn, int)
 {
-    OverloadedCommandNode & cmdNode (
-        node.hasChild(name) 
-        ? dynamic_cast<OverloadedCommandNode &>(node(name))
-        : node.add(name, OverloadedCommandNode::create()) );
-
-    typedef detail::ParsedCommandTraits<Function> CmdTraits;
-    typedef ParsedCommandOverload<typename CmdTraits::traits> Overload;
-    typedef ParsedArgumentAttributor<Overload> Attributor;
-
-    return Attributor(
-        cmdNode.add( CreateParsedCommandOverload<
-                         typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(fn) ) );
+    return senf::console::detail::addOverloadedCommandNode<Function>(node, name, fn);
 }
 
-template <class Owner, class Function>
-prefix_ senf::console::ParsedArgumentAttributor<
-    senf::console::ParsedCommandOverload<
-        typename senf::console::detail::ParsedCommandTraits<Function>::traits> >
-senf::console::
-senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
-                      Function fn, int,
-                      typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_member>::type *)
+template <class Signature>
+typename senf::console::detail::ParsedCommandTraits<Signature>::Attributor
+senf::console::senf_console_add_node(DirectoryNode & node, std::string const & name,
+                                     boost::function<Signature> fn, int)
 {
-    OverloadedCommandNode & cmdNode (
-        node.hasChild(name) 
-        ? dynamic_cast<OverloadedCommandNode &>(node(name))
-        : node.add(name, OverloadedCommandNode::create()) );
-
-    typedef detail::ParsedCommandTraits<Function> CmdTraits;
-    typedef ParsedCommandOverload<typename CmdTraits::traits> Overload;
-    typedef ParsedArgumentAttributor<Overload> Attributor;
-
-    return Attributor(
-        cmdNode.add( CreateParsedCommandOverload<
-                         typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(
-                             senf::membind(fn,&owner)) ) );
+    return senf::console::detail::addOverloadedCommandNode<Signature>(node, name, fn);
 }
 
-///////////////////////////////////////////////////////////////////////////
-// senf::console::detail::CheckVoidReturn<Type>
-
-template <class Type>
-template <class Fn>
-prefix_ void senf::console::detail::CheckVoidReturn<Type>::call(Fn fn, std::ostream & os)
+template <class Owner, class Function>
+typename senf::console::detail::ParsedCommandTraits<Function>::Attributor
+senf::console::senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
+                                     Function fn, int,
+                                     typename boost::enable_if_c<detail::ParsedCommandTraits<Function>::is_member>::type *)
 {
-    ReturnValueTraits<Type>::format(fn(),os);
-    os << "\n";
+    return senf::console::detail::addOverloadedCommandNode<Function>(
+        node, name, senf::membind(fn,&owner));
 }
 
-template <class Fn>
-prefix_ void senf::console::detail::CheckVoidReturn<void>::call(Fn fn, std::ostream & os)
-{
-    fn();
-}
+#endif
 
 ///////////////////////////////cti.e///////////////////////////////////////
 #undef prefix_