Packets: Extend finalize() API
[senf.git] / Packets / Packet.cci
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 Packet inline non-template implementation */
25
26 // Custom includes
27 #include "../Utils/senfassert.hh"
28
29 #define prefix_ inline
30 ///////////////////////////////cci.p///////////////////////////////////////
31
32 ///////////////////////////////////////////////////////////////////////////
33 // senf::Packet
34
35 // protected members
36
37 prefix_  senf::Packet::Packet(PacketInterpreterBase::ptr packet)
38     : packet_(packet)
39 {}
40
41 prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr()
42     const
43 {
44     SENF_ASSERT(packet_);
45     return packet_;
46 }
47
48 // public structors
49
50 prefix_ senf::Packet::Packet()
51 {}
52
53 // public members
54
55 prefix_ senf::Packet senf::Packet::clone()
56     const
57 {
58     return Packet(ptr()->clone());
59 }
60
61 // Interpreter chain access
62
63 prefix_ senf::Packet senf::Packet::next(NoThrow_t)
64     const
65 {
66     PacketInterpreterBase::ptr p (ptr()->next());
67     return !p && ptr()->nextPacketRange() ? checkNext() : Packet(p);
68 }
69
70 prefix_ senf::Packet senf::Packet::next()
71     const
72 {
73     Packet p (next(nothrow));
74     if (!p) throw InvalidPacketChainException();
75     return p;
76 }
77
78 prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
79     const
80 {
81     return Packet(ptr()->prev());
82 }
83
84 prefix_ senf::Packet senf::Packet::prev()
85     const
86 {
87     Packet p (prev(nothrow));
88     if (!p) throw InvalidPacketChainException();
89     return p;
90 }
91
92 prefix_ senf::Packet senf::Packet::first()
93     const
94 {
95     return Packet(ptr()->first());
96 }
97
98 prefix_ senf::Packet senf::Packet::last()
99     const
100 {
101     Packet p (ptr()->last());
102     return p.next(nothrow) ? checkLast() : p;
103 }
104
105 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
106     const
107 {
108     return Packet(ptr()->parseNextAs(factory));
109 }
110
111 prefix_ senf::Packet senf::Packet::append(Packet packet)
112     const
113 {
114     return Packet(ptr()->append(packet.ptr()));
115 }
116
117 // Data access
118
119 prefix_ senf::PacketData & senf::Packet::data()
120     const
121 {
122     return ptr()->data();
123 }
124
125 prefix_ senf::Packet::size_type senf::Packet::size()
126     const
127 {
128     return data().size();
129 }
130
131
132 // Other methods
133
134 prefix_ bool senf::Packet::operator==(Packet other)
135     const
136 {
137     return ptr() == other.ptr();
138 }
139
140 prefix_ void senf::Packet::finalizeThis()
141 {
142     ptr()->finalizeThis();
143 }
144
145 prefix_ void senf::Packet::finalizeTo(Packet other)
146 {
147     ptr()->finalizeTo(other.ptr());
148 }
149
150 prefix_ void senf::Packet::finalizeAll()
151 {
152     ptr()->finalizeTo(last().ptr());
153 }
154
155 prefix_ void senf::Packet::dump(std::ostream & os)
156     const
157 {
158     last(); // Make sure the packet is complete
159     ptr()->dump(os);
160 }
161
162 prefix_ senf::TypeIdValue senf::Packet::typeId()
163     const
164 {
165     return ptr()->typeId();
166 }
167
168 prefix_ senf::Packet::factory_t senf::Packet::factory()
169     const
170 {
171     return ptr()->factory();
172 }
173
174 prefix_ bool senf::Packet::boolean_test()
175     const
176 {
177     return packet_ && packet_->valid();
178 }
179
180 ///////////////////////////////cci.e///////////////////////////////////////
181 #undef prefix_
182
183 \f
184 // Local Variables:
185 // mode: c++
186 // fill-column: 100
187 // c-file-style: "senf"
188 // indent-tabs-mode: nil
189 // ispell-local-dictionary: "american"
190 // compile-command: "scons -u test"
191 // comment-column: 40
192 // End: