X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.ct;h=6605618a17be93b8f6e64490200e311985867c5d;hb=209950ee5f6898978cd68614ef339ae3531c5c53;hp=9c364318ca5fd6636301da65e329bddbf66367ba;hpb=cf48e83de9d4793ca5bd67d1e5acdb5b20968638;p=senf.git
diff --git a/senf/Packets/GenericTLV.ct b/senf/Packets/GenericTLV.ct
index 9c36431..6605618 100644
--- a/senf/Packets/GenericTLV.ct
+++ b/senf/Packets/GenericTLV.ct
@@ -52,23 +52,27 @@ prefix_ Parser senf::GenericTLVParserBase::init()
}
template
-prefix_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase::value()
+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)
+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,64 @@ 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() );
}
-template
-prefix_ void senf::GenericTLVParserRegistry::dump(
- std::ostream & os, GenericTLVParserBase const & parser)
+template
+prefix_ void senf::GenericTLVParserRegistry::dump(
+ GenericTLVParser const & parser, std::ostream & os)
+ 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())
+ (i->second)->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())
+ (i->second)->dump(parser, os);
+}
+
+template
+prefix_ senf::PacketParserBase::size_type senf::GenericTLVParserRegistry::bytes(
+ GenericTLVParser const & parser)
+ const
+{
+ typename Map::const_iterator i (map_.find( parser.type()));
+ if (i != map_.end())
+ return (i->second)->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 (i->second)->bytes(parser);
+ else
+ throw TLVParserNotRegisteredException();
+}
+
+
+
///////////////////////////////ct.e////////////////////////////////////////
#undef prefix_