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