4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief GenericTLV non-inline template implementation */
26 //#include "GenericTLV.ih"
29 #include <boost/io/ios_state.hpp>
30 #include <senf/Utils/hexdump.hh>
31 #include <senf/Utils/TypeInfo.hh>
32 #include <senf/Utils/Format.hh>
35 ///////////////////////////////ct.p////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////
38 // senf::GenericTLVParserBase<Base>
41 template <class Parser>
42 prefix_ Parser senf::GenericTLVParserBase<Base>::init()
44 senf::PacketParserBase::size_type oldSize (bytes() );
45 senf::PacketParserBase::size_type newParserSize ( senf::init_bytes<Parser>::value );
46 this->resize( oldSize, newParserSize);
47 std::fill(this->i(), boost::next(this->i(), newParserSize), 0u);
48 Parser concreteParser = Parser(this->i(), this->state() );
49 concreteParser.init();
50 // concreteParser.length() = newParserSize - senf::init_bytes<Base>::value;
51 return concreteParser;
55 prefix_ senf::PacketInterpreterBase::range senf::GenericTLVParserBase<Base>::value()
58 senf::PacketData::iterator begin ( boost::next(this->i(), senf::bytes( self())) );
59 return PacketInterpreterBase::range(begin, boost::next( begin, this->length()) );
63 template <class ForwardReadableRange>
64 prefix_ void senf::GenericTLVParserBase<Base>::value_(ForwardReadableRange const &range)
66 //typename boost::range_difference<ForwardReadableRange>::type rangeSize ( boost::size(range));
67 unsigned rangeSize ( boost::size(range));
68 if ( rangeSize != this->length() )
69 resize( bytes(), rangeSize + senf::bytes(self()) );
70 std::copy( boost::begin(range), boost::end(range), boost::next(
71 this->i(), senf::bytes( self())) );
72 this->length_() = rangeSize;
76 ///////////////////////////////////////////////////////////////////////////
77 // senf::GenericTLVParserRegistry<BaseParser>
79 template <class BaseParser>
80 template <typename Parser>
81 prefix_ void senf::GenericTLVParserRegistry<BaseParser>::registerParser()
83 typename BaseParser::type_t::value_type key (Parser::typeId+0);
84 typename Map::iterator i (map_.find( key ));
86 map_.insert(key, new detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>() );
89 template <class BaseParser>
90 prefix_ void senf::GenericTLVParserRegistry<BaseParser>::dump(
91 GenericTLVParserBase<BaseParser> const & parser, std::ostream & os)
93 typename Map::iterator i (map_.find( parser.type()));
94 if (i == map_.end()) {
95 boost::io::ios_all_saver ias(os);
96 os << " GenericTLVParser<" << prettyName(typeid(BaseParser)) << ">\n"
97 << " type: " << senf::format::dumpint(parser.type()) << "\n"
98 << " length: " << senf::format::dumpint(parser.length()) << "\n"
100 hexdump(parser.value().begin(), parser.value().end(), os);
103 (i->second)->dump(parser, os);
106 ///////////////////////////////ct.e////////////////////////////////////////
113 // comment-column: 40
114 // c-file-style: "senf"
115 // indent-tabs-mode: nil
116 // ispell-local-dictionary: "american"
117 // compile-command: "scons -u test"