#include "ParsedCommand.ih"
// Custom includes
+#include "../Utils/membind.hh"
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(fn) );
}
+template <class Owner, class Function>
+prefix_ 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 *)
+{
+ OverloadedCommandNode & cmdNode (
+ node.hasChild(name)
+ ? dynamic_cast<OverloadedCommandNode &>(node(name))
+ : node.add(name, OverloadedCommandNode::create()) );
+
+ typedef senf::console::detail::ParsedCommandTraits<Function> CmdTraits;
+
+ return cmdNode.add( CreateParsedCommandOverload<
+ typename CmdTraits::traits, ! CmdTraits::has_ostream_arg>::create(
+ senf::membind(fn,&owner)) );
+}
+
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
#include <boost/type_traits/is_member_pointer.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/if.hpp>
+#include <boost/utility.hpp>
#include "../config.hh"
#include "OverloadedCommand.hh"
#include "ParseParameter.hh"
1))
# include BOOST_PP_ITERATE()
+#ifndef DOXYGEN
+
template <class Function>
ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> &
senf_console_add_node(DirectoryNode & node, std::string const & name, Function fn, int);
+ template <class Owner, class Function>
+ ParsedCommandOverload<typename detail::ParsedCommandTraits<Function>::traits> &
+ 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 * = 0);
+
+#endif
+
}}
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_const.hpp>
#include <boost/bind.hpp>
// ///////////////////////////mpp.p////////////////////////////////////////
typedef boost::function<typename traits::result_type(std::ostream &
mpp_TrailingArgTypes())> Function;
-# define mpp_l(z,n,d) \
- typedef typename boost::remove_reference<typename traits::mpp_ArgTypeN(n)>::type \
- mpp_ArgTypeN(n);
+# define mpp_l(z,n,d) \
+ typedef typename boost::remove_const< \
+ typename boost::remove_reference< typename traits::mpp_ArgTypeN(n) >::type >::type \
+ mpp_ArgTypeN(n);
BOOST_PP_REPEAT( BOOST_PP_ITERATION(), mpp_l, _ )
# undef mpp_l
boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
senf::console::SyntaxErrorException );
}
+
+ {
+ std::stringstream ss;
+
+ dir.add("cb", &cb1);
+ dir.add("cb", &cb5);
+ dir.add("cb", &cb2);
+ parser.parse("test/cb 111 222.4; test/cb 222; test/cb",
+ boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
+ BOOST_CHECK_EQUAL( ss.str(), "333\n" "Value: 222\n" "1.2\n" );
+ }
+}
+
+namespace {
+
+ struct Test
+ {
+ senf::console::ScopedDirectory<Test> dir;
+ std::string name_;
+
+ Test(std::string const & name) : dir(this), name_ (name) {
+ dir.add("name", &Test::name);
+ }
+
+ std::string name(std::string const & suffix) {
+ return name_ + suffix;
+ }
+
+ };
}
+BOOST_AUTO_UNIT_TEST(memberParsedCommand)
+{
+ senf::console::Executor executor;
+ senf::console::CommandParser parser;
+ senf::console::ScopedDirectory<> dir;
+ senf::console::root().add("test", dir);
+
+ {
+ Test obj ("bar");
+ dir.add("obj", obj.dir);
+
+ std::stringstream ss;
+ parser.parse("test/obj/name \": foo\"",
+ boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
+ BOOST_CHECK_EQUAL( ss.str(), "bar: foo\n" );
+ }
+}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
std::string const & name,
Object const & ob)
{
- return senf_console_add_node(node, owner, name, ob);
+ return senf_console_add_node(node, owner, name, ob, 0);
}
///////////////////////////////////////////////////////////////////////////
template <class Owner, class Function>
prefix_ senf::console::SimpleCommandNode & senf::console::
senf_console_add_node(DirectoryNode & node, Owner & , std::string const & name,
- Function const & fn)
+ Function const & fn, ...)
{
return node.add(name,fn);
}
template <class Owner>
prefix_ senf::console::SimpleCommandNode & senf::console::
senf_console_add_node(DirectoryNode & node, Owner & owner, std::string const & name,
- void (Owner::*fn)(std::ostream &, ParseCommandInfo const &))
+ void (Owner::*fn)(std::ostream &, ParseCommandInfo const &), int)
{
return node.add(name, boost::bind(fn,boost::ref(owner),_1,_2));
}
* static_cast<DirectoryNode *>(0),
* static_cast<Owner *>(0),
* static_cast<std::string const *>(0),
- * static_cast<Object const *>(0)) ) result_type;
+ * static_cast<Object const *>(0),
+ * static_cast<int *>(0)) ) result_type;
typedef typename boost::remove_reference<result_type>::type NodeType;
#ifndef DOXYGEN
template <class Owner, class Function>
SimpleCommandNode & senf_console_add_node(
- DirectoryNode & node, Owner & owner, std::string const & name, Function const & fn);
+ DirectoryNode & node, Owner & owner, std::string const & name, Function const & fn, ...);
template <class Owner>
SimpleCommandNode & senf_console_add_node(
DirectoryNode & node, Owner & owner, std::string const & name,
- void (Owner::*fn)(std::ostream &, ParseCommandInfo const &));
+ void (Owner::*fn)(std::ostream &, ParseCommandInfo const &), int);
template <class Node>
DirectoryNode & senf_console_add_node(