X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.ct;h=2153937a970b946cfb69d315ac49f5359007ed2f;hb=78a6e233083efa63a9cd0684a92abc64202a9ee7;hp=9c364318ca5fd6636301da65e329bddbf66367ba;hpb=cf48e83de9d4793ca5bd67d1e5acdb5b20968638;p=senf.git diff --git a/senf/Packets/GenericTLV.ct b/senf/Packets/GenericTLV.ct index 9c36431..2153937 100644 --- a/senf/Packets/GenericTLV.ct +++ b/senf/Packets/GenericTLV.ct @@ -40,7 +40,7 @@ template template prefix_ Parser senf::GenericTLVParserBase::init() -{ +{ senf::PacketParserBase::size_type oldSize (bytes() ); senf::PacketParserBase::size_type newParserSize ( senf::init_bytes::value ); this->resize( oldSize, newParserSize); @@ -52,23 +52,27 @@ prefix_ Parser senf::GenericTLVParserBase::init() } template -prefix_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase::value() - const +prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) + const { - senf::PacketData::iterator begin ( boost::next(this->i(), senf::bytes( self())) ); - return PacketInterpreterBase::range(begin, boost::next( begin, this->length()) ); + 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 -prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) - const +prefix_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase::value() + const { - 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); + senf::PacketData::iterator begin ( boost::next(this->i(), senf::bytes( self())) ); + return PacketInterpreterBase::range(begin, boost::next( begin, this->length()) ); } template @@ -86,30 +90,72 @@ prefix_ void senf::GenericTLVParserBase::value_(ForwardReadableRange const /////////////////////////////////////////////////////////////////////////// -// senf::GenericTLVParserRegistry +// senf::GenericTLVParserRegistry -template +template template -prefix_ void senf::GenericTLVParserRegistry::registerParser() +prefix_ void senf::GenericTLVParserRegistry::registerParser() { - typename Map::iterator i (map_.find( Parser::typeId )); - if (i == map_.end() ) { - typename BaseParser::type_t::value_type k (Parser::typeId); - map_.insert(k , new detail::GenericTLVParserRegistry_Entry() ); - } + Keytype key (Parser::typeId+0); + typename Map::iterator i (map_.find( key )); + if (i == map_.end() ) + map_.insert(key, new detail::GenericTLVParserRegistry_Entry() ); +} + +// Wow ... this is stupid .. Boost 1.33 ptr_map API is broken ... + +#if BOOST_VERSION < 103400 +#define PTRMAP_GET_CONTENTS(v) (v) +#else +#define PTRMAP_GET_CONTENTS(v) (*(v).second) +#endif + +template +prefix_ void senf::GenericTLVParserRegistry::dump( + GenericTLVParser const & parser, std::ostream & os) + const +{ + typename Map::const_iterator i (map_.find( parser.type())); + if (i != map_.end()) + PTRMAP_GET_CONTENTS(*i).dump(parser, os); +} + +template +prefix_ void senf::GenericTLVParserRegistry::dump( + GenericTLVParser const & parser, Keytype const & key, std::ostream & os) + const +{ + typename Map::const_iterator i (map_.find( key)); + if (i != map_.end()) + PTRMAP_GET_CONTENTS(*i).dump(parser, os); } -template -prefix_ void senf::GenericTLVParserRegistry::dump( - std::ostream & os, GenericTLVParserBase const & parser) +template +prefix_ senf::PacketParserBase::size_type senf::GenericTLVParserRegistry::bytes( + GenericTLVParser const & parser) + const { - typename Map::iterator i (map_.find( parser.type())); - if (i == map_.end()) - parser.dump(os); + typename Map::const_iterator i (map_.find( parser.type())); + if (i != map_.end()) + return PTRMAP_GET_CONTENTS(*i).bytes(parser); else - (i->second)->dump(os, parser); + throw TLVParserNotRegisteredException(); } +template +prefix_ senf::PacketParserBase::size_type senf::GenericTLVParserRegistry::bytes( + GenericTLVParser const & parser, Keytype const & key) + const +{ + typename Map::const_iterator i (map_.find( key)); + if (i != map_.end()) + return PTRMAP_GET_CONTENTS(*i).bytes(parser); + else + throw TLVParserNotRegisteredException(); +} + +#undef PTRMAP_GET_CONTENTS + ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_