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 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 p)
59 if (p.data().size() < Self::initSize())
60 return Self::no_factory();
61 PkReg_Entry const * e (PacketRegistry<Registry>::lookup(
62 Self::nextPacketKey(p.as< ConcretePacket<Self> >()), nothrow));
63 return e ? e->factory() : PacketTypeBase::no_factory();
66 template <class Self, class Registry>
67 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
69 return senf::init_bytes< typename Self::parser >::value;
72 template <class Self, class Registry>
73 prefix_ void senf::PacketTypeMixin<Self,Registry>::init(Packet p)
75 p.as< ConcretePacket<Self> >()->init();
78 template <class Self, class Registry>
79 prefix_ typename senf::PacketTypeMixin<Self,Registry>::optional_registry_key_t
80 senf::PacketTypeMixin<Self,Registry>::key(Packet p)
82 return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_registry_key_t();
85 ///////////////////////////////////////////////////////////////////////////
86 // senf::PacketTypeMixin<Self,void>
89 prefix_ senf::PacketInterpreterBase::optional_range
90 senf::PacketTypeMixin<Self,void>::nextPacketRange(Packet p)
92 if (p.data().size() < Self::initSize())
93 return PacketTypeBase::no_range();
94 typename Self::size_type sz (Self::initHeadSize());
95 ///\idea This if condition could be replaced with a compile time switch by checking, wether
96 /// (the function address) Self::initHeadSize is different from PacketTypeBase::initHeadSize
97 if (sz == PacketTypeBase::size_type(-1))
98 return PacketTypeBase::range(boost::next(p.data().begin(),Self::initSize()),
101 return PacketTypeBase::range(boost::next(p.data().begin(),sz),
102 boost::prior(p.data().end(),Self::initSize()-sz));
105 template <class Self>
106 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
108 return senf::init_bytes< typename Self::parser >::value;
111 template <class Self>
112 prefix_ void senf::PacketTypeMixin<Self,void>::init(Packet p)
114 p.as< ConcretePacket<Self> >()->init();
117 ///////////////////////////////cti.e///////////////////////////////////////
124 // c-file-style: "senf"
125 // indent-tabs-mode: nil
126 // ispell-local-dictionary: "american"
127 // compile-command: "scons -u test"
128 // comment-column: 40