# include <boost/preprocessor/expand.hpp>
# include <boost/preprocessor/facilities/is_empty.hpp>
# include <boost/preprocessor/punctuation/comma.hpp>
+# include "../Utils/preprocessor.hh"
# include "../Utils/mpl.hh"
#
# ////////////////////////////////ih.p///////////////////////////////////////
# define SENF_PARSER_COLLECTION_TAG_GETAUX__packetSize() _
# define SENF_PARSER_COLLECTION_TAG_AUXTYPE__packetSize() packetSize
#
-# // No recursive call so we need some more of theese ... ARGH !!!
-# define SENF_CAT_RECURS1(a, b) SENF_CAT_RECURS1_I(a,b)
-# define SENF_CAT_RECURS1_I(a, b) a ## b
-# define SENF_CAT_RECURS2(a, b) SENF_CAT_RECURS2_I(a,b)
-# define SENF_CAT_RECURS2_I(a, b) a ## b
-# define SENF_CAT_RECURS3(a, b) SENF_CAT_RECURS3_I(a,b)
-# define SENF_CAT_RECURS3_I(a, b) a ## b
-#
# define SENF_PARSER_COLLECTION_TAG_EXPAND__none() senf::detail::auxtag::none
#
# define SENF_PARSER_COLLECTION_TAG_RECURS1(aux) \
long parseEnum(EnumTable const & table, ParseCommandInfo::TokensRange const & tokens);
std::string formatEnum(EnumTable const & table, long value);
-# define SENF_CONSOLE_REGISTER_ENUM_ELT(r,d,e) \
- ( BOOST_PP_STRINGIZE(e), static_cast<long>(d e) )
+# define SENF_CONSOLE_REGISTER_ENUM_ELT(r,d,e) \
+ BOOST_PP_IF( SENF_CONSOLE_REGISTER_ENUM_HASKEY(e), \
+ SENF_CONSOLE_REGISTER_ENUM_WITHKEY, \
+ SENF_CONSOLE_REGISTER_ENUM_NOKEY )(d, e)
+
+# define SENF_CONSOLE_REGISTER_ENUM_GOBBLE__key(k,e)
+# define SENF_CONSOLE_REGISTER_ENUM_GET_KEY__key(k,e) k
+# define SENF_CONSOLE_REGISTER_ENUM_GET_ENUM__key(k,e) e
+# define SENF_CONSOLE_REGISTER_ENUM_HASKEY(e) \
+ BOOST_PP_IS_EMPTY( SENF_CAT_RECURS1(SENF_CONSOLE_REGISTER_ENUM_GOBBLE__, e) )
+
+# define SENF_CONSOLE_REGISTER_ENUM_KEY_GETENUM(e) \
+ SENF_CAT_RECURS2(SENF_CONSOLE_REGISTER_ENUM_GET_ENUM__, e)
+# define SENF_CONSOLE_REGISTER_ENUM_KEY_GETKEY(e) \
+ SENF_CAT_RECURS3(SENF_CONSOLE_REGISTER_ENUM_GET_KEY__, e)
+
+# define SENF_CONSOLE_REGISTER_ENUM_NOKEY(prefix, e) \
+ ( BOOST_PP_STRINGIZE(e), static_cast<long>(prefix e) )
+
+# define SENF_CONSOLE_REGISTER_ENUM_WITHKEY(prefix, e) \
+ ( SENF_CONSOLE_REGISTER_ENUM_KEY_GETKEY(e), \
+ static_cast<long>(prefix SENF_CONSOLE_REGISTER_ENUM_KEY_GETENUM(e)) )
+
# define SENF_CONSOLE_REGISTER_ENUM_(Prefix, Type, Values) \
inline senf::console::detail::EnumTable & senf_console_enum_table(Prefix Type) \
static MemberEnum test (MemberEnum value) { return value; }
};
SENF_CONSOLE_REGISTER_ENUM_MEMBER( TestClass, MemberEnum, (MemberFoo)(MemberBar) );
+
+ enum TestEnumKey { ONE, TWO, THREE };
+ SENF_CONSOLE_REGISTER_ENUM( TestEnumKey, (key("1s",ONE))(key("2",TWO))(key("three",THREE)) );
+
+ TestEnumKey testKey (TestEnumKey value) { return value; }
}
SENF_AUTO_UNIT_TEST(charTraits)
senf::console::root().add("test", dir);
dir.add("test",fty::Command(&test));
+ dir.add("testKey",fty::Command(&testKey));
std::stringstream ss;
SENF_CHECK_NO_THROW(
parser.parse("test/test foo",
boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
BOOST_CHECK_EQUAL( ss.str(), "Foo\n" );
+
+ ss.str("");
+ SENF_CHECK_NO_THROW(
+ parser.parse("test/testKey 1S",
+ boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
+ BOOST_CHECK_EQUAL( ss.str(), "1s\n" );
+
+ ss.str("");
+ SENF_CHECK_NO_THROW(
+ parser.parse("test/testKey 2",
+ boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
+ BOOST_CHECK_EQUAL( ss.str(), "2\n" );
+
+ ss.str("");
+ SENF_CHECK_NO_THROW(
+ parser.parse("test/testKey ThrEE",
+ boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
+ BOOST_CHECK_EQUAL( ss.str(), "three\n" );
}
SENF_AUTO_UNIT_TEST(singleToken)
*/
#define SENF_PP_SEQ_BACK(seq) BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(seq)),seq)
+# // No recursive call so we need some more of theese ... ARGH !!!
+# define SENF_CAT_RECURS1(a, b) SENF_CAT_RECURS1_I(a,b)
+# define SENF_CAT_RECURS1_I(a, b) a ## b
+# define SENF_CAT_RECURS2(a, b) SENF_CAT_RECURS2_I(a,b)
+# define SENF_CAT_RECURS2_I(a, b) a ## b
+# define SENF_CAT_RECURS3(a, b) SENF_CAT_RECURS3_I(a,b)
+# define SENF_CAT_RECURS3_I(a, b) a ## b
+#
+
///\}
///////////////////////////////hh.e////////////////////////////////////////