X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FConsole%2FTraits.hh;h=a5b0ccd77db6c96e75acc12f876c3215d3688160;hb=c5d0e492a701a054b1f3d56e128b2c4675b0d50b;hp=d479f45b71926758b57010db32282e37a89e4033;hpb=958bdb52c39fa39f4ef91cafd9628bcb4f85a03c;p=senf.git diff --git a/Utils/Console/Traits.hh b/Utils/Console/Traits.hh index d479f45..a5b0ccd 100644 --- a/Utils/Console/Traits.hh +++ b/Utils/Console/Traits.hh @@ -29,6 +29,7 @@ // Custom includes #include #include +#include #include "../../Utils/intrusive_refcount.hh" #include "Parse.hh" #include "Node.hh" @@ -94,6 +95,12 @@ namespace console { { typedef Type type; + static bool const singleToken = + boost::is_same< typeof(senf_console_parse_argument( + *static_cast(0), + *static_cast(0))), + bool >::value; + static void parse(ParseCommandInfo::TokensRange const & tokens, Type & out); ///< Parse token range into value /**< This function needs to parse \a tokens and write the @@ -121,7 +128,7 @@ namespace console { \related ArgumentTraits */ template - void senf_console_parse_argument(ParseCommandInfo::TokensRange const & tokens, Type & out); + bool senf_console_parse_argument(ParseCommandInfo::TokensRange const & tokens, Type & out); /** \brief Parse token range @@ -133,6 +140,9 @@ namespace console { template void parse(ParseCommandInfo::TokensRange const & tokens, Type & out); + template + void format(Type const & value, std::ostream & os); + #ifndef DOXYGEN // Parse bool: true/false, yes/no, enabled/disabled, 0/1 @@ -140,6 +150,7 @@ namespace console { struct ArgumentTraits { typedef bool type; + static bool const singleToken = true; static void parse(ParseCommandInfo::TokensRange const & tokens, bool & out); static std::string description(); @@ -181,6 +192,10 @@ namespace console { This macro will register an enum type and it's enumerators defined at namespace scope. See \ref SENF_CONSOLE_REGISTER_ENUM_MEMBER to register a member enum type. + \note All enumerator values must be unique ignoring case. + + The enum parser will accept any unique initial substring ignoring case as valid enum value. + \ingroup console_commands */ # define SENF_CONSOLE_REGISTER_ENUM(Type, Values) \ @@ -204,6 +219,33 @@ namespace console { # define SENF_CONSOLE_REGISTER_ENUM_MEMBER(Class, Type, Values) \ SENF_CONSOLE_REGISTER_ENUM_(Class::, Type, Values) + template + struct FlagCollection + { + operator unsigned long() const { return value; } + FlagCollection() : value (0) {} + FlagCollection(unsigned long value_) : value (value_) {} + FlagCollection(Enum value_) : value (value_) {} + unsigned long value; + }; + + template + struct ArgumentTraits< FlagCollection > + { + typedef FlagCollection type; + static bool const singleToken = false; + static void parse(ParseCommandInfo::TokensRange const & tokens, type & out); + static std::string description(); + static std::string str(type const & value); + }; + + template + struct ReturnValueTraits< FlagCollection > + { + typedef FlagCollection type; + static void format(type const & value, std::ostream & os); + }; + }} ///////////////////////////////hh.e////////////////////////////////////////