843e83aa25b9c0ebcfc59e523775200a67c8a73e
[senf.git] / Packets / PacketType.cti
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY 
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief PacketType inline template implementation */
25
26 //#include "PacketType.ih"
27
28 // Custom includes
29 #include <boost/utility.hpp>
30 #include "PacketRegistry.hh"
31
32 #define prefix_ inline
33 ///////////////////////////////cti.p///////////////////////////////////////
34
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::PacketTypeBase
37
38 template <class PacketType>
39 prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeBase::factory()
40 {
41     return PacketInterpreter<PacketType>::factory();
42 }
43
44 ///////////////////////////////////////////////////////////////////////////
45 // senf::PacketTypeMixin<Self,Registry>
46
47 template <class Self, class Registry>
48 prefix_ senf::PacketInterpreterBase::optional_range
49 senf::PacketTypeMixin<Self,Registry>::nextPacketRange(Packet p)
50 {
51     // Call the member defined in the specialization below
52     return PacketTypeMixin<Self>::nextPacketRange(p);
53 }
54
55 template <class Self, class Registry>
56 prefix_ senf::PacketInterpreterBase::factory_t
57 senf::PacketTypeMixin<Self,Registry>::nextPacketType(Packet p)
58 {
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();
64 }
65
66 template <class Self, class Registry>
67 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
68 {
69     return senf::init_bytes< typename Self::parser >::value;
70 }
71
72 template <class Self, class Registry>
73 prefix_ void senf::PacketTypeMixin<Self,Registry>::init(Packet p)
74 {
75     p.as< ConcretePacket<Self> >()->init();
76 }
77
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)
81 {
82     return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_registry_key_t();
83 }
84
85 ///////////////////////////////////////////////////////////////////////////
86 // senf::PacketTypeMixin<Self,void>
87
88 template <class Self>
89 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
90 {
91     return senf::init_bytes< typename Self::parser >::value;
92 }
93
94 template <class Self>
95 prefix_ void senf::PacketTypeMixin<Self,void>::init(Packet p)
96 {
97     p.as< ConcretePacket<Self> >()->init();
98 }
99
100 ///////////////////////////////cti.e///////////////////////////////////////
101 #undef prefix_
102
103 \f
104 // Local Variables:
105 // mode: c++
106 // fill-column: 100
107 // c-file-style: "senf"
108 // indent-tabs-mode: nil
109 // ispell-local-dictionary: "american"
110 // compile-command: "scons -u test"
111 // comment-column: 40
112 // End: