4caed7644a2ae246a1865c3a0547290b52c3fb45
[senf.git] / senf / 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(ConcretePacket<Self> const & 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(ConcretePacket<Self> const & p)
58 {
59     if (p.data().size() < Self::initSize())
60         return Self::no_factory();
61     return lookup( Self::nextPacketKey(p) );
62 }
63
64 template <class Self, class Registry>
65 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
66 {
67     return senf::init_bytes< typename Self::parser >::value;
68 }
69
70 template <class Self, class Registry>
71 prefix_ void senf::PacketTypeMixin<Self,Registry>::init(ConcretePacket<Self> const & p)
72 {
73     p->init();
74 }
75
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)
79 {
80     return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_key_t();
81 }
82
83 template <class Self, class Registry>
84 prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeMixin<Self,Registry>::lookup(key_t key)
85 {
86     typename PacketRegistry<Registry>::Entry const * entry (
87         PacketRegistry<Registry>::lookup( key, senf::nothrow ));
88     return entry ? entry->factory() : PacketTypeBase::no_factory();
89 }
90
91 ///////////////////////////////////////////////////////////////////////////
92 // senf::PacketTypeMixin<Self,void>
93
94 template <class Self>
95 prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
96 {
97     return senf::init_bytes< typename Self::parser >::value;
98 }
99
100 template <class Self>
101 prefix_ void senf::PacketTypeMixin<Self,void>::init(ConcretePacket<Self> const & p)
102 {
103     p->init();
104 }
105
106 ///////////////////////////////cti.e///////////////////////////////////////
107 #undef prefix_
108
109 \f
110 // Local Variables:
111 // mode: c++
112 // fill-column: 100
113 // c-file-style: "senf"
114 // indent-tabs-mode: nil
115 // ispell-local-dictionary: "american"
116 // compile-command: "scons -u test"
117 // comment-column: 40
118 // End: