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 // Stefan Bund <g0dil@berlios.de>
29 \brief PacketType inline template implementation */
31 //#include "PacketType.ih"
34 #include <boost/utility.hpp>
35 #include "PacketRegistry.hh"
37 #define prefix_ inline
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 // senf::PacketTypeBase
43 template <class PacketType>
44 prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeBase::factory()
46 return PacketInterpreter<PacketType>::factory();
49 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 // senf::PacketTypeMixin<Self,Registry>
52 template <class Self, class Registry>
53 prefix_ senf::PacketInterpreterBase::optional_range
54 senf::PacketTypeMixin<Self,Registry>::nextPacketRange(ConcretePacket<Self> const & p)
56 // Call the member defined in the specialization below
57 return PacketTypeMixin<Self>::nextPacketRange(p);
60 template <class Self, class Registry>
61 prefix_ senf::PacketInterpreterBase::factory_t
62 senf::PacketTypeMixin<Self,Registry>::nextPacketType(ConcretePacket<Self> const & p)
64 if (p.data().size() < Self::initSize())
65 return Self::no_factory();
66 return lookup( Self::nextPacketKey(p) );
69 template <class Self, class Registry>
70 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
72 return senf::init_bytes< typename Self::parser >::value;
75 template <class Self, class Registry>
76 prefix_ void senf::PacketTypeMixin<Self,Registry>::init(ConcretePacket<Self> const & p)
81 template <class Self, class Registry>
82 prefix_ typename senf::PacketTypeMixin<Self,Registry>::optional_key_t
83 senf::PacketTypeMixin<Self,Registry>::key(Packet const & p)
85 return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_key_t();
88 template <class Self, class Registry>
89 prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeMixin<Self,Registry>::lookup(key_t key)
91 typename PacketRegistry<Registry>::Entry const * entry (
92 PacketRegistry<Registry>::lookup( key, senf::nothrow ));
93 return entry ? entry->factory() : PacketTypeBase::no_factory();
96 //-/////////////////////////////////////////////////////////////////////////////////////////////////
97 // senf::PacketTypeMixin<Self,void>
100 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
102 return senf::init_bytes< typename Self::parser >::value;
105 template <class Self>
106 prefix_ void senf::PacketTypeMixin<Self,void>::init(ConcretePacket<Self> const & p)
111 //-/////////////////////////////////////////////////////////////////////////////////////////////////
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // comment-column: 40