X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.hh;h=e8e1bb586ea6659ef5521077c1622708cc4c480f;hb=cf48e83de9d4793ca5bd67d1e5acdb5b20968638;hp=3c4f12dbf339b73666f5fa5d91aa6da8a14b302a;hpb=29a39b247b75454ad25f3f9dc7a524debf8e805c;p=senf.git diff --git a/senf/Packets/GenericTLV.hh b/senf/Packets/GenericTLV.hh index 3c4f12d..e8e1bb5 100644 --- a/senf/Packets/GenericTLV.hh +++ b/senf/Packets/GenericTLV.hh @@ -27,8 +27,10 @@ #define HH_SENF_Packets_GenericTLV_ 1 // Custom includes +#include #include #include +#include //#include "GenericTLV.hh.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -53,7 +55,7 @@ namespace senf { \endcode Your concrete TLV parsers will inherit from this base class and have to define a specific - value field and a \c TYPEID member: + value field and a \c typeId member: \code struct MyConcreteTLVParser : public MyTLVParserBase { @@ -63,10 +65,10 @@ namespace senf { SENF_PARSER_FINALIZE ( MyConcreteTLVParser ); SENF_PARSER_INIT() { - type() = TYPEID; + type() = typeId; length_() = 4; } - static const type_t::value_type TYPEID = 0x42; + static const type_t::value_type typeId = 0x42; }; \endcode @@ -89,7 +91,7 @@ namespace senf { typedef senf::GenericTLVParserBase MyGenericTLVParser; \endcode - This generiv tlv parser can now be used for example in a list: + This generic tlv parser can now be used for example in a list: \code class MyTestPacketParser : public senf::PacketParserBase { @@ -124,7 +126,7 @@ namespace senf { \endcode \see - IPv6GenericOptionTLVParser, WLANGenericInfoElementParser, MIHGenericTLVPacketParser + IPv6GenericOptionTLVParser, WLANGenericInfoElementParser, MIHGenericTLVParser */ template class GenericTLVParserBase : public Base @@ -140,13 +142,15 @@ namespace senf { Parser init(); template - Parser as(); + Parser as() const; template - bool is(); + bool is() const; senf::PacketInterpreterBase::range value() const; + void dump(std::ostream & os) const; + #ifndef DOXYGEN template void value(ForwardReadableRange const & val, @@ -174,6 +178,41 @@ namespace senf { Base & self(); Base const & self() const; }; + + + namespace detail { + template + struct GenericTLVParserRegistry_EntryBase { + virtual void dump(std::ostream & os, GenericTLVParserBase const & parser) = 0; + }; + + template + struct GenericTLVParserRegistry_Entry + : GenericTLVParserRegistry_EntryBase + { + virtual void dump(std::ostream & os, GenericTLVParserBase const & parser); + }; + } + + template + class GenericTLVParserRegistry + : public senf::singleton > + { + typedef boost::ptr_map< + typename BaseParser::type_t::value_type, + detail::GenericTLVParserRegistry_EntryBase > Map; + Map map_; + + GenericTLVParserRegistry() {}; + public: + using senf::singleton >::instance; + friend class senf::singleton >; + + template + void registerParser(); + + void dump(std::ostream & os, GenericTLVParserBase const & parser); + }; }