4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
29 \brief GenericTLV inline template implementation */
31 //#include "GenericTLV.ih"
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // senf::GenericTLVParserBase<Base>
42 prefix_ senf::PacketParserBase::size_type senf::GenericTLVParserBase<Base>::bytes()
45 if (Base::Registry::instance().isRegistered( *this))
46 return Base::Registry::instance().bytes( *this);
48 return senf::bytes(self()) + this->length();
52 prefix_ void senf::GenericTLVParserBase<Base>::init()
59 template <class Parser>
60 prefix_ Parser senf::GenericTLVParserBase<Base>::as()
63 return Parser(this->i(), this->state() );
67 template <class Parser>
68 prefix_ bool senf::GenericTLVParserBase<Base>::is()
71 return this->type().value() == Parser::typeId;
75 prefix_ Base & senf::GenericTLVParserBase<Base>::self()
77 return *static_cast<Base *>(this);
81 prefix_ Base const & senf::GenericTLVParserBase<Base>::self()
84 return *static_cast<Base const *>(this);
90 template <class ForwardReadableRange>
91 prefix_ void senf::GenericTLVParserBase<Base>::value(
92 ForwardReadableRange const & val,
93 typename boost::disable_if<senf::is_pair<ForwardReadableRange> >::type *)
99 template <class First, class Second>
100 prefix_ void senf::GenericTLVParserBase<Base>::value(
101 std::pair<First, Second> const & val,
102 typename boost::disable_if<boost::is_convertible<First, typename Base::type_t::value_type> >::type *)
107 template <class Base>
108 template <class Type, class ForwardReadableRange>
109 prefix_ void senf::GenericTLVParserBase<Base>::value(
110 std::pair<Type, ForwardReadableRange> const & val,
111 typename boost::enable_if<boost::is_convertible<Type, typename Base::type_t::value_type> >::type *)
113 this->type() = val.first;
120 //-/////////////////////////////////////////////////////////////////////////////////////////////////
121 // senf::detail:GenericTLVParserRegistry_Entry<BaseParser, Parser>
123 template <class BaseParser, class Parser>
124 prefix_ void senf::detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>::dump(
125 GenericTLVParserBase<BaseParser> const & parser, std::ostream & os)
128 (parser.template as<Parser>()).dump(os);
131 template <class BaseParser, class Parser>
132 prefix_ senf::PacketParserBase::size_type
133 senf::detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>::bytes(
134 GenericTLVParserBase<BaseParser> const & parser)
137 return senf::bytes( parser.template as<Parser>());
140 //-/////////////////////////////////////////////////////////////////////////////////////////////////
141 // senf::GenericTLVParserRegistry<BaseParser,Keytype>
143 template <class BaseParser, class Keytype>
144 prefix_ bool senf::GenericTLVParserRegistry<BaseParser,Keytype>::isRegistered(
145 GenericTLVParser const & parser)
148 typename Map::const_iterator i (map_.find( parser.type()));
149 return i != map_.end();
152 template <class BaseParser, class Keytype>
153 prefix_ bool senf::GenericTLVParserRegistry<BaseParser,Keytype>::isRegistered(Keytype const & key)
156 typename Map::const_iterator i (map_.find( key));
157 return i != map_.end();
160 //-/////////////////////////////////////////////////////////////////////////////////////////////////
161 // senf::GenericTLVParserRegistry<BaseParser,Keytype>::RegistrationProxy<PacketParser>
163 template <class BaseParser, class Keytype>
164 template <class PacketParser>
165 prefix_ senf::GenericTLVParserRegistry<BaseParser,Keytype>::RegistrationProxy<PacketParser>::RegistrationProxy()
167 GenericTLVParserRegistry<BaseParser,Keytype>::instance().registerParser<PacketParser>();
170 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // comment-column: 40
178 // c-file-style: "senf"
179 // indent-tabs-mode: nil
180 // ispell-local-dictionary: "american"
181 // compile-command: "scons -u test"