X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.hh;h=8d1357fda5d5c3e2c75eb1d98cdf7dbb135c7477;hb=0f235de98cae838afb42244ebd307ce8cd1db409;hp=e6f798a3b84bd811cb89a02f2174a2daff5aab55;hpb=52ceda9d4019d45ef0d1a941d517b4ffeafe547b;p=senf.git diff --git a/senf/Packets/GenericTLV.hh b/senf/Packets/GenericTLV.hh index e6f798a..8d1357f 100644 --- a/senf/Packets/GenericTLV.hh +++ b/senf/Packets/GenericTLV.hh @@ -149,7 +149,7 @@ namespace senf { bool is() const; senf::PacketInterpreterBase::range value() const; - + void dump(std::ostream & os) const; #ifndef DOXYGEN @@ -185,6 +185,7 @@ namespace senf { template struct GenericTLVParserRegistry_EntryBase { virtual void dump(GenericTLVParserBase const & parser, std::ostream & os) const = 0; + virtual PacketParserBase::size_type bytes(GenericTLVParserBase const & parser) const = 0; }; template @@ -192,6 +193,17 @@ namespace senf { : GenericTLVParserRegistry_EntryBase { virtual void dump(GenericTLVParserBase const & parser, std::ostream & os) const; + virtual PacketParserBase::size_type bytes(GenericTLVParserBase const & parser) const; + }; + + //Helper Functor for STL-compatible predicate (E.g. find_if, for_each ...) + template + class Predicate + { + public: + const bool operator() (BaseParser const &p) const{ + return p.template is(); + } }; } @@ -235,27 +247,25 @@ namespace senf { The registry provides a dump() member to dump an instance of a generic TLV parser. If the type value of the given TLV parser is registered the generic tlv will be casted to the registered concrete TLV parser and the dump member from this parser - will be called. Otherwise the generic TLV parser will be dumped in a generic way - (hexdump of the value). + will be called. \see GenericTLVParserBase for the general TLV class structure \n 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,9 +275,23 @@ namespace senf { template void registerParser(); - void dump(GenericTLVParserBase const & parser, std::ostream & os) const; + typedef GenericTLVParserBase GenericTLVParser; + + bool isRegistered(GenericTLVParserBase const & parser) const; + bool isRegistered(Keytype const & key) const; + + void dump(GenericTLVParser const & parser, std::ostream & os) const; + void dump(GenericTLVParser const & parser, Keytype const & key, std::ostream & os) const; + + PacketParserBase::size_type bytes(GenericTLVParser const & parser) const; }; + struct TLVParserNotRegisteredException : public senf::Exception + { + TLVParserNotRegisteredException() : senf::Exception("tlv parser not registered") {} + }; + + /** \brief Statically add an entry to a TLV parser registry This macro will declare an anonymous global variable in such a way, that constructing