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() );
}
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)
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////////////////////////////////////////
}
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
{
///////////////////////////////////////////////////////////////////////////
-// 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);
}
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>
(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///////////////////////////////////////
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 {
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
SENF_PARSER_FIELD ( type, senf::UInt8Parser );
SENF_PARSER_FIELD_RO ( length, senf::UInt8Parser );
SENF_PARSER_FINALIZE ( MyTLVParserBase );
+
+ typedef senf::GenericTLVParserRegistry<MyTLVParserBase> Registry;
};
struct MyGenericTLVParser
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////////////////////////////////////////
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 {