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