X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.hh;h=e14f5c6f201bc8b4c4fa138dc00be85705a77ac7;hb=482523171f06cf239fd7e8c991f81711c02cf0ba;hp=e4c84e697ede11316a57c470585ec79e57a80583;hpb=d827fa2c49602de3e7d9559810408f258b5987ba;p=senf.git diff --git a/senf/Packets/GenericTLV.hh b/senf/Packets/GenericTLV.hh index e4c84e6..e14f5c6 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,8 +126,7 @@ namespace senf { \endcode \see - IPv6GenericOptionTLVParser, \n - WLANGenericInfoElementParser + IPv6GenericOptionTLVParser, WLANGenericInfoElementParser, MIHGenericTLVParser */ template class GenericTLVParserBase : public Base @@ -141,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, @@ -171,9 +174,58 @@ namespace senf { private: template void value_(ForwardReadableRange const &range); + + 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( ConreteTLVParser ) \ + namespace { \ + ConreteTLVParser::Registry::RegistrationProxy \ + BOOST_PP_CAT(tlvparserRegistration_, __LINE__); \ + } + +} ///////////////////////////////hh.e//////////////////////////////////////// //#include "GenericTLV.cci"