Packets/GenericTLV: some GenericTLVParserRegistry modifications; not sure if it goes...
tho [Tue, 20 Oct 2009 14:27:02 +0000 (14:27 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1505 270642c3-0616-0410-b53a-bc976706d245

senf/Packets/80221Bundle/TLVParser.test.cc
senf/Packets/DefaultBundle/IPv6Extensions.cc
senf/Packets/DefaultBundle/IPv6Extensions.test.cc
senf/Packets/GenericTLV.ct
senf/Packets/GenericTLV.cti
senf/Packets/GenericTLV.hh
senf/Packets/GenericTLV.test.cc
senf/Packets/MPEGDVBBundle/MPESection.test.cc
senf/Packets/VectorParser.test.cc

index 12d6392..5270580 100644 (file)
@@ -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() );
 }
 
 
index d579277..6e8d714 100644 (file)
@@ -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)
index d92a354..b0ef3cf 100644 (file)
@@ -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>());
-    IPv6ChecksumOptionParser opt ( listIter->as<IPv6ChecksumOptionParser>());
-    BOOST_CHECK_EQUAL( opt.extendedType(), 0x4d);
-    BOOST_CHECK_EQUAL( opt.checksum(), 0x01234567);
+        BOOST_CHECK_EQUAL( listIter->optionType(), 0x0d);
+        BOOST_CHECK( listIter->is<IPv6ChecksumOptionParser>());
+        IPv6ChecksumOptionParser opt ( listIter->as<IPv6ChecksumOptionParser>());
+        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////////////////////////////////////////
index f2aef9b..fb59a10 100644 (file)
@@ -52,6 +52,22 @@ prefix_ Parser senf::GenericTLVParserBase<Base>::init()
 }
 
 template <class Base>
+prefix_  void senf::GenericTLVParserBase<Base>::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 <class Base>
 prefix_  senf::PacketInterpreterBase::range senf::GenericTLVParserBase<Base>::value() 
     const 
 {
@@ -74,33 +90,35 @@ prefix_ void senf::GenericTLVParserBase<Base>::value_(ForwardReadableRange const
 
 
 ///////////////////////////////////////////////////////////////////////////
-// senf::GenericTLVParserRegistry<BaseParser>
+// senf::GenericTLVParserRegistry<BaseParser,Keytype>
 
-template <class BaseParser>
+template <class BaseParser, class Keytype>
 template <typename Parser>
-prefix_ void senf::GenericTLVParserRegistry<BaseParser>::registerParser()
+prefix_ void senf::GenericTLVParserRegistry<BaseParser,Keytype>::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<BaseParser, Parser>() );
 }
 
-template <class BaseParser>
-prefix_ void senf::GenericTLVParserRegistry<BaseParser>::dump(
+template <class BaseParser, class Keytype>
+prefix_ void senf::GenericTLVParserRegistry<BaseParser,Keytype>::dump(
         GenericTLVParserBase<BaseParser> 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 <class BaseParser, class Keytype>
+prefix_ void senf::GenericTLVParserRegistry<BaseParser,Keytype>::dump(
+        GenericTLVParserBase<BaseParser> 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);
 }
 
index 5c75565..55a4573 100644 (file)
@@ -75,13 +75,6 @@ prefix_ Base const & senf::GenericTLVParserBase<Base>::self()
     return *static_cast<Base const *>(this);
 }
 
-template <class Base>
-prefix_  void senf::GenericTLVParserBase<Base>::dump(std::ostream & os)
-    const 
-{
-    GenericTLVParserRegistry<Base>::instance().dump(*this, os);
-}
-
 #ifndef DOXYGEN
 
 template <class Base>
@@ -126,15 +119,34 @@ prefix_ void senf::detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>::d
     (parser.template as<Parser>()).dump(os);
 }
 
+///////////////////////////////////////////////////////////////////////////
+// senf::GenericTLVParserRegistry<BaseParser,Keytype>
+
+template <class BaseParser, class Keytype>
+prefix_ bool senf::GenericTLVParserRegistry<BaseParser,Keytype>::isRegistered(
+        GenericTLVParserBase<BaseParser> const & parser)
+    const
+{
+    typename Map::const_iterator i (map_.find( parser.type()));
+    return i != map_.end();
+}
+
+template <class BaseParser, class Keytype>
+prefix_ bool senf::GenericTLVParserRegistry<BaseParser,Keytype>::isRegistered(Keytype const & key)
+    const
+{
+    typename Map::const_iterator i (map_.find( key));
+    return i != map_.end();
+}
 
 ///////////////////////////////////////////////////////////////////////////
-// senf::GenericTLVParserRegistry<BaseParser>::RegistrationProxy<PacketParser>
+// senf::GenericTLVParserRegistry<BaseParser,Keytype>::RegistrationProxy<PacketParser>
 
-template <class BaseParser>
+template <class BaseParser, class Keytype>
 template <class PacketParser>
-prefix_ senf::GenericTLVParserRegistry<BaseParser>::RegistrationProxy<PacketParser>::RegistrationProxy()
+prefix_ senf::GenericTLVParserRegistry<BaseParser,Keytype>::RegistrationProxy<PacketParser>::RegistrationProxy()
 {
-    GenericTLVParserRegistry<BaseParser>::instance().registerParser<PacketParser>();
+    GenericTLVParserRegistry<BaseParser,Keytype>::instance().registerParser<PacketParser>();
 };
 
 ///////////////////////////////cti.e///////////////////////////////////////
index e6f798a..7cb5da7 100644 (file)
@@ -243,19 +243,18 @@ namespace senf {
             IPv6OptionParser::Registry, WLANInfoElementParser::Registry,
             MIHBaseTLVParser::Registry 
      */
-    template <class BaseParser>
+    template <class BaseParser, class Keytype = typename BaseParser::type_t::value_type>
     class GenericTLVParserRegistry
-        : public senf::singleton<GenericTLVParserRegistry<BaseParser> >
+        : public senf::singleton<GenericTLVParserRegistry<BaseParser,Keytype> >
     {
-        typedef boost::ptr_map<
-            typename BaseParser::type_t::value_type, 
+        typedef boost::ptr_map<Keytype, 
             detail::GenericTLVParserRegistry_EntryBase<BaseParser> > Map;
         Map map_;
         
         GenericTLVParserRegistry() {};
     public:
-        using senf::singleton<GenericTLVParserRegistry<BaseParser> >::instance;
-        friend class senf::singleton<GenericTLVParserRegistry<BaseParser> >;
+        using senf::singleton<GenericTLVParserRegistry<BaseParser,Keytype> >::instance;
+        friend class senf::singleton<GenericTLVParserRegistry<BaseParser,Keytype> >;
         
         template <class PacketParser>
         struct RegistrationProxy {
@@ -265,7 +264,11 @@ namespace senf {
         template <typename Parser>
         void registerParser();
         
+        bool isRegistered(GenericTLVParserBase<BaseParser> const & parser) const;
+        bool isRegistered(Keytype const & key) const;
+        
         void dump(GenericTLVParserBase<BaseParser> const & parser, std::ostream & os) const;
+        void dump(GenericTLVParserBase<BaseParser> const & parser, Keytype const & key, std::ostream & os) const;
     };
         
     /** \brief Statically add an entry to a TLV parser registry
index 5a1d3d6..6b93252 100644 (file)
@@ -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<MyTLVParserBase> Registry;
     };
     
     struct MyGenericTLVParser
index 7f5955c..bff8970 100644 (file)
@@ -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////////////////////////////////////////
index b0d368c..edb9578 100644 (file)
@@ -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 {