};
}
-namespace {
+// We can't use the unnamed namespace here since there's a bug in gcc-4.2.3 which is
+// the default version of gcc on ubuntu hardy :-(
+// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34213
+namespace VariantParser_test_cc_anon_namespace {
struct SubParser : public senf::PacketParserBase
{
{
# include SENF_PARSER()
- struct TestTransform {
- typedef unsigned value_type;
- static unsigned get(unsigned v) { return v/2; }
- static unsigned set(unsigned v) { return 2*v; }
- };
-
- SENF_PARSER_SKIP_BITS( 4 );
+ SENF_PARSER_BITFIELD_RO( len, 4, unsigned );
SENF_PARSER_BITFIELD_RO( type, 4, unsigned );
- SENF_PARSER_PRIVATE_VARIANT( content_, transform(TestTransform, type),
- (senf::VoidPacketParser)(SubParser) );
-
- bool hasContent() const { return content_().variant() == 1; }
- void hasContent(bool v) const { if (v) content_().init<1>(); else content_().init<0>(); }
- SubParser content() const { return content_().get<1>(); }
+ // just here so the second variant is 'var'
+ SENF_PARSER_VARIANT( value, len,
+ (senf::VoidPacketParser)
+ (senf::UInt8Parser)
+ (senf::UInt16Parser)
+ (senf::UInt32Parser)
+ );
+ SENF_PARSER_VARIANT( content_, type,
+ ( novalue( nocontent, key(10, senf::VoidPacketParser) ) )
+ ( id( content, SubParser ) )
+ );
SENF_PARSER_FINALIZE(TestParser);
};
}
+using namespace VariantParser_test_cc_anon_namespace;
BOOST_AUTO_UNIT_TEST(VariantParserMacro)
{
{
TestParser v (p.data().begin(), & p.data());
- BOOST_CHECK( ! v.hasContent() );
+ v.init();
+ BOOST_CHECK( ! v.has_content() );
BOOST_CHECK_EQUAL( senf::bytes(v), 1u );
- BOOST_CHECK_EQUAL( v.type(), 0u );
- v.hasContent(true);
+ BOOST_CHECK_EQUAL( v.type(), 10u );
+ v.init_content();
// Parser invalidated
}
{
TestParser v (p.data().begin(), & p.data());
- BOOST_CHECK( v.hasContent() );
+ BOOST_CHECK( v.has_content() );
BOOST_CHECK_EQUAL( senf::bytes(v), 7u );
BOOST_CHECK_EQUAL( v.content().foo(), 0u );
- BOOST_CHECK_EQUAL( v.type(), 2u );
+ BOOST_CHECK_EQUAL( v.type(), 1u );
+ v.nocontent();
+ // Parser invalidated
}
}