4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@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 PacketType inline template implementation */
26 //#include "PacketType.ih"
29 #include <boost/utility.hpp>
30 #include "PacketRegistry.hh"
32 #define prefix_ inline
33 ///////////////////////////////cti.p///////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::PacketTypeBase
38 template <class PacketType>
39 prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeBase::factory()
41 return PacketInterpreter<PacketType>::factory();
44 ///////////////////////////////////////////////////////////////////////////
45 // senf::PacketTypeMixin<Self,Registry>
47 template <class Self, class Registry>
48 prefix_ senf::PacketInterpreterBase::optional_range
49 senf::PacketTypeMixin<Self,Registry>::nextPacketRange(Packet const & p)
51 // Call the member defined in the specialization below
52 return PacketTypeMixin<Self>::nextPacketRange(p);
55 template <class Self, class Registry>
56 prefix_ senf::PacketInterpreterBase::factory_t
57 senf::PacketTypeMixin<Self,Registry>::nextPacketType(Packet const & p)
59 if (p.data().size() < Self::initSize())
60 return Self::no_factory();
61 return lookup( Self::nextPacketKey(p.as< ConcretePacket<Self> >()) );
64 template <class Self, class Registry>
65 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
67 return senf::init_bytes< typename Self::parser >::value;
70 template <class Self, class Registry>
71 prefix_ void senf::PacketTypeMixin<Self,Registry>::init(Packet const & p)
73 p.as< ConcretePacket<Self> >()->init();
76 template <class Self, class Registry>
77 prefix_ typename senf::PacketTypeMixin<Self,Registry>::optional_key_t
78 senf::PacketTypeMixin<Self,Registry>::key(Packet const & p)
80 return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_key_t();
83 template <class Self, class Registry>
84 prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeMixin<Self,Registry>::lookup(key_t key)
86 PkReg_Entry const * entry (PacketRegistry<Registry>::lookup( key, senf::nothrow ));
87 return entry ? entry->factory() : PacketTypeBase::no_factory();
90 ///////////////////////////////////////////////////////////////////////////
91 // senf::PacketTypeMixin<Self,void>
94 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
96 return senf::init_bytes< typename Self::parser >::value;
100 prefix_ void senf::PacketTypeMixin<Self,void>::init(Packet const & p)
102 p.as< ConcretePacket<Self> >()->init();
105 ///////////////////////////////cti.e///////////////////////////////////////
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // comment-column: 40