From: tho Date: Tue, 20 Oct 2009 14:27:02 +0000 (+0000) Subject: Packets/GenericTLV: some GenericTLVParserRegistry modifications; not sure if it goes... X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=bea7cfcf3d02688ece159d76890acfe2d0051d71;hp=0061f12af7284b2d2f03de23014ac2faccfd37ed;p=senf.git Packets/GenericTLV: some GenericTLVParserRegistry modifications; not sure if it goes in the right direction.... git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1505 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80221Bundle/TLVParser.test.cc b/senf/Packets/80221Bundle/TLVParser.test.cc index 12d6392..5270580 100644 --- a/senf/Packets/80221Bundle/TLVParser.test.cc +++ b/senf/Packets/80221Bundle/TLVParser.test.cc @@ -207,7 +207,8 @@ BOOST_AUTO_UNIT_TEST(TestMacAddressTLVPacket_create) 0x0c, // length 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67 // value }; - BOOST_CHECK( equal( tlvPacket.data().begin(), tlvPacket.data().end(), data )); + SENF_CHECK_EQUAL_COLLECTIONS( + data, data+sizeof(data), tlvPacket.data().begin(), tlvPacket.data().end() ); } diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.cc b/senf/Packets/DefaultBundle/IPv6Extensions.cc index d579277..6e8d714 100644 --- a/senf/Packets/DefaultBundle/IPv6Extensions.cc +++ b/senf/Packets/DefaultBundle/IPv6Extensions.cc @@ -75,14 +75,8 @@ prefix_ void senf::IPv6HopByHopOptionsPacketType::dump(packet p, std::ostream & os << " OptionTypes:\n"; typedef IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; optContainer_t options (p->options()); - optContainer_t::iterator optIter(options.begin()); - for(; optIter != options.end(); ++optIter) { - os << senf::fieldName(" AltAction") << unsigned(optIter->altAction()) << "\n" - << senf::fieldName(" ChangeFlag") << unsigned(optIter->changeFlag()) << "\n" - << senf::fieldName(" Option Type") << unsigned(optIter->optionType()) << "\n" - << senf::fieldName(" length") << unsigned(optIter->length()) <<"\n"; - senf::hexdump(boost::begin(optIter->value()) , boost::end(optIter->value()), os ); - } + for (optContainer_t::const_iterator i = options.begin(); i != options.end(); ++i) + i->dump( os); } prefix_ void senf::IPv6DestinationOptionsPacketType::dump(packet p, std::ostream & os) diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc index d92a354..b0ef3cf 100644 --- a/senf/Packets/DefaultBundle/IPv6Extensions.test.cc +++ b/senf/Packets/DefaultBundle/IPv6Extensions.test.cc @@ -369,15 +369,20 @@ BOOST_AUTO_UNIT_TEST(ipv6Extensions_hopByHop_parse_SN) senf::IPv6HopByHopOptionsPacket p ( senf::IPv6HopByHopOptionsPacket::create(data) ); BOOST_CHECK_EQUAL( p->nextHeader(), 0x3a); - typedef senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; - optContainer_t optC (p->options() ); - optContainer_t::iterator listIter (optC.begin()); + { + typedef senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; + optContainer_t optC (p->options() ); + optContainer_t::iterator listIter (optC.begin()); - BOOST_CHECK_EQUAL( listIter->optionType(), 0x0d); - BOOST_CHECK( listIter->is()); - IPv6ChecksumOptionParser opt ( listIter->as()); - BOOST_CHECK_EQUAL( opt.extendedType(), 0x4d); - BOOST_CHECK_EQUAL( opt.checksum(), 0x01234567); + BOOST_CHECK_EQUAL( listIter->optionType(), 0x0d); + BOOST_CHECK( listIter->is()); + IPv6ChecksumOptionParser opt ( listIter->as()); + BOOST_CHECK_EQUAL( opt.extendedType(), 0x4d); + BOOST_CHECK_EQUAL( opt.checksum(), 0x01234567); + } + + std::ostringstream oss (std::ostringstream::out); + SENF_CHECK_NO_THROW( p.dump( oss)); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/senf/Packets/GenericTLV.ct b/senf/Packets/GenericTLV.ct index f2aef9b..fb59a10 100644 --- a/senf/Packets/GenericTLV.ct +++ b/senf/Packets/GenericTLV.ct @@ -52,6 +52,22 @@ prefix_ Parser senf::GenericTLVParserBase::init() } template +prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) + const +{ + if (Base::Registry::instance().isRegistered( *this)) { + Base::Registry::instance().dump( *this, os); + } else { + boost::io::ios_all_saver ias(os); + os << " GenericTLVParser<" << prettyName(typeid(Base)) << ">\n" + << " type: " << senf::format::dumpint(this->type()) << "\n" + << " length: " << senf::format::dumpint(this->length()) << "\n" + << " value:\n"; + hexdump(value().begin(), value().end(), os); + } +} + +template prefix_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase::value() const { @@ -74,33 +90,35 @@ prefix_ void senf::GenericTLVParserBase::value_(ForwardReadableRange const /////////////////////////////////////////////////////////////////////////// -// senf::GenericTLVParserRegistry +// senf::GenericTLVParserRegistry -template +template template -prefix_ void senf::GenericTLVParserRegistry::registerParser() +prefix_ void senf::GenericTLVParserRegistry::registerParser() { - typename BaseParser::type_t::value_type key (Parser::typeId+0); + Keytype key (Parser::typeId+0); typename Map::iterator i (map_.find( key )); if (i == map_.end() ) map_.insert(key, new detail::GenericTLVParserRegistry_Entry() ); } -template -prefix_ void senf::GenericTLVParserRegistry::dump( +template +prefix_ void senf::GenericTLVParserRegistry::dump( GenericTLVParserBase const & parser, std::ostream & os) const { typename Map::const_iterator i (map_.find( parser.type())); - if (i == map_.end()) { - boost::io::ios_all_saver ias(os); - os << " GenericTLVParser<" << prettyName(typeid(BaseParser)) << ">\n" - << " type: " << senf::format::dumpint(parser.type()) << "\n" - << " length: " << senf::format::dumpint(parser.length()) << "\n" - << " value:\n"; - hexdump(parser.value().begin(), parser.value().end(), os); - } - else + if (i != map_.end()) + (i->second)->dump(parser, os); +} + +template +prefix_ void senf::GenericTLVParserRegistry::dump( + GenericTLVParserBase const & parser, Keytype const & key, std::ostream & os) + const +{ + typename Map::const_iterator i (map_.find( key)); + if (i != map_.end()) (i->second)->dump(parser, os); } diff --git a/senf/Packets/GenericTLV.cti b/senf/Packets/GenericTLV.cti index 5c75565..55a4573 100644 --- a/senf/Packets/GenericTLV.cti +++ b/senf/Packets/GenericTLV.cti @@ -75,13 +75,6 @@ prefix_ Base const & senf::GenericTLVParserBase::self() return *static_cast(this); } -template -prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) - const -{ - GenericTLVParserRegistry::instance().dump(*this, os); -} - #ifndef DOXYGEN template @@ -126,15 +119,34 @@ prefix_ void senf::detail::GenericTLVParserRegistry_Entry::d (parser.template as()).dump(os); } +/////////////////////////////////////////////////////////////////////////// +// senf::GenericTLVParserRegistry + +template +prefix_ bool senf::GenericTLVParserRegistry::isRegistered( + GenericTLVParserBase const & parser) + const +{ + typename Map::const_iterator i (map_.find( parser.type())); + return i != map_.end(); +} + +template +prefix_ bool senf::GenericTLVParserRegistry::isRegistered(Keytype const & key) + const +{ + typename Map::const_iterator i (map_.find( key)); + return i != map_.end(); +} /////////////////////////////////////////////////////////////////////////// -// senf::GenericTLVParserRegistry::RegistrationProxy +// senf::GenericTLVParserRegistry::RegistrationProxy -template +template template -prefix_ senf::GenericTLVParserRegistry::RegistrationProxy::RegistrationProxy() +prefix_ senf::GenericTLVParserRegistry::RegistrationProxy::RegistrationProxy() { - GenericTLVParserRegistry::instance().registerParser(); + GenericTLVParserRegistry::instance().registerParser(); }; ///////////////////////////////cti.e/////////////////////////////////////// diff --git a/senf/Packets/GenericTLV.hh b/senf/Packets/GenericTLV.hh index e6f798a..7cb5da7 100644 --- a/senf/Packets/GenericTLV.hh +++ b/senf/Packets/GenericTLV.hh @@ -243,19 +243,18 @@ namespace senf { IPv6OptionParser::Registry, WLANInfoElementParser::Registry, MIHBaseTLVParser::Registry */ - template + template class GenericTLVParserRegistry - : public senf::singleton > + : public senf::singleton > { - typedef boost::ptr_map< - typename BaseParser::type_t::value_type, + typedef boost::ptr_map > Map; Map map_; GenericTLVParserRegistry() {}; public: - using senf::singleton >::instance; - friend class senf::singleton >; + using senf::singleton >::instance; + friend class senf::singleton >; template struct RegistrationProxy { @@ -265,7 +264,11 @@ namespace senf { template void registerParser(); + bool isRegistered(GenericTLVParserBase const & parser) const; + bool isRegistered(Keytype const & key) const; + void dump(GenericTLVParserBase const & parser, std::ostream & os) const; + void dump(GenericTLVParserBase const & parser, Keytype const & key, std::ostream & os) const; }; /** \brief Statically add an entry to a TLV parser registry diff --git a/senf/Packets/GenericTLV.test.cc b/senf/Packets/GenericTLV.test.cc index 5a1d3d6..6b93252 100644 --- a/senf/Packets/GenericTLV.test.cc +++ b/senf/Packets/GenericTLV.test.cc @@ -40,6 +40,8 @@ namespace { SENF_PARSER_FIELD ( type, senf::UInt8Parser ); SENF_PARSER_FIELD_RO ( length, senf::UInt8Parser ); SENF_PARSER_FINALIZE ( MyTLVParserBase ); + + typedef senf::GenericTLVParserRegistry Registry; }; struct MyGenericTLVParser diff --git a/senf/Packets/MPEGDVBBundle/MPESection.test.cc b/senf/Packets/MPEGDVBBundle/MPESection.test.cc index 7f5955c..bff8970 100644 --- a/senf/Packets/MPEGDVBBundle/MPESection.test.cc +++ b/senf/Packets/MPEGDVBBundle/MPESection.test.cc @@ -187,7 +187,8 @@ BOOST_AUTO_UNIT_TEST(MPESection_create) 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x52, 0xdf, 0x6a, 0x1d }; - BOOST_CHECK( equal( sec.data().begin(), sec.data().end(), sec_data )); + SENF_CHECK_EQUAL_COLLECTIONS( + sec_data, sec_data+sizeof(sec_data), sec.data().begin(), sec.data().end() ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/senf/Packets/VectorParser.test.cc b/senf/Packets/VectorParser.test.cc index b0d368c..edb9578 100644 --- a/senf/Packets/VectorParser.test.cc +++ b/senf/Packets/VectorParser.test.cc @@ -280,9 +280,10 @@ BOOST_AUTO_UNIT_TEST(vectorMacro_create) 0x07, 0x08, // vec1[1] 0x09, 0x0A, // vec1[2] 0x0B, 0x0C, // vec2[0] - 0x0D, 0x0E }; // vec2[1] - - BOOST_CHECK( equal( p.data().begin(), p.data().end(), data )); + 0x0D, 0x0E // vec2[1] + }; + SENF_CHECK_EQUAL_COLLECTIONS( + data, data+sizeof(data), p.data().begin(), p.data().end() ); } namespace {