X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.ct;h=fb59a100049c13e91d17ccbd55887e8133fa0797;hb=33adfa86c0b25cb6eeda0fa12d47e077e488375a;hp=75debb10d5a83f88e3c020157e461d7af022f227;hpb=29a39b247b75454ad25f3f9dc7a524debf8e805c;p=senf.git diff --git a/senf/Packets/GenericTLV.ct b/senf/Packets/GenericTLV.ct index 75debb1..fb59a10 100644 --- a/senf/Packets/GenericTLV.ct +++ b/senf/Packets/GenericTLV.ct @@ -26,10 +26,17 @@ //#include "GenericTLV.ih" // Custom includes +#include +#include +#include +#include #define prefix_ ///////////////////////////////ct.p//////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////// +// senf::GenericTLVParserBase + template template prefix_ Parser senf::GenericTLVParserBase::init() @@ -45,6 +52,22 @@ prefix_ Parser senf::GenericTLVParserBase::init() } template +prefix_ void senf::GenericTLVParserBase::dump(std::ostream & os) + const +{ + 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_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase::value() const { @@ -56,10 +79,8 @@ template template prefix_ void senf::GenericTLVParserBase::value_(ForwardReadableRange const &range) { - unsigned int rangeSize = boost::size(range); - std::cerr << "GenericTLVParserBase::value_() rangeSize=" << - unsigned( rangeSize) << " length()=" << unsigned( this->length()) << " bytes(self)=" << - unsigned( senf::bytes(self())) << " bytes()=" << unsigned( senf::bytes(*this)) << std::endl; + //typename boost::range_difference::type rangeSize ( boost::size(range)); + unsigned rangeSize ( boost::size(range)); if ( rangeSize != this->length() ) resize( bytes(), rangeSize + senf::bytes(self()) ); std::copy( boost::begin(range), boost::end(range), boost::next( @@ -67,6 +88,40 @@ prefix_ void senf::GenericTLVParserBase::value_(ForwardReadableRange const this->length_() = rangeSize; } + +/////////////////////////////////////////////////////////////////////////// +// senf::GenericTLVParserRegistry + +template +template +prefix_ void senf::GenericTLVParserRegistry::registerParser() +{ + 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( + GenericTLVParserBase const & parser, std::ostream & os) + const +{ + typename Map::const_iterator i (map_.find( parser.type())); + if (i != map_.end()) + (i->second)->dump(parser, os); +} + +template +prefix_ void senf::GenericTLVParserRegistry::dump( + GenericTLVParserBase 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); +} + ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_