ef4611215b24bc9d59e5287f2a8862d38584ee75
[senf.git] / senf / 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 <senf/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 const & packet)
38     : packet_(packet)
39 {}
40
41 prefix_ senf::PacketInterpreterBase::ptr const & senf::Packet::ptr()
42     const
43 {
44     SENF_ASSERT(packet_, "Invalid operation (dereferencing) on in-valid() 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     if (p) return Packet(p);
68     PacketInterpreterBase::optional_range r (ptr()->nextPacketRange());
69     return (r && ! r->empty()) ? getNext() : Packet();
70 }
71
72 prefix_ senf::Packet senf::Packet::next()
73     const
74 {
75     Packet p (next(nothrow));
76     if (!p) throw InvalidPacketChainException();
77     return p;
78 }
79
80 prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
81     const
82 {
83     return Packet(ptr()->prev());
84 }
85
86 prefix_ senf::Packet senf::Packet::prev()
87     const
88 {
89     Packet p (prev(nothrow));
90     if (!p) throw InvalidPacketChainException();
91     return p;
92 }
93
94 prefix_ senf::Packet senf::Packet::first()
95     const
96 {
97     return Packet(ptr()->first());
98 }
99
100 prefix_ senf::Packet senf::Packet::last()
101     const
102 {
103     Packet p (ptr()->last());
104     return p.next(nothrow) ? getLast() : p;
105 }
106
107 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
108     const
109 {
110     return Packet(ptr()->parseNextAs(factory));
111 }
112
113 prefix_ senf::Packet senf::Packet::append(Packet const & packet)
114     const
115 {
116     return Packet(ptr()->append(packet.ptr()));
117 }
118
119 // Data access
120
121 prefix_ senf::PacketData & senf::Packet::data()
122     const
123 {
124     return ptr()->data();
125 }
126
127 prefix_ senf::Packet::size_type senf::Packet::size()
128     const
129 {
130     return data().size();
131 }
132
133 // Other methods
134
135 prefix_ bool senf::Packet::operator==(Packet const & other)
136     const
137 {
138     return ptr() == other.ptr();
139 }
140
141 prefix_ void senf::Packet::finalizeThis()
142 {
143     ptr()->finalizeThis();
144 }
145
146 prefix_ void senf::Packet::finalizeTo(Packet const & other)
147 {
148     ptr()->finalizeTo(other.ptr());
149 }
150
151 prefix_ void senf::Packet::finalizeAll()
152 {
153     ptr()->finalizeTo(last().ptr());
154 }
155
156 prefix_ void senf::Packet::dump(std::ostream & os)
157     const
158 {
159     last(); // Make sure the packet is complete
160     ptr()->dump(os);
161 }
162
163 prefix_ senf::TypeIdValue senf::Packet::typeId()
164     const
165 {
166     return ptr()->typeId();
167 }
168
169 prefix_ senf::Packet::factory_t senf::Packet::factory()
170     const
171 {
172     return ptr()->factory();
173 }
174
175 prefix_ unsigned long senf::Packet::id()
176     const
177 {
178     return reinterpret_cast<unsigned long>(&ptr()->impl());
179 }
180
181 prefix_ bool senf::Packet::boolean_test()
182     const
183 {
184     return packet_ && packet_->valid();
185 }
186
187 prefix_ bool senf::Packet::valid()
188     const
189 {
190     return *this;
191 }
192
193 prefix_ bool senf::Packet::is_shared()
194     const
195 {
196     return ptr()->is_shared() || (ptr()->impl().refcount() > 1);
197 }
198
199 prefix_ void senf::Packet::reparse()
200     const
201 {
202     return ptr()->reparse();
203 }
204
205 prefix_ void senf::Packet::clearAnnotations()
206 {
207     return ptr()->clearAnnotations();
208 }
209
210 template <class PacketType, class Parser>
211 prefix_ Parser senf::operator<<(Parser target, ConcretePacket<PacketType> const & packet)
212 {
213     target << packet.parser();
214     return target;
215 }
216
217 ///////////////////////////////cci.e///////////////////////////////////////
218 #undef prefix_
219
220 \f
221 // Local Variables:
222 // mode: c++
223 // fill-column: 100
224 // c-file-style: "senf"
225 // indent-tabs-mode: nil
226 // ispell-local-dictionary: "american"
227 // compile-command: "scons -u test"
228 // comment-column: 40
229 // End: