parse/enum: add support fro enum classes
This commit is contained in:
parent
6367596537
commit
ad92254554
@ -53,7 +53,9 @@ namespace cruft::parse::enumeration {
|
||||
for (auto const [key,val]: m_cache) {
|
||||
if (equal (key, str)) {
|
||||
str = str.consume (key.size ());
|
||||
return val;
|
||||
// We must cast the value here so that enum
|
||||
// classes are supported.
|
||||
return static_cast<ValueT> (val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,12 @@
|
||||
|
||||
enum enumeration_t : u16 { FOO, BAR = 2, QUX = 257 };
|
||||
|
||||
enum class enum_class { VALUE };
|
||||
|
||||
int main ()
|
||||
{
|
||||
cruft::TAP::logger tap;
|
||||
|
||||
{
|
||||
auto const cookie = cruft::parse::enumeration::setup<enumeration_t> ({
|
||||
{ "FOO", FOO },
|
||||
@ -14,7 +19,6 @@ int main ()
|
||||
});
|
||||
(void)cookie;
|
||||
|
||||
cruft::TAP::logger tap;
|
||||
tap.expect_eq (FOO, cruft::parse::from_string<enumeration_t> ("FOO"), "enumeration, FOO");
|
||||
tap.expect_eq (BAR, cruft::parse::from_string<enumeration_t> ("BAR"), "enumeration, BAR");
|
||||
tap.expect_eq (QUX, cruft::parse::from_string<enumeration_t> ("QUX"), "enumeration, QUX");
|
||||
@ -27,5 +31,19 @@ int main ()
|
||||
),
|
||||
"u16, QUX"
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
auto const cookie = cruft::parse::enumeration::setup<enum_class> ({
|
||||
{ "VALUE", enum_class::VALUE },
|
||||
});
|
||||
(void)cookie;
|
||||
|
||||
tap.expect_eq (
|
||||
enum_class::VALUE,
|
||||
cruft::parse::from_string<enum_class> ("VALUE"), "enum class, VALUE"
|
||||
);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user