X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.hh;h=b0dab34c8b252ce728a337edc19ecd7d5dbd845a;hb=9ffdaae4804503c4f36a53747c852a87ee626b9e;hp=6f89e827c5a642cd119cbf662243ccd8c21748c5;hpb=f723d7852a8195072eee387ea9ca77156b58438b;p=senf.git diff --git a/senf/Packets/GenericTLV.hh b/senf/Packets/GenericTLV.hh index 6f89e82..b0dab34 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 { @@ -147,6 +149,8 @@ namespace senf { senf::PacketInterpreterBase::range value() const; + void dump(std::ostream & os) const; + #ifndef DOXYGEN template void value(ForwardReadableRange const & val, @@ -174,8 +178,55 @@ namespace senf { Base & self(); Base const & self() const; }; -} + + + namespace detail { + template + struct GenericTLVParserRegistry_EntryBase { + virtual void dump(GenericTLVParserBase const & parser, std::ostream & os) = 0; + }; + + template + struct GenericTLVParserRegistry_Entry + : GenericTLVParserRegistry_EntryBase + { + virtual void dump(GenericTLVParserBase const & parser, std::ostream & os); + }; + } + + 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 + struct RegistrationProxy { + RegistrationProxy(); + }; + template + void registerParser(); + + void dump(GenericTLVParserBase const & parser, std::ostream & os); + }; + +# define SENF_PACKET_TLV_REGISTRY_REGISTER( BaseTLVParser, ConreteTLVParser ) \ + namespace { \ + senf::GenericTLVParserRegistry \ + ::RegistrationProxy \ + BOOST_PP_CAT(tlvparserRegistration_, __LINE__); \ + } + +} ///////////////////////////////hh.e//////////////////////////////////////// //#include "GenericTLV.cci"