switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / Packet.cci
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief Packet inline non-template implementation */
30
31 // Custom includes
32 #include <senf/Utils/senfassert.hh>
33
34 #define prefix_ inline
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38 // senf::Packet
39
40 // protected members
41
42 prefix_  senf::Packet::Packet(PacketInterpreterBase::ptr const & packet)
43     : packet_(packet)
44 {}
45
46 prefix_ senf::PacketInterpreterBase::ptr const & senf::Packet::ptr()
47     const
48 {
49     SENF_ASSERT(packet_, "Invalid operation (dereferencing) on in-valid() Packet");
50     return packet_;
51 }
52
53 // public structors
54
55 prefix_ senf::Packet::Packet()
56 {}
57
58 // public members
59
60 prefix_ senf::Packet senf::Packet::clone()
61     const
62 {
63     return Packet(ptr()->clone());
64 }
65
66 // Interpreter chain access
67
68 prefix_ senf::Packet senf::Packet::next(NoThrow_t)
69     const
70 {
71     PacketInterpreterBase::ptr p (ptr()->next());
72     if (p) return Packet(p);
73     PacketInterpreterBase::optional_range r (ptr()->nextPacketRange());
74     return (r && ! r->empty()) ? getNext() : Packet();
75 }
76
77 prefix_ senf::Packet senf::Packet::next()
78     const
79 {
80     Packet p (next(nothrow));
81     if (!p) throw InvalidPacketChainException();
82     return p;
83 }
84
85 prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
86     const
87 {
88     return Packet(ptr()->prev());
89 }
90
91 prefix_ senf::Packet senf::Packet::prev()
92     const
93 {
94     Packet p (prev(nothrow));
95     if (!p) throw InvalidPacketChainException();
96     return p;
97 }
98
99 prefix_ senf::Packet senf::Packet::first()
100     const
101 {
102     return Packet(ptr()->first());
103 }
104
105 prefix_ senf::Packet senf::Packet::last()
106     const
107 {
108     Packet p (ptr()->last());
109     return p.next(nothrow) ? getLast() : p;
110 }
111
112 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
113     const
114 {
115     return Packet(ptr()->parseNextAs(factory));
116 }
117
118 prefix_ senf::Packet senf::Packet::append(Packet const & packet)
119     const
120 {
121     return Packet(ptr()->append(packet.ptr()));
122 }
123
124 // Data access
125
126 prefix_ senf::PacketData & senf::Packet::data()
127     const
128 {
129     return ptr()->data();
130 }
131
132 prefix_ senf::Packet::size_type senf::Packet::size()
133     const
134 {
135     return data().size();
136 }
137
138 // Other methods
139
140 prefix_ bool senf::Packet::operator==(Packet const & other)
141     const
142 {
143     return ptr() == other.ptr();
144 }
145
146 prefix_ void senf::Packet::finalizeThis()
147 {
148     ptr()->finalizeThis();
149 }
150
151 prefix_ void senf::Packet::finalizeTo(Packet const & other)
152 {
153     ptr()->finalizeTo(other.ptr());
154 }
155
156 prefix_ void senf::Packet::finalizeAll()
157 {
158     ptr()->finalizeTo(last().ptr());
159 }
160
161 prefix_ senf::TypeIdValue senf::Packet::typeId()
162     const
163 {
164     return ptr()->typeId();
165 }
166
167 prefix_ senf::Packet::factory_t senf::Packet::factory()
168     const
169 {
170     return ptr()->factory();
171 }
172
173 prefix_ unsigned long senf::Packet::id()
174     const
175 {
176     return reinterpret_cast<unsigned long>(&ptr()->impl());
177 }
178
179 prefix_ bool senf::Packet::boolean_test()
180     const
181 {
182     return packet_ && packet_->valid();
183 }
184
185 prefix_ bool senf::Packet::valid()
186     const
187 {
188     return *this;
189 }
190
191 prefix_ bool senf::Packet::is_shared()
192     const
193 {
194     return ptr()->is_shared() || (ptr()->impl().refcount() > 1);
195 }
196
197 prefix_ void senf::Packet::reparse()
198     const
199 {
200     return ptr()->reparse();
201 }
202
203 prefix_ void senf::Packet::clearAnnotations()
204 {
205     return ptr()->clearAnnotations();
206 }
207
208 template <class PacketType, class Parser>
209 prefix_ Parser senf::operator<<(Parser target, ConcretePacket<PacketType> const & packet)
210 {
211     target << packet.parser();
212     return target;
213 }
214
215 //-/////////////////////////////////////////////////////////////////////////////////////////////////
216 #undef prefix_
217
218 \f
219 // Local Variables:
220 // mode: c++
221 // fill-column: 100
222 // c-file-style: "senf"
223 // indent-tabs-mode: nil
224 // ispell-local-dictionary: "american"
225 // compile-command: "scons -u test"
226 // comment-column: 40
227 // End: